@@ -54,7 +54,9 @@ import { TimePickerProps } from "antd/es/time-picker";
54
54
import { EditorContext } from "comps/editorState" ;
55
55
import { dropdownControl } from "comps/controls/dropdownControl" ;
56
56
import { timeZoneOptions } from "./timeZone" ;
57
-
57
+ import { migrateOldData } from "@lowcoder-ee/comps/generators/simpleGenerators" ;
58
+ import { fixOldInputCompData } from "../textInputComp/textInputConstants" ;
59
+ import { fixOldDateOrTimeRangeData } from "./dateComp" ;
58
60
59
61
const EventOptions = [ changeEvent , focusEvent , blurEvent ] as const ;
60
62
@@ -124,6 +126,7 @@ function validate(
124
126
}
125
127
126
128
const childrenMap = {
129
+ defaultValue : stringExposingStateControl ( "defaultValue" ) ,
127
130
value : stringExposingStateControl ( "value" ) ,
128
131
userTimeZone : stringExposingStateControl ( "userTimeZone" , Intl . DateTimeFormat ( ) . resolvedOptions ( ) . timeZone ) ,
129
132
...commonChildren ,
@@ -149,18 +152,25 @@ export type TimeCompViewProps = Pick<
149
152
timeZone :string
150
153
} ;
151
154
152
- export const timePickerControl = new UICompBuilder ( childrenMap , ( props ) => {
155
+ const TimePickerTmpCmp = new UICompBuilder ( childrenMap , ( props ) => {
156
+ const defaultValue = { ...props . defaultValue } . value ;
157
+ const value = { ...props . value } . value ;
158
+
153
159
let time : dayjs . Dayjs | null = null ;
154
- if ( props . value . value !== '' ) {
155
- time = dayjs ( props . value . value , TimeParser ) ;
160
+ if ( value !== '' ) {
161
+ time = dayjs ( value , TimeParser ) ;
156
162
}
157
163
158
164
const [ tempValue , setTempValue ] = useState < dayjs . Dayjs | null > ( time ) ;
159
165
160
166
useEffect ( ( ) => {
161
- const value = props . value . value ? dayjs ( props . value . value , TimeParser ) : null ;
162
- setTempValue ( value ) ;
163
- } , [ props . value . value ] )
167
+ props . value . onChange ( defaultValue ) ;
168
+ } , [ defaultValue ] ) ;
169
+
170
+ useEffect ( ( ) => {
171
+ const newValue = value ? dayjs ( value , TimeParser ) : null ;
172
+ setTempValue ( newValue ) ;
173
+ } , [ value ] )
164
174
165
175
const handleTimeZoneChange = ( newTimeZone : any ) => {
166
176
props . userTimeZone . onChange ( newTimeZone )
@@ -205,7 +215,7 @@ export const timePickerControl = new UICompBuilder(childrenMap, (props) => {
205
215
. setPropertyViewFn ( ( children ) => (
206
216
< >
207
217
< Section name = { sectionNames . basic } >
208
- { children . value . propertyView ( {
218
+ { children . defaultValue . propertyView ( {
209
219
label : trans ( "prop.defaultValue" ) ,
210
220
tooltip : trans ( "time.formatTip" ) ,
211
221
} ) }
@@ -270,37 +280,55 @@ export const timePickerControl = new UICompBuilder(childrenMap, (props) => {
270
280
. setExposeMethodConfigs ( dateRefMethods )
271
281
. build ( ) ;
272
282
273
- export const timeRangeControl = ( function ( ) {
283
+ export const timePickerControl = migrateOldData ( TimePickerTmpCmp , fixOldInputCompData ) ;
284
+
285
+ const TimeRangeTmpCmp = ( function ( ) {
274
286
const childrenMap = {
287
+ defaultStart : stringExposingStateControl ( "defaultStart" ) ,
275
288
start : stringExposingStateControl ( "start" ) ,
289
+ defaultEnd : stringExposingStateControl ( "defaultEnd" ) ,
276
290
end : stringExposingStateControl ( "end" ) ,
277
291
userRangeTimeZone : stringExposingStateControl ( "userRangeTimeZone" , Intl . DateTimeFormat ( ) . resolvedOptions ( ) . timeZone ) ,
278
292
...formDataChildren ,
279
293
...commonChildren ,
280
294
} ;
281
295
282
296
return new UICompBuilder ( childrenMap , ( props ) => {
297
+ const defaultStart = { ...props . defaultStart } . value ;
298
+ const startValue = { ...props . start } . value ;
299
+
300
+ const defaultEnd = { ...props . defaultEnd } . value ;
301
+ const endValue = { ...props . end } . value ;
302
+
283
303
let start : dayjs . Dayjs | null = null ;
284
- if ( props . start . value !== '' ) {
285
- start = dayjs ( props . start . value , TimeParser ) ;
304
+ if ( startValue !== '' ) {
305
+ start = dayjs ( startValue , TimeParser ) ;
286
306
}
287
307
let end : dayjs . Dayjs | null = null ;
288
- if ( props . end . value !== '' ) {
289
- end = dayjs ( props . end . value , TimeParser ) ;
308
+ if ( endValue !== '' ) {
309
+ end = dayjs ( endValue , TimeParser ) ;
290
310
}
291
311
292
312
const [ tempStartValue , setTempStartValue ] = useState < dayjs . Dayjs | null > ( start ) ;
293
313
const [ tempEndValue , setTempEndValue ] = useState < dayjs . Dayjs | null > ( end ) ;
294
314
295
315
useEffect ( ( ) => {
296
- const value = props . start . value ? dayjs ( props . start . value , TimeParser ) : null ;
316
+ props . start . onChange ( defaultStart ) ;
317
+ } , [ defaultStart ] ) ;
318
+
319
+ useEffect ( ( ) => {
320
+ props . end . onChange ( defaultEnd ) ;
321
+ } , [ defaultEnd ] ) ;
322
+
323
+ useEffect ( ( ) => {
324
+ const value = startValue ? dayjs ( startValue , TimeParser ) : null ;
297
325
setTempStartValue ( value ) ;
298
- } , [ props . start . value ] )
326
+ } , [ startValue ] )
299
327
300
328
useEffect ( ( ) => {
301
- const value = props . end . value ? dayjs ( props . end . value , TimeParser ) : null ;
329
+ const value = endValue ? dayjs ( endValue , TimeParser ) : null ;
302
330
setTempEndValue ( value ) ;
303
- } , [ props . end . value ] )
331
+ } , [ endValue ] )
304
332
305
333
const handleTimeRangeZoneChange = ( newTimeZone : any ) => {
306
334
props . userRangeTimeZone . onChange ( newTimeZone )
@@ -354,11 +382,11 @@ export const timeRangeControl = (function () {
354
382
. setPropertyViewFn ( ( children ) => (
355
383
< >
356
384
< Section name = { sectionNames . basic } >
357
- { children . start . propertyView ( {
385
+ { children . defaultStart . propertyView ( {
358
386
label : trans ( "time.start" ) ,
359
387
tooltip : trans ( "time.formatTip" ) ,
360
388
} ) }
361
- { children . end . propertyView ( {
389
+ { children . defaultEnd . propertyView ( {
362
390
label : trans ( "time.end" ) ,
363
391
tooltip : trans ( "time.formatTip" ) ,
364
392
} ) }
@@ -423,6 +451,8 @@ export const timeRangeControl = (function () {
423
451
. build ( ) ;
424
452
} ) ( ) ;
425
453
454
+ export const timeRangeControl = migrateOldData ( TimeRangeTmpCmp , fixOldDateOrTimeRangeData ) ;
455
+
426
456
const getTimeZoneInfo = ( timeZone : any , otherTimeZone : any ) => {
427
457
const tz = timeZone === 'UserChoice' ? otherTimeZone : timeZone ;
428
458
0 commit comments