@@ -54,7 +54,9 @@ import { TimePickerProps } from "antd/es/time-picker";
5454import { EditorContext } from "comps/editorState" ;
5555import { dropdownControl } from "comps/controls/dropdownControl" ;
5656import { timeZoneOptions } from "./timeZone" ;
57-
57+ import { migrateOldData } from "@lowcoder-ee/comps/generators/simpleGenerators" ;
58+ import { fixOldInputCompData } from "../textInputComp/textInputConstants" ;
59+ import { fixOldDateOrTimeRangeData } from "./dateComp" ;
5860
5961const EventOptions = [ changeEvent , focusEvent , blurEvent ] as const ;
6062
@@ -124,6 +126,7 @@ function validate(
124126}
125127
126128const childrenMap = {
129+ defaultValue : stringExposingStateControl ( "defaultValue" ) ,
127130 value : stringExposingStateControl ( "value" ) ,
128131 userTimeZone : stringExposingStateControl ( "userTimeZone" , Intl . DateTimeFormat ( ) . resolvedOptions ( ) . timeZone ) ,
129132 ...commonChildren ,
@@ -149,18 +152,25 @@ export type TimeCompViewProps = Pick<
149152 timeZone :string
150153} ;
151154
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+
153159 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 ) ;
156162 }
157163
158164 const [ tempValue , setTempValue ] = useState < dayjs . Dayjs | null > ( time ) ;
159165
160166 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 ] )
164174
165175 const handleTimeZoneChange = ( newTimeZone : any ) => {
166176 props . userTimeZone . onChange ( newTimeZone )
@@ -205,7 +215,7 @@ export const timePickerControl = new UICompBuilder(childrenMap, (props) => {
205215 . setPropertyViewFn ( ( children ) => (
206216 < >
207217 < Section name = { sectionNames . basic } >
208- { children . value . propertyView ( {
218+ { children . defaultValue . propertyView ( {
209219 label : trans ( "prop.defaultValue" ) ,
210220 tooltip : trans ( "time.formatTip" ) ,
211221 } ) }
@@ -270,37 +280,55 @@ export const timePickerControl = new UICompBuilder(childrenMap, (props) => {
270280 . setExposeMethodConfigs ( dateRefMethods )
271281 . build ( ) ;
272282
273- export const timeRangeControl = ( function ( ) {
283+ export const timePickerControl = migrateOldData ( TimePickerTmpCmp , fixOldInputCompData ) ;
284+
285+ const TimeRangeTmpCmp = ( function ( ) {
274286 const childrenMap = {
287+ defaultStart : stringExposingStateControl ( "defaultStart" ) ,
275288 start : stringExposingStateControl ( "start" ) ,
289+ defaultEnd : stringExposingStateControl ( "defaultEnd" ) ,
276290 end : stringExposingStateControl ( "end" ) ,
277291 userRangeTimeZone : stringExposingStateControl ( "userRangeTimeZone" , Intl . DateTimeFormat ( ) . resolvedOptions ( ) . timeZone ) ,
278292 ...formDataChildren ,
279293 ...commonChildren ,
280294 } ;
281295
282296 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+
283303 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 ) ;
286306 }
287307 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 ) ;
290310 }
291311
292312 const [ tempStartValue , setTempStartValue ] = useState < dayjs . Dayjs | null > ( start ) ;
293313 const [ tempEndValue , setTempEndValue ] = useState < dayjs . Dayjs | null > ( end ) ;
294314
295315 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 ;
297325 setTempStartValue ( value ) ;
298- } , [ props . start . value ] )
326+ } , [ startValue ] )
299327
300328 useEffect ( ( ) => {
301- const value = props . end . value ? dayjs ( props . end . value , TimeParser ) : null ;
329+ const value = endValue ? dayjs ( endValue , TimeParser ) : null ;
302330 setTempEndValue ( value ) ;
303- } , [ props . end . value ] )
331+ } , [ endValue ] )
304332
305333 const handleTimeRangeZoneChange = ( newTimeZone : any ) => {
306334 props . userRangeTimeZone . onChange ( newTimeZone )
@@ -354,11 +382,11 @@ export const timeRangeControl = (function () {
354382 . setPropertyViewFn ( ( children ) => (
355383 < >
356384 < Section name = { sectionNames . basic } >
357- { children . start . propertyView ( {
385+ { children . defaultStart . propertyView ( {
358386 label : trans ( "time.start" ) ,
359387 tooltip : trans ( "time.formatTip" ) ,
360388 } ) }
361- { children . end . propertyView ( {
389+ { children . defaultEnd . propertyView ( {
362390 label : trans ( "time.end" ) ,
363391 tooltip : trans ( "time.formatTip" ) ,
364392 } ) }
@@ -423,6 +451,8 @@ export const timeRangeControl = (function () {
423451 . build ( ) ;
424452} ) ( ) ;
425453
454+ export const timeRangeControl = migrateOldData ( TimeRangeTmpCmp , fixOldDateOrTimeRangeData ) ;
455+
426456const getTimeZoneInfo = ( timeZone : any , otherTimeZone : any ) => {
427457 const tz = timeZone === 'UserChoice' ? otherTimeZone : timeZone ;
428458
0 commit comments