@@ -50,6 +50,8 @@ import { DateRangeUIView } from "comps/comps/dateComp/dateRangeUIView";
5050import { EditorContext } from "comps/editorState" ;
5151import { dropdownControl } from "comps/controls/dropdownControl" ;
5252import { timeZoneOptions } from "./timeZone" ;
53+ import { migrateOldData } from "@lowcoder-ee/comps/generators/simpleGenerators" ;
54+ import { fixOldInputCompData } from "../textInputComp/textInputConstants" ;
5355
5456
5557
@@ -142,6 +144,7 @@ function validate(
142144}
143145
144146const childrenMap = {
147+ defaultValue : stringExposingStateControl ( "defaultValue" ) ,
145148 value : stringExposingStateControl ( "value" ) ,
146149 userTimeZone : stringExposingStateControl ( "userTimeZone" , Intl . DateTimeFormat ( ) . resolvedOptions ( ) . timeZone ) ,
147150 ...commonChildren ,
@@ -170,18 +173,25 @@ export type DateCompViewProps = Pick<
170173 placeholder ?: string | [ string , string ] ;
171174} ;
172175
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+
174180 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 ) ;
177183 }
178184
179185 const [ tempValue , setTempValue ] = useState < dayjs . Dayjs | null > ( time ) ;
180186
181187 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 ] )
185195
186196 const handleDateZoneChange = ( newTimeZone : any ) => {
187197 props . userTimeZone . onChange ( newTimeZone )
@@ -234,7 +244,7 @@ export const datePickerControl = new UICompBuilder(childrenMap, (props) => {
234244 return (
235245 < >
236246 < Section name = { sectionNames . basic } >
237- { children . value . propertyView ( {
247+ { children . defaultValue . propertyView ( {
238248 label : trans ( "prop.defaultValue" ) ,
239249 placeholder : "2022-04-07 21:39:59" ,
240250 tooltip : trans ( "date.formatTip" )
@@ -304,38 +314,76 @@ export const datePickerControl = new UICompBuilder(childrenMap, (props) => {
304314 . setExposeMethodConfigs ( dateRefMethods )
305315 . build ( ) ;
306316
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 ( ) {
308340 const childrenMap = {
341+ defaultStart : stringExposingStateControl ( "defaultStart" ) ,
309342 start : stringExposingStateControl ( "start" ) ,
343+ defaultEnd : stringExposingStateControl ( "defaultEnd" ) ,
310344 end : stringExposingStateControl ( "end" ) ,
311345 userRangeTimeZone : stringExposingStateControl ( "userRangeTimeZone" , Intl . DateTimeFormat ( ) . resolvedOptions ( ) . timeZone ) ,
312346 ...formDataChildren ,
313347 ...commonChildren ,
314348 } ;
315349
316350 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+
317357 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 ) ;
320360 }
321361
322362 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 ) ;
325365 }
326366
327367 const [ tempStartValue , setTempStartValue ] = useState < dayjs . Dayjs | null > ( start ) ;
328368 const [ tempEndValue , setTempEndValue ] = useState < dayjs . Dayjs | null > ( end ) ;
329369
330370 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 ;
332380 setTempStartValue ( value ) ;
333- } , [ props . start . value ] )
381+ } , [ startValue ] )
334382
335383 useEffect ( ( ) => {
336- const value = props . end . value ? dayjs ( props . end . value , DateParser ) : null ;
384+ const value = endValue ? dayjs ( endValue , DateParser ) : null ;
337385 setTempEndValue ( value ) ;
338- } , [ props . end . value ] )
386+ } , [ endValue ] )
339387
340388
341389 const handleDateRangeZoneChange = ( newTimeZone : any ) => {
@@ -399,12 +447,12 @@ export const dateRangeControl = (function () {
399447 return (
400448 < >
401449 < Section name = { sectionNames . basic } >
402- { children . start . propertyView ( {
450+ { children . defaultStart . propertyView ( {
403451 label : trans ( "date.start" ) ,
404452 placeholder : "2022-04-07 21:39:59" ,
405453 tooltip : trans ( "date.formatTip" ) ,
406454 } ) }
407- { children . end . propertyView ( {
455+ { children . defaultEnd . propertyView ( {
408456 label : trans ( "date.end" ) ,
409457 placeholder : "2022-04-07 21:39:59" ,
410458 tooltip : trans ( "date.formatTip" ) ,
@@ -471,6 +519,8 @@ export const dateRangeControl = (function () {
471519 . build ( ) ;
472520} ) ( ) ;
473521
522+ export const dateRangeControl = migrateOldData ( DateRangeTmpCmp , fixOldDateOrTimeRangeData ) ;
523+
474524const getTimeZoneInfo = ( timeZone : any , otherTimeZone : any ) => {
475525 const tz = timeZone === 'UserChoice' ? otherTimeZone : timeZone ;
476526
0 commit comments