Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 32e8c4d

Browse files
Merge pull request #1309 from lowcoder-org/fixes/listview
Fixes/listview
2 parents d11e2ec + 079e482 commit 32e8c4d

File tree

3 files changed

+130
-39
lines changed

3 files changed

+130
-39
lines changed

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

Lines changed: 68 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ import { DateRangeUIView } from "comps/comps/dateComp/dateRangeUIView";
5050
import { EditorContext } from "comps/editorState";
5151
import { dropdownControl } from "comps/controls/dropdownControl";
5252
import { 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

144146
const 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+
474524
const getTimeZoneInfo = (timeZone: any, otherTimeZone: any) => {
475525
const tz = timeZone === 'UserChoice' ? otherTimeZone : timeZone;
476526

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

Lines changed: 49 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ import { TimePickerProps } from "antd/es/time-picker";
5454
import { EditorContext } from "comps/editorState";
5555
import { dropdownControl } from "comps/controls/dropdownControl";
5656
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";
5860

5961
const EventOptions = [changeEvent, focusEvent, blurEvent] as const;
6062

@@ -124,6 +126,7 @@ function validate(
124126
}
125127

126128
const 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+
426456
const getTimeZoneInfo = (timeZone: any, otherTimeZone: any) => {
427457
const tz = timeZone === 'UserChoice' ? otherTimeZone : timeZone;
428458

‎client/packages/lowcoder/src/comps/comps/switchComp.tsx‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { trans } from "i18n";
1616
import { RefControl } from "comps/controls/refControl";
1717
import { refMethods } from "comps/generators/withMethodExposing";
1818
import { blurMethod, clickMethod, focusWithOptions } from "comps/utils/methodUtils";
19+
import { fixOldInputCompData } from "./textInputComp/textInputConstants";
1920

2021
import { useContext, useEffect } from "react";
2122
import { EditorContext } from "comps/editorState";
@@ -88,6 +89,7 @@ function fixOldData(oldData: any) {
8889
*/
8990
let SwitchTmpComp = (function () {
9091
const childrenMap = {
92+
defaultValue: booleanExposingStateControl("defaultValue"),
9193
value: booleanExposingStateControl("value"),
9294
label: LabelControl,
9395
onEvent: eventHandlerControl(EventOptions),
@@ -105,6 +107,13 @@ let SwitchTmpComp = (function () {
105107
...formDataChildren,
106108
};
107109
return new UICompBuilder(childrenMap, (props) => {
110+
const defaultValue = { ...props.defaultValue }.value;
111+
const value = { ...props.value }.value;
112+
113+
useEffect(() => {
114+
props.value.onChange(defaultValue);
115+
}, [defaultValue]);
116+
108117
return props.label({
109118
style: props.style,
110119
labelStyle: props.labelStyle,
@@ -113,7 +122,7 @@ let SwitchTmpComp = (function () {
113122
children: (
114123
<SwitchWrapper disabled={props.disabled} $style={props.inputFieldStyle}>
115124
<Switch
116-
checked={props.value.value}
125+
checked={value}
117126
disabled={props.disabled}
118127
ref={props.viewRef}
119128
onChange={(checked) => {
@@ -130,7 +139,7 @@ let SwitchTmpComp = (function () {
130139
return (
131140
<>
132141
<Section name={sectionNames.basic}>
133-
{children.value.propertyView({ label: trans("switchComp.defaultValue") })}
142+
{children.defaultValue.propertyView({ label: trans("switchComp.defaultValue") })}
134143
</Section>
135144

136145
<FormDataPropertyView {...children} />
@@ -170,6 +179,8 @@ let SwitchTmpComp = (function () {
170179
.build();
171180
})();
172181

182+
SwitchTmpComp = migrateOldData(SwitchTmpComp, fixOldInputCompData);
183+
173184
export const SwitchComp = withExposingConfigs(SwitchTmpComp, [
174185
new NameConfig("value", trans("switchComp.valueDesc")),
175186
...CommonNameConfig,

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /