Skip to content

Commit ad537a3

Browse files
authored
Merge pull request #675 from raheeliftikhar5/bug-fixes-2-6
Bug fixes
2 parents 697c308 + 50bf25a commit ad537a3

22 files changed

+223
-78
lines changed

client/packages/lowcoder/src/comps/comps/buttonComp/dropdownComp.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,16 @@ const DropdownTmpComp = (function () {
8383
key: option.label + " - " + index,
8484
disabled: option.disabled,
8585
icon: hasIcon && <span>{option.prefixIcon}</span>,
86-
onEvent: option.onEvent,
86+
index,
8787
}));
8888

8989
const menu = (
9090
<Menu
9191
items={items}
92-
onClick={({ key }) => items.find((o) => o.key === key)?.onEvent("click")}
92+
onClick={({ key }) => {
93+
const item = items.find((o) => o.key === key);
94+
item && props.options[item.index]?.onEvent("click");
95+
}}
9396
/>
9497
);
9598

client/packages/lowcoder/src/comps/comps/listViewComp/listView.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,10 @@ export function ListView(props: Props) {
176176
return <div key={itemIdx} style={{ flex: "auto" }}></div>;
177177
}
178178
const containerProps = containerFn(
179-
{ [itemIndexName]: itemIdx, [itemDataName]: getCurrentItemParams(data, itemIdx) },
179+
{
180+
[itemIndexName]: itemIdx,
181+
[itemDataName]: getCurrentItemParams(data, itemIdx)
182+
},
180183
String(itemIdx)
181184
).getView();
182185
const unMountFn = () => {

client/packages/lowcoder/src/comps/comps/listViewComp/listViewComp.tsx

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
} from "comps/controls/codeControl";
88
import { styleControl } from "comps/controls/styleControl";
99
import { ListViewStyle } from "comps/controls/styleControlConstants";
10-
import { UICompBuilder, withDefault, withPropertyViewFn, withViewFn } from "comps/generators";
10+
import { UICompBuilder, stateComp, valueComp, withDefault, withPropertyViewFn, withViewFn } from "comps/generators";
1111
import {
1212
CompDepsConfig,
1313
depsConfig,
@@ -37,6 +37,7 @@ import { ContextContainerComp } from "./contextContainerComp";
3737
import { ListView } from "./listView";
3838
import { listPropertyView } from "./listViewPropertyView";
3939
import { getData } from "./listViewUtils";
40+
import { withMethodExposing } from "comps/generators/withMethodExposing";
4041

4142
const childrenMap = {
4243
noOfRows: withIsLoadingMethod(NumberOrJSONObjectArrayControl), // FIXME: migrate "noOfRows" to "data"
@@ -80,10 +81,10 @@ export class ListViewImplComp extends ListViewTmpComp implements IContainer {
8081
}
8182
override reduce(action: CompAction): this {
8283
// console.info("listView reduce. action: ", action);
83-
8484
let comp = reduceInContext({ inEventContext: true }, () => super.reduce(action));
85+
8586
if (action.type === CompActionTypes.UPDATE_NODES_V2) {
86-
const { itemCount } = getData(comp.children.noOfRows.getView());
87+
const { itemCount} = getData(comp.children.noOfRows.getView());
8788
const pagination = comp.children.pagination.getView();
8889
const total = pagination.total || itemCount;
8990
const offset = (pagination.current - 1) * pagination.pageSize;
@@ -151,11 +152,11 @@ export class ListViewImplComp extends ListViewTmpComp implements IContainer {
151152

152153
const ListViewRenderComp = withViewFn(ListViewImplComp, (comp) => <ListView comp={comp} />);
153154
const ListPropertyView = listPropertyView("listView");
154-
const ListViewPropertyComp = withPropertyViewFn(ListViewRenderComp, (comp) => {
155+
let ListViewPropertyComp = withPropertyViewFn(ListViewRenderComp, (comp) => {
155156
return <ListPropertyView comp={comp} />;
156157
});
157158

158-
export const ListViewComp = withExposingConfigs(ListViewPropertyComp, [
159+
ListViewPropertyComp = withExposingConfigs(ListViewPropertyComp, [
159160
new CompDepsConfig(
160161
"items",
161162
(comp) => ({ data: comp.itemsNode() }),
@@ -171,9 +172,31 @@ export const ListViewComp = withExposingConfigs(ListViewPropertyComp, [
171172
return data;
172173
},
173174
}),
175+
// new CompDepsConfig(
176+
// "index",
177+
// (comp) => ({index: comp.children.itemIndexName.node() }),
178+
// (input) => input.index.value,
179+
// "index", // trans("listView.itemsDesc")
180+
// ),
174181
NameConfigHidden,
175182
]);
176183

184+
export const ListViewComp = withMethodExposing(ListViewPropertyComp, [
185+
{
186+
method: {
187+
name: "setPage",
188+
description: "",
189+
params: [{ name: "page", type: "number" }],
190+
},
191+
execute: (comp, values) => {
192+
const page = values[0] as number;
193+
if (page && page > 0) {
194+
comp.children.pagination.children.pageNo.dispatchChangeValueAction(page);
195+
}
196+
},
197+
},
198+
])
199+
177200
export function defaultListViewData(compName: string, nameGenerator: NameGenerator) {
178201
return {
179202
noOfRows:
@@ -232,7 +255,7 @@ export function defaultListViewData(compName: string, nameGenerator: NameGenerat
232255
compType: "rating",
233256
name: nameGenerator.genItemName("rating"),
234257
comp: {
235-
value: "{{currentItem.rate / 2}}",
258+
defaultValue: "{{currentItem.rate / 2}}",
236259
max: "5",
237260
label: {
238261
text: "",

client/packages/lowcoder/src/comps/comps/numberInputComp/numberInputComp.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
import { BoolControl } from "comps/controls/boolControl";
1111
import { dropdownControl } from "comps/controls/dropdownControl";
1212
import { LabelControl } from "comps/controls/labelControl";
13-
import { numberExposingStateControl } from "comps/controls/codeStateControl";
13+
import { numberExposingStateControl, stringExposingStateControl } from "comps/controls/codeStateControl";
1414
import NP from "number-precision";
1515

1616
import {
@@ -234,6 +234,7 @@ const UndefinedNumberControl = codeControl<number | undefined>((value: any) => {
234234
});
235235

236236
const childrenMap = {
237+
defaultValue: stringExposingStateControl("defaultValue"), // It is more convenient for string to handle various states, save raw input here
237238
value: numberExposingStateControl("value"), // It is more convenient for string to handle various states, save raw input here
238239
placeholder: StringControl,
239240
disabled: BoolCodeControl,
@@ -261,6 +262,17 @@ const childrenMap = {
261262

262263
const CustomInputNumber = (props: RecordConstructorToView<typeof childrenMap>) => {
263264
const ref = useRef<HTMLInputElement | null>(null);
265+
const defaultValue = props.defaultValue.value;
266+
267+
useEffect(() => {
268+
let value = 0;
269+
if (defaultValue === 'null' && props.allowNull) {
270+
value = NaN;
271+
} else if (!isNaN(Number(defaultValue))) {
272+
value = Number(defaultValue);
273+
}
274+
props.value.onChange(value);
275+
}, [defaultValue]);
264276

265277
const formatFn = (value: number) =>
266278
format(value, props.allowNull, props.formatter, props.precision, props.thousandsSeparator);
@@ -271,7 +283,9 @@ const CustomInputNumber = (props: RecordConstructorToView<typeof childrenMap>) =
271283
const oldValue = props.value.value;
272284
const newValue = parseNumber(tmpValue, props.allowNull);
273285
props.value.onChange(newValue);
274-
oldValue !== newValue && props.onEvent("change");
286+
if((oldValue !== newValue)) {
287+
props.onEvent("change");
288+
}
275289
};
276290

277291
useEffect(() => {
@@ -363,7 +377,7 @@ const NumberInputTmpComp = (function () {
363377
.setPropertyViewFn((children) => (
364378
<>
365379
<Section name={sectionNames.basic}>
366-
{children.value.propertyView({ label: trans("prop.defaultValue") })}
380+
{children.defaultValue.propertyView({ label: trans("prop.defaultValue") })}
367381
{placeholderPropertyView(children)}
368382
{children.formatter.propertyView({ label: trans("numberInput.formatter") })}
369383
</Section>

client/packages/lowcoder/src/comps/comps/ratingComp.tsx

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { migrateOldData } from "comps/generators/simpleGenerators";
1515
import { disabledPropertyView, hiddenPropertyView } from "comps/utils/propertyUtils";
1616
import { trans } from "i18n";
1717

18-
import { useContext } from "react";
18+
import { useContext, useEffect, useRef } from "react";
1919
import { EditorContext } from "comps/editorState";
2020

2121
const EventOptions = [changeEvent] as const;
@@ -36,6 +36,7 @@ function fixOldData(oldData: any) {
3636

3737
const RatingBasicComp = (function () {
3838
const childrenMap = {
39+
defaultValue: numberExposingStateControl("defaultValue"),
3940
value: numberExposingStateControl("value"),
4041
max: withDefault(NumberControl, "5"),
4142
label: LabelControl,
@@ -46,6 +47,21 @@ const RatingBasicComp = (function () {
4647
...formDataChildren,
4748
};
4849
return new UICompBuilder(childrenMap, (props) => {
50+
const defaultValue = { ...props.defaultValue }.value;
51+
const value = { ...props.value }.value;
52+
const changeRef = useRef(false)
53+
54+
useEffect(() => {
55+
props.value.onChange(defaultValue);
56+
}, [defaultValue]);
57+
58+
useEffect(() => {
59+
if (!changeRef.current) return;
60+
61+
props.onEvent("change");
62+
changeRef.current = false;
63+
}, [value]);
64+
4965
return props.label({
5066
style: props.style,
5167
children: (
@@ -54,7 +70,7 @@ const RatingBasicComp = (function () {
5470
value={props.value.value}
5571
onChange={(e) => {
5672
props.value.onChange(e);
57-
props.onEvent("change");
73+
changeRef.current = true;
5874
}}
5975
allowHalf={props.allowHalf}
6076
disabled={props.disabled}
@@ -67,7 +83,7 @@ const RatingBasicComp = (function () {
6783
return (
6884
<>
6985
<Section name={sectionNames.basic}>
70-
{children.value.propertyView({ label: trans("prop.defaultValue") })}
86+
{children.defaultValue.propertyView({ label: trans("prop.defaultValue") })}
7187
{children.max.propertyView({
7288
label: trans("rating.max"),
7389
})}

client/packages/lowcoder/src/comps/comps/selectInputComp/checkboxComp.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ const CheckboxGroup = styled(AntdCheckboxGroup)<{
102102

103103
const CheckboxBasicComp = (function () {
104104
const childrenMap = {
105-
value: arrayStringExposingStateControl("value", ["1"]),
105+
defaultValue: arrayStringExposingStateControl("defaultValue"),
106+
value: arrayStringExposingStateControl("value"),
106107
label: LabelControl,
107108
disabled: BoolCodeControl,
108109
onEvent: ChangeEventHandlerControl,
@@ -115,7 +116,10 @@ const CheckboxBasicComp = (function () {
115116
...formDataChildren,
116117
};
117118
return new UICompBuilder(childrenMap, (props) => {
118-
const [validateState, handleValidate] = useSelectInputValidate(props);
119+
const [
120+
validateState,
121+
handleChange,
122+
] = useSelectInputValidate(props);
119123
return props.label({
120124
required: props.required,
121125
style: props.style,
@@ -134,9 +138,7 @@ const CheckboxBasicComp = (function () {
134138
disabled: option.disabled,
135139
}))}
136140
onChange={(values) => {
137-
handleValidate(values as string[]);
138-
props.value.onChange(values as string[]);
139-
props.onEvent("change");
141+
handleChange(values as string[]);
140142
}}
141143
/>
142144
),

client/packages/lowcoder/src/comps/comps/selectInputComp/multiSelectComp.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,24 @@ import { SelectInputInvalidConfig, useSelectInputValidate } from "./selectInputC
1414

1515
import { PaddingControl } from "../../controls/paddingControl";
1616
import { MarginControl } from "../../controls/marginControl";
17+
import { useEffect, useRef } from "react";
1718

1819
const MultiSelectBasicComp = (function () {
1920
const childrenMap = {
2021
...SelectChildrenMap,
21-
value: arrayStringExposingStateControl("value", ["1", "2"]),
22+
defaultValue: arrayStringExposingStateControl("defaultValue", ["1", "2"]),
23+
value: arrayStringExposingStateControl("value"),
2224
style: styleControl(MultiSelectStyle),
2325
margin: MarginControl,
2426
padding: PaddingControl,
2527
};
2628
return new UICompBuilder(childrenMap, (props, dispatch) => {
2729
const valueSet = new Set<any>(props.options.map((o) => o.value)); // Filter illegal default values entered by the user
28-
const [validateState, handleValidate] = useSelectInputValidate(props);
30+
const [
31+
validateState,
32+
handleChange,
33+
] = useSelectInputValidate(props);
34+
2935
return props.label({
3036
required: props.required,
3137
style: props.style,
@@ -34,11 +40,7 @@ const MultiSelectBasicComp = (function () {
3440
{...props}
3541
mode={"multiple"}
3642
value={props.value.value.filter?.((v) => valueSet.has(v))}
37-
onChange={(value) => {
38-
handleValidate(value);
39-
props.value.onChange(value);
40-
props.onEvent("change");
41-
}}
43+
onChange={handleChange}
4244
dispatch={dispatch}
4345
/>
4446
),

client/packages/lowcoder/src/comps/comps/selectInputComp/radioComp.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@ const Radio = styled(AntdRadioGroup)<{
8383

8484
const RadioBasicComp = (function () {
8585
return new UICompBuilder(RadioChildrenMap, (props) => {
86-
const [validateState, handleValidate] = useSelectInputValidate(props);
86+
const [
87+
validateState,
88+
handleChange,
89+
] = useSelectInputValidate(props);
8790
return props.label({
8891
required: props.required,
8992
style: props.style,
@@ -95,9 +98,7 @@ const RadioBasicComp = (function () {
9598
$style={props.style}
9699
$layout={props.layout}
97100
onChange={(e) => {
98-
handleValidate(e.target.value);
99-
props.value.onChange(e.target.value);
100-
props.onEvent("change");
101+
handleChange(e.target.value);
101102
}}
102103
options={props.options
103104
.filter((option) => option.value !== undefined && !option.hidden)

client/packages/lowcoder/src/comps/comps/selectInputComp/radioCompConstants.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export const RadioLayoutOptions = [
3030
] as const;
3131

3232
export const RadioChildrenMap = {
33+
defaultValue: stringExposingStateControl("value"),
3334
value: stringExposingStateControl("value"),
3435
label: LabelControl,
3536
disabled: BoolCodeControl,
@@ -46,6 +47,9 @@ export const RadioChildrenMap = {
4647
export const RadioPropertyView = (
4748
children: RecordConstructorToComp<
4849
typeof RadioChildrenMap & { hidden: typeof BoolCodeControl } & {
50+
defaultValue:
51+
| ReturnType<typeof stringExposingStateControl>
52+
| ReturnType<typeof arrayStringExposingStateControl>;
4953
value:
5054
| ReturnType<typeof stringExposingStateControl>
5155
| ReturnType<typeof arrayStringExposingStateControl>;
@@ -55,7 +59,7 @@ export const RadioPropertyView = (
5559
<>
5660
<Section name={sectionNames.basic}>
5761
{children.options.propertyView({})}
58-
{children.value.propertyView({ label: trans("prop.defaultValue") })}
62+
{children.defaultValue.propertyView({ label: trans("prop.defaultValue") })}
5963
</Section>
6064

6165
{["logic", "both"].includes(useContext(EditorContext).editorModeStatus) && (

client/packages/lowcoder/src/comps/comps/selectInputComp/segmentedControl.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ const Segmented = styled(AntdSegmented)<{ $style: SegmentStyleType }>`
6262
`;
6363

6464
const SegmentChildrenMap = {
65+
defaultValue: stringExposingStateControl("value"),
6566
value: stringExposingStateControl("value"),
6667
label: LabelControl,
6768
disabled: BoolCodeControl,
@@ -76,7 +77,11 @@ const SegmentChildrenMap = {
7677

7778
const SegmentedControlBasicComp = (function () {
7879
return new UICompBuilder(SegmentChildrenMap, (props) => {
79-
const [validateState, handleValidate] = useSelectInputValidate(props);
80+
const [
81+
validateState,
82+
handleValidate,
83+
handleChange,
84+
] = useSelectInputValidate(props);
8085
return props.label({
8186
required: props.required,
8287
style: props.style,
@@ -88,9 +93,7 @@ const SegmentedControlBasicComp = (function () {
8893
value={props.value.value}
8994
$style={props.style}
9095
onChange={(value) => {
91-
handleValidate(value.toString());
92-
props.value.onChange(value.toString());
93-
props.onEvent("change");
96+
handleChange(value.toString());
9497
}}
9598
options={props.options
9699
.filter((option) => option.value !== undefined && !option.hidden)
@@ -109,7 +112,7 @@ const SegmentedControlBasicComp = (function () {
109112
<>
110113
<Section name={sectionNames.basic}>
111114
{children.options.propertyView({})}
112-
{children.value.propertyView({ label: trans("prop.defaultValue") })}
115+
{children.defaultValue.propertyView({ label: trans("prop.defaultValue") })}
113116
</Section>
114117

115118
{["logic", "both"].includes(useContext(EditorContext).editorModeStatus) && (

0 commit comments

Comments
 (0)