Skip to content

Commit 020d569

Browse files
fix: datepicker and timepicker issues fixed
1 parent 4dbbd23 commit 020d569

File tree

10 files changed

+55
-21
lines changed

10 files changed

+55
-21
lines changed

client/packages/lowcoder-dev-utils/external.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ export const libs = [
2222
name: "moment",
2323
extractDefault: true,
2424
},
25+
{
26+
name: "dayjs",
27+
extractDefault: true,
28+
},
2529
{
2630
name: "lowcoder-sdk",
2731
from: "./src/index.sdk.ts",

client/packages/lowcoder/src/comps/comps/dateComp/dateComp.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,10 @@ export type DateCompViewProps = Pick<
154154
};
155155

156156
export const datePickerControl = new UICompBuilder(childrenMap, (props) => {
157-
const time = dayjs(props.value.value, DateParser);
158-
157+
let time = dayjs(null);
158+
if(props.value.value !== '') {
159+
time = dayjs(props.value.value, DateParser);
160+
}
159161
return props.label({
160162
required: props.required,
161163
style: props.style,
@@ -242,8 +244,14 @@ export const dateRangeControl = (function () {
242244
};
243245

244246
return new UICompBuilder(childrenMap, (props) => {
245-
const start = dayjs(props.start.value, DateParser);
246-
const end = dayjs(props.end.value, DateParser);
247+
let start = dayjs(null);
248+
let end = dayjs(null);
249+
if(props.start.value !== '') {
250+
start = dayjs(props.start.value, DateParser);
251+
}
252+
if(props.end.value !== '') {
253+
end = dayjs(props.end.value, DateParser);
254+
}
247255

248256
const children = (
249257
<DateRangeUIView

client/packages/lowcoder/src/comps/comps/dateComp/dateCompUtil.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ export const handleDateChange = (
1717
};
1818

1919
export const disabledDate = (current: dayjs.Dayjs, min: string, max: string) => {
20-
const maxDate = dayjs(max, DateParser);
21-
const minDate = dayjs(min, DateParser);
20+
const tmpMinDate = min === '' ? undefined : min
21+
const tmpMaxDate = max === '' ? undefined : max
22+
const maxDate = dayjs(tmpMaxDate, DateParser);
23+
const minDate = dayjs(tmpMinDate, DateParser);
24+
2225
return (
2326
current &&
2427
current.isValid() &&
@@ -27,8 +30,11 @@ export const disabledDate = (current: dayjs.Dayjs, min: string, max: string) =>
2730
};
2831

2932
export const disabledTime = (min: string, max: string) => {
30-
const maxTime = dayjs(max, TimeParser);
31-
const minTime = dayjs(min, TimeParser);
33+
const tmpMinTime = min === '' ? undefined : min
34+
const tmpMaxTime = max === '' ? undefined : max
35+
const maxTime = dayjs(tmpMaxTime, TimeParser);
36+
const minTime = dayjs(tmpMinTime, TimeParser);
37+
3238
return {
3339
disabledHours: () => {
3440
let disabledHours: number[] = [];

client/packages/lowcoder/src/comps/comps/dateComp/timeComp.tsx

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,10 @@ export type TimeCompViewProps = Pick<
133133
};
134134

135135
export const timePickerControl = new UICompBuilder(childrenMap, (props) => {
136-
const time = dayjs(props.value.value, TimeParser);
136+
let time = dayjs(null);
137+
if(props.value.value !== '') {
138+
time = dayjs(props.value.value, TimeParser);
139+
}
137140

138141
return props.label({
139142
required: props.required,
@@ -147,8 +150,8 @@ export const timePickerControl = new UICompBuilder(childrenMap, (props) => {
147150
disabledTime={() => disabledTime(props.minTime, props.maxTime)}
148151
{...timePickerComps(props)}
149152
hourStep={props.hourStep as hourStepType}
150-
minuteStep={props.hourStep as minuteStepType}
151-
secondStep={props.hourStep as secondStepType}
153+
minuteStep={props.minuteStep as minuteStepType}
154+
secondStep={props.secondStep as secondStepType}
152155
onChange={(time) => {
153156
handleDateChange(
154157
time && time.isValid() ? time.format(TIME_FORMAT) : "",
@@ -209,21 +212,27 @@ export const timeRangeControl = (function () {
209212
};
210213

211214
return new UICompBuilder(childrenMap, (props) => {
212-
const start = dayjs(props.start.value, TimeParser);
213-
const end = dayjs(props.end.value, TimeParser);
215+
let start = null;
216+
if(props.start.value !== '') {
217+
start = dayjs(props.start.value, TimeParser);
218+
}
219+
let end = null;
220+
if(props.end.value !== '') {
221+
end = dayjs(props.end.value, TimeParser);
222+
}
214223

215224
const children = (
216225
<TimeRangeUIView
217226
viewRef={props.viewRef}
218227
$style={props.style}
219228
disabled={props.disabled}
220-
start={start.isValid() ? start : null}
221-
end={end.isValid() ? end : null}
229+
start={start?.isValid() ? start : null}
230+
end={end?.isValid() ? end : null}
222231
disabledTime={() => disabledTime(props.minTime, props.maxTime)}
223232
{...timePickerComps(props)}
224233
hourStep={props.hourStep as hourStepType}
225-
minuteStep={props.hourStep as minuteStepType}
226-
secondStep={props.hourStep as secondStepType}
234+
minuteStep={props.minuteStep as minuteStepType}
235+
secondStep={props.secondStep as secondStepType}
227236
onChange={(start, end) => {
228237
props.start.onChange(start && start.isValid() ? start.format(TIME_FORMAT) : "");
229238
props.end.onChange(end && end.isValid() ? end.format(TIME_FORMAT) : "");

client/packages/lowcoder/src/comps/comps/dateComp/timeRangeUIView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export interface TimeRangeUIViewProps extends TimeCompViewProps {
2828

2929
export const TimeRangeUIView = (props: TimeRangeUIViewProps) => {
3030
const editorState = useContext(EditorContext);
31-
console.log(props);
31+
3232
return useUIView(
3333
<TimeRangeMobileUIView {...props} />,
3434
<RangePickerStyled

client/packages/lowcoder/src/comps/comps/formComp/generate/comp.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ const multiSelectComps: CompConfig[] = [
8888
const dateComp: CompConfig = {
8989
type: "date",
9090
};
91+
// TODO: RAHEEL
9192
function dateTimeToTimestamp(compName: string) {
9293
return "moment(" + compName + ".value || 0).valueOf()";
9394
}

client/packages/lowcoder/src/comps/hooks/hookComp.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ const HookMap: HookCompMapRawType = {
8585
currentTime: CurrentTimeHookComp,
8686
lodashJsLib: LodashJsLib,
8787
dayJsLib: DayJsLib,
88+
momentJsLib: DayJsLib,
8889
utils: UtilsComp,
8990
message: MessageComp,
9091
localStorage: LocalStorageComp,

client/packages/lowcoder/src/comps/hooks/hookCompTypes.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const AllHookComp = [
88
"currentTime",
99
"lodashJsLib",
1010
"dayJsLib",
11+
"momentJsLib",
1112
"utils",
1213
"message",
1314
"localStorage",
@@ -46,6 +47,9 @@ const HookCompConfig: Record<
4647
dayJsLib: {
4748
category: "hide",
4849
},
50+
momentJsLib: {
51+
category: "hide",
52+
},
4953
utils: { category: "hide" },
5054
message: { category: "hide" },
5155
};

client/packages/lowcoder/src/comps/hooks/hookListComp.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const defaultHookListValue = [
1616
// { compType: "windowSize", name: "windowSize" },
1717
{ compType: "urlParams", name: "url" },
1818
{ compType: "dayJsLib", name: "dayjs" },
19+
// { compType: "momentJsLib", name: "dayjs" },
1920
{ compType: "lodashJsLib", name: "_" },
2021
{ compType: "utils", name: "utils" },
2122
{ compType: "message", name: "message" },

client/packages/lowcoder/src/comps/utils/propertyUtils.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,12 @@ export const formatPropertyView = (params: {
109109
{trans("date.reference")} &nbsp;
110110
<a
111111
href={`${
112-
language === "zh" ? "http://momentjs.cn" : "http://momentjs.com"
113-
}/docs/#/displaying/format/`}
112+
language === "zh" ? "https://day.js.org/docs/zh-CN" : "https://day.js.org/docs/en"
113+
}/display/format`}
114114
target={"_blank"}
115115
rel="noreferrer"
116116
>
117-
momentjs format
117+
dayjs format
118118
</a>
119119
</>
120120
),

0 commit comments

Comments
 (0)