react-form-manage 1.0.8-beta.7 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +173 -4
- package/README.md +8 -4
- package/dist/components/Form/FormCleanUp.js +3 -3
- package/dist/components/Form/FormItem.d.ts +10 -4
- package/dist/components/Form/FormItem.js +52 -14
- package/dist/components/Form/FormList.d.ts +2 -2
- package/dist/components/Form/FormList.js +2 -2
- package/dist/constants/form.d.ts +1 -1
- package/dist/hooks/useFormItemControl.d.ts +8 -3
- package/dist/hooks/useFormItemControl.js +64 -28
- package/dist/hooks/useFormListControl.d.ts +2 -1
- package/dist/hooks/useFormListControl.js +85 -19
- package/dist/index.cjs.d.ts +1 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.esm.d.ts +1 -0
- package/dist/index.js +4 -2
- package/dist/providers/Form.d.ts +15 -2
- package/dist/providers/Form.js +226 -41
- package/dist/stores/formStore.d.ts +44 -4
- package/dist/stores/formStore.js +42 -7
- package/dist/test/CommonTest.d.ts +3 -0
- package/dist/test/CommonTest.js +49 -0
- package/dist/test/TestDialog.d.ts +3 -0
- package/dist/test/TestDialog.js +21 -0
- package/dist/test/TestListener.d.ts +3 -0
- package/dist/test/TestListener.js +17 -0
- package/dist/test/TestNotFormWrapper.d.ts +3 -0
- package/dist/test/TestNotFormWrapper.js +15 -0
- package/dist/test/TestSelect.d.ts +6 -0
- package/dist/test/TestSelect.js +24 -0
- package/dist/test/TestWatchNormalize.d.ts +3 -0
- package/dist/test/TestWatchNormalize.js +23 -0
- package/dist/test/TestWrapperFormItem.d.ts +3 -0
- package/dist/test/TestWrapperFormItem.js +13 -0
- package/dist/test/testSetValue/TestCase10_SetFieldValues_ComplexNested.d.ts +21 -0
- package/dist/test/testSetValue/TestCase10_SetFieldValues_ComplexNested.js +61 -0
- package/dist/test/testSetValue/TestCase1_PlainObjectToPrimitives.d.ts +16 -0
- package/dist/test/testSetValue/TestCase1_PlainObjectToPrimitives.js +18 -0
- package/dist/test/testSetValue/TestCase2_PlainObjectToFormList.d.ts +21 -0
- package/dist/test/testSetValue/TestCase2_PlainObjectToFormList.js +33 -0
- package/dist/test/testSetValue/TestCase3_ArrayNonListenerToPrimitives.d.ts +21 -0
- package/dist/test/testSetValue/TestCase3_ArrayNonListenerToPrimitives.js +26 -0
- package/dist/test/testSetValue/TestCase4_PlainObjectRemovedFields.d.ts +20 -0
- package/dist/test/testSetValue/TestCase4_PlainObjectRemovedFields.js +32 -0
- package/dist/test/testSetValue/TestCase5_FormListRemovedItems.d.ts +22 -0
- package/dist/test/testSetValue/TestCase5_FormListRemovedItems.js +29 -0
- package/dist/test/testSetValue/TestCase6_NestedFormListRemoved.d.ts +28 -0
- package/dist/test/testSetValue/TestCase6_NestedFormListRemoved.js +36 -0
- package/dist/test/testSetValue/TestCase7_SetFieldValues_MixedStructure.d.ts +17 -0
- package/dist/test/testSetValue/TestCase7_SetFieldValues_MixedStructure.js +33 -0
- package/dist/test/testSetValue/TestCase8_SetFieldValues_NestedObject.d.ts +27 -0
- package/dist/test/testSetValue/TestCase8_SetFieldValues_NestedObject.js +57 -0
- package/dist/test/testSetValue/TestCase9_SetFieldValues_MultipleArrays.d.ts +25 -0
- package/dist/test/testSetValue/TestCase9_SetFieldValues_MultipleArrays.js +46 -0
- package/dist/test/testSetValue/index.d.ts +2 -0
- package/dist/test/testSetValue/index.js +28 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/public.d.ts +1 -1
- package/dist/utils/obj.util.d.ts +29 -1
- package/dist/utils/obj.util.js +59 -5
- package/package.json +2 -1
- package/src/App.tsx +39 -156
- package/src/DEEP_TRIGGER_LOGIC.md +573 -0
- package/src/components/Form/FormCleanUp.tsx +4 -8
- package/src/components/Form/FormItem.tsx +174 -57
- package/src/components/Form/FormList.tsx +17 -4
- package/src/constants/form.ts +1 -1
- package/src/hooks/useFormItemControl.ts +78 -32
- package/src/hooks/useFormListControl.ts +133 -43
- package/src/index.ts +25 -13
- package/src/main.tsx +6 -1
- package/src/providers/Form.tsx +454 -26
- package/src/stores/formStore.ts +363 -283
- package/src/test/CommonTest.tsx +177 -0
- package/src/test/TestDialog.tsx +52 -0
- package/src/test/TestListener.tsx +21 -0
- package/src/test/TestNotFormWrapper.tsx +43 -0
- package/src/test/TestSelect.tsx +38 -0
- package/src/test/TestWatchNormalize.tsx +32 -0
- package/src/test/TestWrapperFormItem.tsx +34 -0
- package/src/test/testSetValue/TestCase10_SetFieldValues_ComplexNested.tsx +203 -0
- package/src/test/testSetValue/TestCase1_PlainObjectToPrimitives.tsx +72 -0
- package/src/test/testSetValue/TestCase2_PlainObjectToFormList.tsx +114 -0
- package/src/test/testSetValue/TestCase3_ArrayNonListenerToPrimitives.tsx +99 -0
- package/src/test/testSetValue/TestCase4_PlainObjectRemovedFields.tsx +112 -0
- package/src/test/testSetValue/TestCase5_FormListRemovedItems.tsx +119 -0
- package/src/test/testSetValue/TestCase6_NestedFormListRemoved.tsx +185 -0
- package/src/test/testSetValue/TestCase7_SetFieldValues_MixedStructure.tsx +110 -0
- package/src/test/testSetValue/TestCase8_SetFieldValues_NestedObject.tsx +162 -0
- package/src/test/testSetValue/TestCase9_SetFieldValues_MultipleArrays.tsx +169 -0
- package/src/test/testSetValue/index.tsx +100 -0
- package/src/types/index.ts +1 -1
- package/src/types/public.ts +1 -1
- package/src/utils/obj.util.ts +153 -13
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { Box } from "@mui/material";
|
|
2
|
+
import { Button, Input, Typography } from "antd";
|
|
3
|
+
import Form from "../../providers/Form";
|
|
4
|
+
|
|
5
|
+
type Props = {};
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Test Case 7: setFieldValues với Mixed Structure
|
|
9
|
+
*
|
|
10
|
+
* Cấu trúc:
|
|
11
|
+
* - name (string) - primitive
|
|
12
|
+
* - age (number) - primitive
|
|
13
|
+
* - tags (array) - sẽ trigger deepTrigger
|
|
14
|
+
*
|
|
15
|
+
* Test: setFieldValues({name: "John", age: 30, tags: ["tag1", "tag2"]})
|
|
16
|
+
* Kỳ vọng:
|
|
17
|
+
* - "name" listener.onChange("John")
|
|
18
|
+
* - "age" listener.onChange(30)
|
|
19
|
+
* - "tags" → handleDeepTriggerSet(["tag1", "tag2"])
|
|
20
|
+
*/
|
|
21
|
+
function TestCase7_SetFieldValues_MixedStructure({}: Props) {
|
|
22
|
+
const [form] = Form.useForm("testCase7");
|
|
23
|
+
|
|
24
|
+
const handleTestSetFieldValues = () => {
|
|
25
|
+
form?.setFieldValues({
|
|
26
|
+
name: "John Doe",
|
|
27
|
+
age: 30,
|
|
28
|
+
tags: ["javascript", "typescript", "react"],
|
|
29
|
+
});
|
|
30
|
+
console.log("✅ Called setFieldValues with mixed structure");
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const handleTestWithOptions = () => {
|
|
34
|
+
form?.setFieldValues(
|
|
35
|
+
{
|
|
36
|
+
name: "Jane Doe",
|
|
37
|
+
age: 25,
|
|
38
|
+
tags: ["vue", "angular"],
|
|
39
|
+
},
|
|
40
|
+
{ notTriggerDirty: true },
|
|
41
|
+
);
|
|
42
|
+
console.log("✅ Called setFieldValues with notTriggerDirty option");
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const handleClear = () => {
|
|
46
|
+
form?.setFieldValues({
|
|
47
|
+
name: "",
|
|
48
|
+
age: undefined,
|
|
49
|
+
tags: [],
|
|
50
|
+
});
|
|
51
|
+
console.log("✅ Cleared all fields");
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<Box sx={{ p: 2 }}>
|
|
56
|
+
<Typography.Title level={4}>
|
|
57
|
+
Test Case 7: setFieldValues - Mixed Structure
|
|
58
|
+
</Typography.Title>
|
|
59
|
+
<Typography.Paragraph>
|
|
60
|
+
Test setFieldValues với primitives + array (array sẽ dùng deepTrigger)
|
|
61
|
+
</Typography.Paragraph>
|
|
62
|
+
|
|
63
|
+
<Form formName="testCase7">
|
|
64
|
+
{/* Primitive fields */}
|
|
65
|
+
<Form.Item name="name" label="Name">
|
|
66
|
+
<Input placeholder="Enter name" />
|
|
67
|
+
</Form.Item>
|
|
68
|
+
|
|
69
|
+
<Form.Item name="age" label="Age">
|
|
70
|
+
<Input type="number" placeholder="Enter age" />
|
|
71
|
+
</Form.Item>
|
|
72
|
+
|
|
73
|
+
{/* Array field - will use deepTrigger */}
|
|
74
|
+
<Box sx={{ border: "1px solid #d9d9d9", p: 2, mb: 2, borderRadius: 1 }}>
|
|
75
|
+
<Typography.Text strong>Tags (Array - Deep Trigger)</Typography.Text>
|
|
76
|
+
<Form.Item name="tags.0">
|
|
77
|
+
<Input placeholder="Tag 1" />
|
|
78
|
+
</Form.Item>
|
|
79
|
+
<Form.Item name="tags.1">
|
|
80
|
+
<Input placeholder="Tag 2" />
|
|
81
|
+
</Form.Item>
|
|
82
|
+
<Form.Item name="tags.2">
|
|
83
|
+
<Input placeholder="Tag 3" />
|
|
84
|
+
</Form.Item>
|
|
85
|
+
</Box>
|
|
86
|
+
|
|
87
|
+
<Box sx={{ mt: 2, display: "flex", gap: 2 }}>
|
|
88
|
+
<Button type="primary" onClick={handleTestSetFieldValues}>
|
|
89
|
+
Test setFieldValues
|
|
90
|
+
</Button>
|
|
91
|
+
<Button onClick={handleTestWithOptions}>Test with Options</Button>
|
|
92
|
+
<Button danger onClick={handleClear}>
|
|
93
|
+
Clear All
|
|
94
|
+
</Button>
|
|
95
|
+
</Box>
|
|
96
|
+
|
|
97
|
+
<Box sx={{ mt: 2, p: 2, bgcolor: "#f0f0f0", borderRadius: 1 }}>
|
|
98
|
+
<Typography.Text strong>Expected Behavior:</Typography.Text>
|
|
99
|
+
<Typography.Paragraph>
|
|
100
|
+
- name, age: trigger onChange trực tiếp
|
|
101
|
+
<br />- tags: gọi handleDeepTriggerSet (đệ quy trigger tất cả tags
|
|
102
|
+
items)
|
|
103
|
+
</Typography.Paragraph>
|
|
104
|
+
</Box>
|
|
105
|
+
</Form>
|
|
106
|
+
</Box>
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export default TestCase7_SetFieldValues_MixedStructure;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { Box } from "@mui/material";
|
|
2
|
+
import { Button, Input, Typography } from "antd";
|
|
3
|
+
import Form from "../../providers/Form";
|
|
4
|
+
|
|
5
|
+
type Props = {};
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Test Case 8: setFieldValues với Nested Object + Array
|
|
9
|
+
*
|
|
10
|
+
* Cấu trúc:
|
|
11
|
+
* - user.name (string)
|
|
12
|
+
* - user.email (string)
|
|
13
|
+
* - user.preferences.theme (string)
|
|
14
|
+
* - user.preferences.language (string)
|
|
15
|
+
* - user.hobbies (array) - sẽ trigger deepTrigger
|
|
16
|
+
*
|
|
17
|
+
* Test: setFieldValues({
|
|
18
|
+
* user: {
|
|
19
|
+
* name: "John",
|
|
20
|
+
* email: "john@example.com",
|
|
21
|
+
* preferences: { theme: "dark", language: "en" },
|
|
22
|
+
* hobbies: ["reading", "coding"]
|
|
23
|
+
* }
|
|
24
|
+
* })
|
|
25
|
+
*
|
|
26
|
+
* Kỳ vọng:
|
|
27
|
+
* - getAllPathsStopAtArray sẽ dừng tại array "user.hobbies"
|
|
28
|
+
* - Tất cả primitive paths được trigger onChange
|
|
29
|
+
* - "user.hobbies" được gọi handleDeepTriggerSet
|
|
30
|
+
*/
|
|
31
|
+
function TestCase8_SetFieldValues_NestedObject({}: Props) {
|
|
32
|
+
const [form] = Form.useForm("testCase8");
|
|
33
|
+
|
|
34
|
+
const handleTestSetFieldValues = () => {
|
|
35
|
+
form?.setFieldValues({
|
|
36
|
+
user: {
|
|
37
|
+
name: "John Doe",
|
|
38
|
+
email: "john@example.com",
|
|
39
|
+
preferences: {
|
|
40
|
+
theme: "dark",
|
|
41
|
+
language: "en",
|
|
42
|
+
},
|
|
43
|
+
hobbies: ["reading", "coding", "gaming"],
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
console.log("✅ Called setFieldValues with nested structure");
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const handleTestPartialUpdate = () => {
|
|
50
|
+
form?.setFieldValues({
|
|
51
|
+
user: {
|
|
52
|
+
name: "Jane Doe",
|
|
53
|
+
email: "jane@example.com",
|
|
54
|
+
preferences: {
|
|
55
|
+
theme: "light",
|
|
56
|
+
language: "vi",
|
|
57
|
+
},
|
|
58
|
+
hobbies: ["painting"],
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
console.log("✅ Partial update with fewer hobbies");
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const handleClear = () => {
|
|
65
|
+
form?.setFieldValues({
|
|
66
|
+
user: {
|
|
67
|
+
name: "",
|
|
68
|
+
email: "",
|
|
69
|
+
preferences: {
|
|
70
|
+
theme: "",
|
|
71
|
+
language: "",
|
|
72
|
+
},
|
|
73
|
+
hobbies: [],
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
console.log("✅ Cleared all fields");
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
<Box sx={{ p: 2 }}>
|
|
81
|
+
<Typography.Title level={4}>
|
|
82
|
+
Test Case 8: setFieldValues - Nested Object + Array
|
|
83
|
+
</Typography.Title>
|
|
84
|
+
<Typography.Paragraph>
|
|
85
|
+
Test setFieldValues với deep nested object và array
|
|
86
|
+
</Typography.Paragraph>
|
|
87
|
+
|
|
88
|
+
<Form formName="testCase8">
|
|
89
|
+
{/* User basic info */}
|
|
90
|
+
<Box sx={{ border: "1px solid #1890ff", p: 2, mb: 2, borderRadius: 1 }}>
|
|
91
|
+
<Typography.Text strong>User Info</Typography.Text>
|
|
92
|
+
<Form.Item name="user.name" label="Name">
|
|
93
|
+
<Input placeholder="Enter name" />
|
|
94
|
+
</Form.Item>
|
|
95
|
+
<Form.Item name="user.email" label="Email">
|
|
96
|
+
<Input placeholder="Enter email" />
|
|
97
|
+
</Form.Item>
|
|
98
|
+
</Box>
|
|
99
|
+
|
|
100
|
+
{/* User preferences */}
|
|
101
|
+
<Box sx={{ border: "1px solid #52c41a", p: 2, mb: 2, borderRadius: 1 }}>
|
|
102
|
+
<Typography.Text strong>Preferences</Typography.Text>
|
|
103
|
+
<Form.Item name="user.preferences.theme" label="Theme">
|
|
104
|
+
<Input placeholder="Enter theme" />
|
|
105
|
+
</Form.Item>
|
|
106
|
+
<Form.Item name="user.preferences.language" label="Language">
|
|
107
|
+
<Input placeholder="Enter language" />
|
|
108
|
+
</Form.Item>
|
|
109
|
+
</Box>
|
|
110
|
+
|
|
111
|
+
{/* User hobbies (array - will use deepTrigger) */}
|
|
112
|
+
<Box sx={{ border: "1px solid #faad14", p: 2, mb: 2, borderRadius: 1 }}>
|
|
113
|
+
<Typography.Text strong>
|
|
114
|
+
Hobbies (Array - Deep Trigger)
|
|
115
|
+
</Typography.Text>
|
|
116
|
+
<Form.Item name="user.hobbies.0">
|
|
117
|
+
<Input placeholder="Hobby 1" />
|
|
118
|
+
</Form.Item>
|
|
119
|
+
<Form.Item name="user.hobbies.1">
|
|
120
|
+
<Input placeholder="Hobby 2" />
|
|
121
|
+
</Form.Item>
|
|
122
|
+
<Form.Item name="user.hobbies.2">
|
|
123
|
+
<Input placeholder="Hobby 3" />
|
|
124
|
+
</Form.Item>
|
|
125
|
+
</Box>
|
|
126
|
+
|
|
127
|
+
<Box sx={{ mt: 2, display: "flex", gap: 2, flexDirection: "column" }}>
|
|
128
|
+
<Button type="primary" onClick={handleTestSetFieldValues}>
|
|
129
|
+
1. Set Full Structure (3 hobbies)
|
|
130
|
+
</Button>
|
|
131
|
+
<Button onClick={handleTestPartialUpdate}>
|
|
132
|
+
2. Partial Update (1 hobby - cleanup test)
|
|
133
|
+
</Button>
|
|
134
|
+
<Button danger onClick={handleClear}>
|
|
135
|
+
3. Clear All
|
|
136
|
+
</Button>
|
|
137
|
+
</Box>
|
|
138
|
+
|
|
139
|
+
<Box
|
|
140
|
+
sx={{
|
|
141
|
+
mt: 2,
|
|
142
|
+
p: 2,
|
|
143
|
+
bgcolor: "#e6f7ff",
|
|
144
|
+
border: "1px solid #1890ff",
|
|
145
|
+
borderRadius: 1,
|
|
146
|
+
}}
|
|
147
|
+
>
|
|
148
|
+
<Typography.Text strong>Expected Behavior:</Typography.Text>
|
|
149
|
+
<Typography.Paragraph>
|
|
150
|
+
- Primitives (name, email, theme, language): trigger onChange
|
|
151
|
+
<br />
|
|
152
|
+
- user.hobbies: gọi handleDeepTriggerSet
|
|
153
|
+
<br />- Khi update với 1 hobby, hobbies.1 và hobbies.2 nhận
|
|
154
|
+
undefined
|
|
155
|
+
</Typography.Paragraph>
|
|
156
|
+
</Box>
|
|
157
|
+
</Form>
|
|
158
|
+
</Box>
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export default TestCase8_SetFieldValues_NestedObject;
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { Box } from "@mui/material";
|
|
2
|
+
import { Button, Input, Typography } from "antd";
|
|
3
|
+
import FormList from "../../components/Form/FormList";
|
|
4
|
+
import Form from "../../providers/Form";
|
|
5
|
+
|
|
6
|
+
type Props = {};
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Test Case 9: setFieldValues với Multiple Arrays
|
|
10
|
+
*
|
|
11
|
+
* Cấu trúc:
|
|
12
|
+
* - title (string)
|
|
13
|
+
* - tags (array) - deepTrigger
|
|
14
|
+
* - items (FormList array) - deepTrigger
|
|
15
|
+
* - categories (array) - deepTrigger
|
|
16
|
+
*
|
|
17
|
+
* Test: setFieldValues({
|
|
18
|
+
* title: "My Post",
|
|
19
|
+
* tags: ["js", "react"],
|
|
20
|
+
* items: [{name: "Item 1"}],
|
|
21
|
+
* categories: ["tech", "web"]
|
|
22
|
+
* })
|
|
23
|
+
*
|
|
24
|
+
* Kỳ vọng:
|
|
25
|
+
* - "title" trigger onChange
|
|
26
|
+
* - "tags" gọi handleDeepTriggerSet
|
|
27
|
+
* - "items" gọi handleDeepTriggerSet (FormList)
|
|
28
|
+
* - "categories" gọi handleDeepTriggerSet
|
|
29
|
+
*/
|
|
30
|
+
function TestCase9_SetFieldValues_MultipleArrays({}: Props) {
|
|
31
|
+
const [form] = Form.useForm("testCase9");
|
|
32
|
+
|
|
33
|
+
const handleTestSetFieldValues = () => {
|
|
34
|
+
form?.setFieldValues({
|
|
35
|
+
title: "My Blog Post",
|
|
36
|
+
tags: ["javascript", "react"],
|
|
37
|
+
items: [
|
|
38
|
+
{ name: "Item 1", value: 100 },
|
|
39
|
+
{ name: "Item 2", value: 200 },
|
|
40
|
+
],
|
|
41
|
+
categories: ["technology", "web development"],
|
|
42
|
+
});
|
|
43
|
+
console.log("✅ Called setFieldValues with multiple arrays");
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const handleTestReduceArrays = () => {
|
|
47
|
+
form?.setFieldValues({
|
|
48
|
+
title: "Updated Post",
|
|
49
|
+
tags: ["vue"],
|
|
50
|
+
items: [{ name: "Item 1", value: 150 }],
|
|
51
|
+
categories: ["tech"],
|
|
52
|
+
});
|
|
53
|
+
console.log("✅ Reduced arrays (cleanup test)");
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const handleClear = () => {
|
|
57
|
+
form?.setFieldValues({
|
|
58
|
+
title: "",
|
|
59
|
+
tags: [],
|
|
60
|
+
items: [],
|
|
61
|
+
categories: [],
|
|
62
|
+
});
|
|
63
|
+
console.log("✅ Cleared all fields");
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<Box sx={{ p: 2 }}>
|
|
68
|
+
<Typography.Title level={4}>
|
|
69
|
+
Test Case 9: setFieldValues - Multiple Arrays
|
|
70
|
+
</Typography.Title>
|
|
71
|
+
<Typography.Paragraph>
|
|
72
|
+
Test setFieldValues với nhiều arrays khác nhau (FormList và
|
|
73
|
+
non-FormList)
|
|
74
|
+
</Typography.Paragraph>
|
|
75
|
+
|
|
76
|
+
<Form formName="testCase9">
|
|
77
|
+
{/* Title - primitive */}
|
|
78
|
+
<Form.Item name="title" label="Title">
|
|
79
|
+
<Input placeholder="Enter title" />
|
|
80
|
+
</Form.Item>
|
|
81
|
+
|
|
82
|
+
{/* Tags - simple array */}
|
|
83
|
+
<Box sx={{ border: "1px solid #1890ff", p: 2, mb: 2, borderRadius: 1 }}>
|
|
84
|
+
<Typography.Text strong>Tags (Simple Array)</Typography.Text>
|
|
85
|
+
<Form.Item name="tags.0">
|
|
86
|
+
<Input placeholder="Tag 1" />
|
|
87
|
+
</Form.Item>
|
|
88
|
+
<Form.Item name="tags.1">
|
|
89
|
+
<Input placeholder="Tag 2" />
|
|
90
|
+
</Form.Item>
|
|
91
|
+
</Box>
|
|
92
|
+
|
|
93
|
+
{/* Items - FormList */}
|
|
94
|
+
<Box sx={{ border: "1px solid #52c41a", p: 2, mb: 2, borderRadius: 1 }}>
|
|
95
|
+
<Typography.Text strong>Items (FormList)</Typography.Text>
|
|
96
|
+
<FormList name="items">
|
|
97
|
+
{(fields, { add, remove }) => (
|
|
98
|
+
<Box>
|
|
99
|
+
{fields.map((field, index) => (
|
|
100
|
+
<Box key={field.key} sx={{ display: "flex", gap: 1, mb: 1 }}>
|
|
101
|
+
<Form.Item name={`items.${index}.name`}>
|
|
102
|
+
<Input placeholder="Name" />
|
|
103
|
+
</Form.Item>
|
|
104
|
+
<Form.Item name={`items.${index}.value`}>
|
|
105
|
+
<Input type="number" placeholder="Value" />
|
|
106
|
+
</Form.Item>
|
|
107
|
+
<Button
|
|
108
|
+
danger
|
|
109
|
+
size="small"
|
|
110
|
+
onClick={() => remove({ key: field.key })}
|
|
111
|
+
>
|
|
112
|
+
Remove
|
|
113
|
+
</Button>
|
|
114
|
+
</Box>
|
|
115
|
+
))}
|
|
116
|
+
<Button type="dashed" size="small" onClick={() => add()}>
|
|
117
|
+
Add Item
|
|
118
|
+
</Button>
|
|
119
|
+
</Box>
|
|
120
|
+
)}
|
|
121
|
+
</FormList>
|
|
122
|
+
</Box>
|
|
123
|
+
|
|
124
|
+
{/* Categories - simple array */}
|
|
125
|
+
<Box sx={{ border: "1px solid #faad14", p: 2, mb: 2, borderRadius: 1 }}>
|
|
126
|
+
<Typography.Text strong>Categories (Simple Array)</Typography.Text>
|
|
127
|
+
<Form.Item name="categories.0">
|
|
128
|
+
<Input placeholder="Category 1" />
|
|
129
|
+
</Form.Item>
|
|
130
|
+
<Form.Item name="categories.1">
|
|
131
|
+
<Input placeholder="Category 2" />
|
|
132
|
+
</Form.Item>
|
|
133
|
+
</Box>
|
|
134
|
+
|
|
135
|
+
<Box sx={{ mt: 2, display: "flex", gap: 2, flexDirection: "column" }}>
|
|
136
|
+
<Button type="primary" onClick={handleTestSetFieldValues}>
|
|
137
|
+
1. Set All Arrays (2 items each)
|
|
138
|
+
</Button>
|
|
139
|
+
<Button onClick={handleTestReduceArrays}>
|
|
140
|
+
2. Reduce Arrays (1 item each)
|
|
141
|
+
</Button>
|
|
142
|
+
<Button danger onClick={handleClear}>
|
|
143
|
+
3. Clear All
|
|
144
|
+
</Button>
|
|
145
|
+
</Box>
|
|
146
|
+
|
|
147
|
+
<Box
|
|
148
|
+
sx={{
|
|
149
|
+
mt: 2,
|
|
150
|
+
p: 2,
|
|
151
|
+
bgcolor: "#fffbe6",
|
|
152
|
+
border: "1px solid #faad14",
|
|
153
|
+
borderRadius: 1,
|
|
154
|
+
}}
|
|
155
|
+
>
|
|
156
|
+
<Typography.Text strong>Expected Behavior:</Typography.Text>
|
|
157
|
+
<Typography.Paragraph>
|
|
158
|
+
- title: trigger onChange
|
|
159
|
+
<br />
|
|
160
|
+
- tags, items, categories: tất cả gọi handleDeepTriggerSet
|
|
161
|
+
<br />- Khi reduce arrays: items bị xóa nhận undefined (cleanup)
|
|
162
|
+
</Typography.Paragraph>
|
|
163
|
+
</Box>
|
|
164
|
+
</Form>
|
|
165
|
+
</Box>
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export default TestCase9_SetFieldValues_MultipleArrays;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { Box, Tab, Tabs } from "@mui/material";
|
|
2
|
+
import React, { useState } from "react";
|
|
3
|
+
import TestCase10_SetFieldValues_ComplexNested from "./TestCase10_SetFieldValues_ComplexNested";
|
|
4
|
+
import TestCase1_PlainObjectToPrimitives from "./TestCase1_PlainObjectToPrimitives";
|
|
5
|
+
import TestCase2_PlainObjectToFormList from "./TestCase2_PlainObjectToFormList";
|
|
6
|
+
import TestCase3_ArrayNonListenerToPrimitives from "./TestCase3_ArrayNonListenerToPrimitives";
|
|
7
|
+
import TestCase4_PlainObjectRemovedFields from "./TestCase4_PlainObjectRemovedFields";
|
|
8
|
+
import TestCase5_FormListRemovedItems from "./TestCase5_FormListRemovedItems";
|
|
9
|
+
import TestCase6_NestedFormListRemoved from "./TestCase6_NestedFormListRemoved";
|
|
10
|
+
import TestCase7_SetFieldValues_MixedStructure from "./TestCase7_SetFieldValues_MixedStructure";
|
|
11
|
+
import TestCase8_SetFieldValues_NestedObject from "./TestCase8_SetFieldValues_NestedObject";
|
|
12
|
+
import TestCase9_SetFieldValues_MultipleArrays from "./TestCase9_SetFieldValues_MultipleArrays";
|
|
13
|
+
|
|
14
|
+
interface TabPanelProps {
|
|
15
|
+
children?: React.ReactNode;
|
|
16
|
+
index: number;
|
|
17
|
+
value: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function TabPanel(props: TabPanelProps) {
|
|
21
|
+
const { children, value, index, ...other } = props;
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<div
|
|
25
|
+
role="tabpanel"
|
|
26
|
+
hidden={value !== index}
|
|
27
|
+
id={`test-tabpanel-${index}`}
|
|
28
|
+
aria-labelledby={`test-tab-${index}`}
|
|
29
|
+
{...other}
|
|
30
|
+
>
|
|
31
|
+
{value === index && <Box sx={{ p: 3 }}>{children}</Box>}
|
|
32
|
+
</div>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function TestSetValueIndex() {
|
|
37
|
+
const [value, setValue] = useState(0);
|
|
38
|
+
|
|
39
|
+
const handleChange = (event: React.SyntheticEvent, newValue: number) => {
|
|
40
|
+
setValue(newValue);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<Box sx={{ width: "100%" }}>
|
|
45
|
+
<Box sx={{ borderBottom: 1, borderColor: "divider" }}>
|
|
46
|
+
<Tabs
|
|
47
|
+
value={value}
|
|
48
|
+
onChange={handleChange}
|
|
49
|
+
aria-label="test cases tabs"
|
|
50
|
+
variant="scrollable"
|
|
51
|
+
scrollButtons="auto"
|
|
52
|
+
>
|
|
53
|
+
<Tab label="Case 1: Plain Object" />
|
|
54
|
+
<Tab label="Case 2: FormList Nested" />
|
|
55
|
+
<Tab label="Case 3: Array Non-Listener" />
|
|
56
|
+
<Tab label="Case 4: Removed Fields" />
|
|
57
|
+
<Tab label="Case 5: FormList Removed" />
|
|
58
|
+
<Tab label="Case 6: Nested Removed" />
|
|
59
|
+
<Tab label="Case 7: setFieldValues Mixed" />
|
|
60
|
+
<Tab label="Case 8: setFieldValues Nested" />
|
|
61
|
+
<Tab label="Case 9: setFieldValues Arrays" />
|
|
62
|
+
<Tab label="Case 10: setFieldValues Complex" />
|
|
63
|
+
</Tabs>
|
|
64
|
+
</Box>
|
|
65
|
+
|
|
66
|
+
<TabPanel value={value} index={0}>
|
|
67
|
+
<TestCase1_PlainObjectToPrimitives />
|
|
68
|
+
</TabPanel>
|
|
69
|
+
<TabPanel value={value} index={1}>
|
|
70
|
+
<TestCase2_PlainObjectToFormList />
|
|
71
|
+
</TabPanel>
|
|
72
|
+
<TabPanel value={value} index={2}>
|
|
73
|
+
<TestCase3_ArrayNonListenerToPrimitives />
|
|
74
|
+
</TabPanel>
|
|
75
|
+
<TabPanel value={value} index={3}>
|
|
76
|
+
<TestCase4_PlainObjectRemovedFields />
|
|
77
|
+
</TabPanel>
|
|
78
|
+
<TabPanel value={value} index={4}>
|
|
79
|
+
<TestCase5_FormListRemovedItems />
|
|
80
|
+
</TabPanel>
|
|
81
|
+
<TabPanel value={value} index={5}>
|
|
82
|
+
<TestCase6_NestedFormListRemoved />
|
|
83
|
+
</TabPanel>
|
|
84
|
+
<TabPanel value={value} index={6}>
|
|
85
|
+
<TestCase7_SetFieldValues_MixedStructure />
|
|
86
|
+
</TabPanel>
|
|
87
|
+
<TabPanel value={value} index={7}>
|
|
88
|
+
<TestCase8_SetFieldValues_NestedObject />
|
|
89
|
+
</TabPanel>
|
|
90
|
+
<TabPanel value={value} index={8}>
|
|
91
|
+
<TestCase9_SetFieldValues_MultipleArrays />
|
|
92
|
+
</TabPanel>
|
|
93
|
+
<TabPanel value={value} index={9}>
|
|
94
|
+
<TestCase10_SetFieldValues_ComplexNested />
|
|
95
|
+
</TabPanel>
|
|
96
|
+
</Box>
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export default TestSetValueIndex;
|
package/src/types/index.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from "./public";
|