ding-react-admin 2.3.0 → 2.5.0
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/dist/index.js +284 -231
- package/dist/src/crud/HiddenSources.d.ts +9 -0
- package/dist/src/crud/HiddenSources.d.ts.map +1 -0
- package/dist/src/crud/InlineFormSet.d.ts.map +1 -1
- package/dist/src/crud/ResourceList.d.ts.map +1 -1
- package/dist/src/crud/columns/BooleanColumn.d.ts.map +1 -1
- package/dist/src/crud/columns/DateColumn.d.ts.map +1 -1
- package/dist/src/crud/columns/ImageColumn.d.ts.map +1 -1
- package/dist/src/crud/columns/NumberColumn.d.ts.map +1 -1
- package/dist/src/crud/columns/ReferenceColumn.d.ts.map +1 -1
- package/dist/src/crud/columns/ReferenceManyColumn.d.ts.map +1 -1
- package/dist/src/crud/columns/TextColumn.d.ts.map +1 -1
- package/dist/src/crud/fields/BooleanField.d.ts +3 -3
- package/dist/src/crud/fields/BooleanField.d.ts.map +1 -1
- package/dist/src/crud/fields/DateField.d.ts +3 -3
- package/dist/src/crud/fields/DateField.d.ts.map +1 -1
- package/dist/src/crud/fields/FieldWrapper.d.ts +3 -1
- package/dist/src/crud/fields/FieldWrapper.d.ts.map +1 -1
- package/dist/src/crud/fields/FileField.d.ts +3 -3
- package/dist/src/crud/fields/FileField.d.ts.map +1 -1
- package/dist/src/crud/fields/ImageField.d.ts +3 -3
- package/dist/src/crud/fields/ImageField.d.ts.map +1 -1
- package/dist/src/crud/fields/NumberField.d.ts +3 -3
- package/dist/src/crud/fields/NumberField.d.ts.map +1 -1
- package/dist/src/crud/fields/PasswordField.d.ts +3 -3
- package/dist/src/crud/fields/PasswordField.d.ts.map +1 -1
- package/dist/src/crud/fields/ReferenceField.d.ts +3 -3
- package/dist/src/crud/fields/ReferenceField.d.ts.map +1 -1
- package/dist/src/crud/fields/ReferenceManyField.d.ts +3 -3
- package/dist/src/crud/fields/ReferenceManyField.d.ts.map +1 -1
- package/dist/src/crud/fields/SelectField.d.ts +3 -3
- package/dist/src/crud/fields/SelectField.d.ts.map +1 -1
- package/dist/src/crud/fields/TextAreaField.d.ts +3 -3
- package/dist/src/crud/fields/TextAreaField.d.ts.map +1 -1
- package/dist/src/crud/fields/TextField.d.ts +3 -3
- package/dist/src/crud/fields/TextField.d.ts.map +1 -1
- package/dist/src/crud/fields/TimeField.d.ts +3 -3
- package/dist/src/crud/fields/TimeField.d.ts.map +1 -1
- package/dist/src/crud/index.d.ts +3 -1
- package/dist/src/crud/index.d.ts.map +1 -1
- package/dist/src/crud/types.d.ts +5 -0
- package/dist/src/crud/types.d.ts.map +1 -1
- package/dist/src/crud/utils/buildInlineRowsPayload.d.ts.map +1 -1
- package/dist/src/crud/utils/columnDataIndex.d.ts +5 -0
- package/dist/src/crud/utils/columnDataIndex.d.ts.map +1 -0
- package/dist/src/crud/utils/shouldRegisterSourceInPayload.d.ts +6 -0
- package/dist/src/crud/utils/shouldRegisterSourceInPayload.d.ts.map +1 -0
- package/dist/src/index.d.ts +2 -2
- package/dist/src/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/crud/HiddenSources.tsx +37 -0
- package/src/crud/InlineFormSet.tsx +4 -1
- package/src/crud/ResourceList.tsx +10 -1
- package/src/crud/columns/BooleanColumn.tsx +2 -1
- package/src/crud/columns/DateColumn.tsx +2 -1
- package/src/crud/columns/ImageColumn.tsx +2 -1
- package/src/crud/columns/NumberColumn.tsx +2 -1
- package/src/crud/columns/ReferenceColumn.tsx +2 -1
- package/src/crud/columns/ReferenceManyColumn.tsx +2 -1
- package/src/crud/columns/TextColumn.tsx +3 -2
- package/src/crud/fields/BooleanField.tsx +4 -2
- package/src/crud/fields/DateField.tsx +4 -2
- package/src/crud/fields/FieldWrapper.tsx +20 -7
- package/src/crud/fields/FileField.tsx +4 -2
- package/src/crud/fields/ImageField.tsx +4 -2
- package/src/crud/fields/NumberField.tsx +4 -2
- package/src/crud/fields/PasswordField.tsx +8 -2
- package/src/crud/fields/ReferenceField.tsx +4 -2
- package/src/crud/fields/ReferenceManyField.tsx +4 -2
- package/src/crud/fields/SelectField.tsx +4 -2
- package/src/crud/fields/TextAreaField.tsx +4 -2
- package/src/crud/fields/TextField.tsx +4 -2
- package/src/crud/fields/TimeField.tsx +4 -2
- package/src/crud/index.ts +3 -0
- package/src/crud/types.ts +6 -0
- package/src/crud/utils/buildInlineRowsPayload.ts +5 -2
- package/src/crud/utils/columnDataIndex.ts +6 -0
- package/src/crud/utils/shouldRegisterSourceInPayload.ts +10 -0
- package/src/data/dataUtils.test.ts +52 -1
- package/src/index.ts +3 -0
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { getFormValue } from "./getFormValue";
|
|
2
|
+
import { setFormValue } from "./setFormValue";
|
|
3
|
+
|
|
1
4
|
export type BuildInlineRowsPayloadOptions = {
|
|
2
5
|
transformRows?: (rows: Record<string, unknown>[]) => unknown;
|
|
3
6
|
};
|
|
@@ -16,9 +19,9 @@ export function buildInlineRowsPayload(
|
|
|
16
19
|
const out: Record<string, unknown> = {};
|
|
17
20
|
|
|
18
21
|
for (const source of sources) {
|
|
19
|
-
const value = record
|
|
22
|
+
const value = getFormValue(record, source);
|
|
20
23
|
if (value !== undefined) {
|
|
21
|
-
out
|
|
24
|
+
setFormValue(out, source, value);
|
|
22
25
|
}
|
|
23
26
|
}
|
|
24
27
|
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parent form fields register even when `source` is nested (`address.city`).
|
|
3
|
+
* Inline cells pass a different `name` (`lines.0.label`) and must not.
|
|
4
|
+
*/
|
|
5
|
+
export function shouldRegisterSourceInPayload(
|
|
6
|
+
source: string,
|
|
7
|
+
name?: string,
|
|
8
|
+
): boolean {
|
|
9
|
+
return name == null || name === source;
|
|
10
|
+
}
|
|
@@ -2,6 +2,9 @@ import { describe, expect, it, vi } from "vitest";
|
|
|
2
2
|
import { buildFormPayload } from "../crud/utils/buildFormPayload";
|
|
3
3
|
import { buildInlineRowsPayload } from "../crud/utils/buildInlineRowsPayload";
|
|
4
4
|
import { nestedFieldPath } from "../crud/utils/nestedFieldPath";
|
|
5
|
+
import { columnDataIndex } from "../crud/utils/columnDataIndex";
|
|
6
|
+
import { shouldRegisterSourceInPayload } from "../crud/utils/shouldRegisterSourceInPayload";
|
|
7
|
+
import { isSourceHidden } from "../crud/HiddenSources";
|
|
5
8
|
import { hasUploadValues } from "../crud/utils/hasUploadValues";
|
|
6
9
|
import { prepareFormSubmitBody } from "../crud/utils/prepareFormSubmitBody";
|
|
7
10
|
import { toFormData } from "../crud/utils/toFormData";
|
|
@@ -17,7 +20,7 @@ describe("buildFormPayload", () => {
|
|
|
17
20
|
const values = {
|
|
18
21
|
username: "jane",
|
|
19
22
|
email: "jane@example.com",
|
|
20
|
-
|
|
23
|
+
tags: [{ id: 1 }],
|
|
21
24
|
};
|
|
22
25
|
expect(buildFormPayload(values, ["username", "email"])).toEqual({
|
|
23
26
|
username: "jane",
|
|
@@ -37,6 +40,16 @@ describe("buildFormPayload", () => {
|
|
|
37
40
|
});
|
|
38
41
|
});
|
|
39
42
|
|
|
43
|
+
it("picks JSON nested sources", () => {
|
|
44
|
+
const values = {
|
|
45
|
+
address: { city: "Lahore", notes: "x" },
|
|
46
|
+
extra: "ignored",
|
|
47
|
+
};
|
|
48
|
+
expect(buildFormPayload(values, ["address.city"])).toEqual({
|
|
49
|
+
address: { city: "Lahore" },
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
40
53
|
it("returns all values when no field paths registered", () => {
|
|
41
54
|
const values = { a: 1, b: 2 };
|
|
42
55
|
expect(buildFormPayload(values, [])).toEqual(values);
|
|
@@ -62,6 +75,15 @@ describe("buildInlineRowsPayload", () => {
|
|
|
62
75
|
});
|
|
63
76
|
expect(result).toEqual([{ label: "A", kind: "line" }]);
|
|
64
77
|
});
|
|
78
|
+
|
|
79
|
+
it("picks nested sources on each row", () => {
|
|
80
|
+
const rows = [
|
|
81
|
+
{ rowKey: "a", id: 10, address: { city: "Lahore" }, extra: "x" },
|
|
82
|
+
];
|
|
83
|
+
expect(buildInlineRowsPayload(rows, ["address.city"])).toEqual([
|
|
84
|
+
{ address: { city: "Lahore" }, id: 10 },
|
|
85
|
+
]);
|
|
86
|
+
});
|
|
65
87
|
});
|
|
66
88
|
|
|
67
89
|
describe("nestedFieldPath", () => {
|
|
@@ -235,3 +257,32 @@ describe("createRestResourceHandlers", () => {
|
|
|
235
257
|
expect(create).toHaveBeenCalledWith(fd);
|
|
236
258
|
});
|
|
237
259
|
});
|
|
260
|
+
|
|
261
|
+
describe("shouldRegisterSourceInPayload", () => {
|
|
262
|
+
it("registers parent fields including nested sources", () => {
|
|
263
|
+
expect(shouldRegisterSourceInPayload("email")).toBe(true);
|
|
264
|
+
expect(shouldRegisterSourceInPayload("address.city")).toBe(true);
|
|
265
|
+
expect(shouldRegisterSourceInPayload("address.city", "address.city")).toBe(true);
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
it("does not register inline cells", () => {
|
|
269
|
+
expect(shouldRegisterSourceInPayload("label", "lines.0.label")).toBe(false);
|
|
270
|
+
});
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
describe("columnDataIndex", () => {
|
|
274
|
+
it("splits dotted sources for Ant Design", () => {
|
|
275
|
+
expect(columnDataIndex("name")).toBe("name");
|
|
276
|
+
expect(columnDataIndex("address.city")).toEqual(["address", "city"]);
|
|
277
|
+
});
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
describe("isSourceHidden", () => {
|
|
281
|
+
it("hides from the prop or the source set", () => {
|
|
282
|
+
const hide = new Set(["phone"]);
|
|
283
|
+
expect(isSourceHidden("phone", undefined, hide)).toBe(true);
|
|
284
|
+
expect(isSourceHidden("email", undefined, hide)).toBe(false);
|
|
285
|
+
expect(isSourceHidden("email", true, hide)).toBe(true);
|
|
286
|
+
expect(isSourceHidden("email", false, new Set())).toBe(false);
|
|
287
|
+
});
|
|
288
|
+
});
|
package/src/index.ts
CHANGED
|
@@ -135,6 +135,7 @@ export {
|
|
|
135
135
|
FilterBar,
|
|
136
136
|
ResourceForm,
|
|
137
137
|
ResourceFormModal,
|
|
138
|
+
HiddenSources,
|
|
138
139
|
InlineFormSet,
|
|
139
140
|
InlineFormSetStacked,
|
|
140
141
|
FormTabs,
|
|
@@ -178,6 +179,7 @@ export {
|
|
|
178
179
|
setFormValue,
|
|
179
180
|
buildFormPayload,
|
|
180
181
|
buildInlineRowsPayload,
|
|
182
|
+
columnDataIndex,
|
|
181
183
|
buildResourceFormSubmitBody,
|
|
182
184
|
prepareFormSubmitBody,
|
|
183
185
|
toFormData,
|
|
@@ -200,6 +202,7 @@ export type {
|
|
|
200
202
|
ResourceListProps,
|
|
201
203
|
TextFilterProps,
|
|
202
204
|
BaseSourceProps,
|
|
205
|
+
FieldSourceProps,
|
|
203
206
|
ChoiceOption,
|
|
204
207
|
ChoicesLoader,
|
|
205
208
|
UseChoicesOptions,
|