@@ -50,6 +50,8 @@ import { DateRangeUIView } from "comps/comps/dateComp/dateRangeUIView";
50
50
import { EditorContext } from "comps/editorState" ;
51
51
import { dropdownControl } from "comps/controls/dropdownControl" ;
52
52
import { timeZoneOptions } from "./timeZone" ;
53
+ import { migrateOldData } from "@lowcoder-ee/comps/generators/simpleGenerators" ;
54
+ import { fixOldInputCompData } from "../textInputComp/textInputConstants" ;
53
55
54
56
55
57
@@ -142,6 +144,7 @@ function validate(
142
144
}
143
145
144
146
const childrenMap = {
147
+ defaultValue : stringExposingStateControl ( "defaultValue" ) ,
145
148
value : stringExposingStateControl ( "value" ) ,
146
149
userTimeZone : stringExposingStateControl ( "userTimeZone" , Intl . DateTimeFormat ( ) . resolvedOptions ( ) . timeZone ) ,
147
150
...commonChildren ,
@@ -170,18 +173,25 @@ export type DateCompViewProps = Pick<
170
173
placeholder ?: string | [ string , string ] ;
171
174
} ;
172
175
173
- export const datePickerControl = new UICompBuilder ( childrenMap , ( props ) => {
176
+ const DatePickerTmpCmp = new UICompBuilder ( childrenMap , ( props ) => {
177
+ const defaultValue = { ...props . defaultValue } . value ;
178
+ const value = { ...props . value } . value ;
179
+
174
180
let time : dayjs . Dayjs | null = null ;
175
- if ( props . value . value !== '' ) {
176
- time = dayjs ( props . value . value , DateParser ) ;
181
+ if ( value !== '' ) {
182
+ time = dayjs ( value , DateParser ) ;
177
183
}
178
184
179
185
const [ tempValue , setTempValue ] = useState < dayjs . Dayjs | null > ( time ) ;
180
186
181
187
useEffect ( ( ) => {
182
- const value = props . value . value ? dayjs ( props . value . value , DateParser ) : null ;
183
- setTempValue ( value ) ;
184
- } , [ props . value . value ] )
188
+ props . value . onChange ( defaultValue ) ;
189
+ } , [ defaultValue ] ) ;
190
+
191
+ useEffect ( ( ) => {
192
+ const newValue = value ? dayjs ( value , DateParser ) : null ;
193
+ setTempValue ( newValue ) ;
194
+ } , [ value ] )
185
195
186
196
const handleDateZoneChange = ( newTimeZone : any ) => {
187
197
props . userTimeZone . onChange ( newTimeZone )
@@ -234,7 +244,7 @@ export const datePickerControl = new UICompBuilder(childrenMap, (props) => {
234
244
return (
235
245
< >
236
246
< Section name = { sectionNames . basic } >
237
- { children . value . propertyView ( {
247
+ { children . defaultValue . propertyView ( {
238
248
label : trans ( "prop.defaultValue" ) ,
239
249
placeholder : "2022-04-07 21:39:59" ,
240
250
tooltip : trans ( "date.formatTip" )
@@ -304,38 +314,76 @@ export const datePickerControl = new UICompBuilder(childrenMap, (props) => {
304
314
. setExposeMethodConfigs ( dateRefMethods )
305
315
. build ( ) ;
306
316
307
- export const dateRangeControl = ( function ( ) {
317
+ export const datePickerControl = migrateOldData ( DatePickerTmpCmp , fixOldInputCompData ) ;
318
+
319
+ export function fixOldDateOrTimeRangeData ( oldData : any ) {
320
+ if ( ! oldData ) return oldData ;
321
+
322
+ let { defaultStart, defaultEnd} = oldData
323
+ if ( Boolean ( oldData . start ) && ! Boolean ( oldData . defaultStart ) ) {
324
+ defaultStart = oldData . start ;
325
+ }
326
+ if ( Boolean ( oldData . end ) && ! Boolean ( oldData . defaultEnd ) ) {
327
+ defaultEnd = oldData . end ;
328
+ }
329
+ return {
330
+ ...oldData ,
331
+ defaultStart,
332
+ defaultEnd,
333
+ start : '' ,
334
+ end : '' ,
335
+ } ;
336
+ // return oldData;
337
+ }
338
+
339
+ let DateRangeTmpCmp = ( function ( ) {
308
340
const childrenMap = {
341
+ defaultStart : stringExposingStateControl ( "defaultStart" ) ,
309
342
start : stringExposingStateControl ( "start" ) ,
343
+ defaultEnd : stringExposingStateControl ( "defaultEnd" ) ,
310
344
end : stringExposingStateControl ( "end" ) ,
311
345
userRangeTimeZone : stringExposingStateControl ( "userRangeTimeZone" , Intl . DateTimeFormat ( ) . resolvedOptions ( ) . timeZone ) ,
312
346
...formDataChildren ,
313
347
...commonChildren ,
314
348
} ;
315
349
316
350
return new UICompBuilder ( childrenMap , ( props ) => {
351
+ const defaultStart = { ...props . defaultStart } . value ;
352
+ const startValue = { ...props . start } . value ;
353
+
354
+ const defaultEnd = { ...props . defaultEnd } . value ;
355
+ const endValue = { ...props . end } . value ;
356
+
317
357
let start : dayjs . Dayjs | null = null ;
318
- if ( props . start . value !== '' ) {
319
- start = dayjs ( props . start . value , DateParser ) ;
358
+ if ( startValue !== '' ) {
359
+ start = dayjs ( startValue , DateParser ) ;
320
360
}
321
361
322
362
let end : dayjs . Dayjs | null = null ;
323
- if ( props . end . value !== '' ) {
324
- end = dayjs ( props . end . value , DateParser ) ;
363
+ if ( endValue !== '' ) {
364
+ end = dayjs ( endValue , DateParser ) ;
325
365
}
326
366
327
367
const [ tempStartValue , setTempStartValue ] = useState < dayjs . Dayjs | null > ( start ) ;
328
368
const [ tempEndValue , setTempEndValue ] = useState < dayjs . Dayjs | null > ( end ) ;
329
369
330
370
useEffect ( ( ) => {
331
- const value = props . start . value ? dayjs ( props . start . value , DateParser ) : null ;
371
+ props . start . onChange ( defaultStart ) ;
372
+ } , [ defaultStart ] ) ;
373
+
374
+ useEffect ( ( ) => {
375
+ props . end . onChange ( defaultEnd ) ;
376
+ } , [ defaultEnd ] ) ;
377
+
378
+ useEffect ( ( ) => {
379
+ const value = startValue ? dayjs ( startValue , DateParser ) : null ;
332
380
setTempStartValue ( value ) ;
333
- } , [ props . start . value ] )
381
+ } , [ startValue ] )
334
382
335
383
useEffect ( ( ) => {
336
- const value = props . end . value ? dayjs ( props . end . value , DateParser ) : null ;
384
+ const value = endValue ? dayjs ( endValue , DateParser ) : null ;
337
385
setTempEndValue ( value ) ;
338
- } , [ props . end . value ] )
386
+ } , [ endValue ] )
339
387
340
388
341
389
const handleDateRangeZoneChange = ( newTimeZone : any ) => {
@@ -399,12 +447,12 @@ export const dateRangeControl = (function () {
399
447
return (
400
448
< >
401
449
< Section name = { sectionNames . basic } >
402
- { children . start . propertyView ( {
450
+ { children . defaultStart . propertyView ( {
403
451
label : trans ( "date.start" ) ,
404
452
placeholder : "2022-04-07 21:39:59" ,
405
453
tooltip : trans ( "date.formatTip" ) ,
406
454
} ) }
407
- { children . end . propertyView ( {
455
+ { children . defaultEnd . propertyView ( {
408
456
label : trans ( "date.end" ) ,
409
457
placeholder : "2022-04-07 21:39:59" ,
410
458
tooltip : trans ( "date.formatTip" ) ,
@@ -471,6 +519,8 @@ export const dateRangeControl = (function () {
471
519
. build ( ) ;
472
520
} ) ( ) ;
473
521
522
+ export const dateRangeControl = migrateOldData ( DateRangeTmpCmp , fixOldDateOrTimeRangeData ) ;
523
+
474
524
const getTimeZoneInfo = ( timeZone : any , otherTimeZone : any ) => {
475
525
const tz = timeZone === 'UserChoice' ? otherTimeZone : timeZone ;
476
526
0 commit comments