@abysstract/admin-core 0.1.0 → 0.3.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.
|
@@ -21,15 +21,19 @@ function inputValue(field, value) {
|
|
|
21
21
|
return Boolean(value);
|
|
22
22
|
return value === undefined || value === null ? "" : String(value);
|
|
23
23
|
}
|
|
24
|
+
/** Value of a cleared input: nullable fields return to "not set". */
|
|
25
|
+
function emptyValue(field) {
|
|
26
|
+
return field.optional === true ? undefined : "";
|
|
27
|
+
}
|
|
24
28
|
function parseInput(field, value, fallback) {
|
|
25
29
|
switch (field.tsType) {
|
|
26
30
|
case "boolean":
|
|
27
31
|
return value;
|
|
28
32
|
case "number":
|
|
29
|
-
return value === "" ?
|
|
33
|
+
return value === "" ? emptyValue(field) : Number(value);
|
|
30
34
|
case "bigint":
|
|
31
35
|
if (value === "")
|
|
32
|
-
return
|
|
36
|
+
return emptyValue(field);
|
|
33
37
|
try {
|
|
34
38
|
return BigInt(value);
|
|
35
39
|
}
|
|
@@ -206,7 +210,9 @@ function ProductionResourceForm({ props }) {
|
|
|
206
210
|
const defaults = {};
|
|
207
211
|
if (mode === "create") {
|
|
208
212
|
for (const field of schema.fields) {
|
|
209
|
-
|
|
213
|
+
// Nullable fields start empty: a zero value would be stored, and for an
|
|
214
|
+
// optional foreign key it references a row that does not exist.
|
|
215
|
+
if (!editable(field, mode) || field.relation !== undefined || field.optional === true)
|
|
210
216
|
continue;
|
|
211
217
|
switch (field.tsType) {
|
|
212
218
|
case "string":
|
|
@@ -394,7 +400,8 @@ function ProductionResourceForm({ props }) {
|
|
|
394
400
|
const context = fieldContext(schema, field, mode, initialValues);
|
|
395
401
|
const visible = override?.visible;
|
|
396
402
|
if (visible === false ||
|
|
397
|
-
(typeof visible === "function" &&
|
|
403
|
+
(typeof visible === "function" &&
|
|
404
|
+
!visible(fieldContext(schema, field, mode, visibilityValues))))
|
|
398
405
|
return null;
|
|
399
406
|
const disabled = override?.disabled === true ||
|
|
400
407
|
(typeof override?.disabled === "function" && override.disabled(context));
|
|
@@ -429,7 +436,7 @@ function ProductionResourceForm({ props }) {
|
|
|
429
436
|
control = (_jsx(Select, { ...common, value: value, options: selectOptions, onChange: (nextValue) => change(field, nextValue) }));
|
|
430
437
|
}
|
|
431
438
|
else if (field.tsType === "number" || override?.valueType === "number") {
|
|
432
|
-
control = (_jsx(InputNumber, { ...common, min: fieldProps?.min, max: fieldProps?.max, step: fieldProps?.step, value: value, onChange: (nextValue) => change(field, nextValue ??
|
|
439
|
+
control = (_jsx(InputNumber, { ...common, min: fieldProps?.min, max: fieldProps?.max, step: fieldProps?.step, value: value, onChange: (nextValue) => change(field, nextValue ?? emptyValue(field)) }));
|
|
433
440
|
}
|
|
434
441
|
else if (field.tsType === "boolean" || override?.valueType === "boolean") {
|
|
435
442
|
control = (_jsx(Switch, { ...common, checked: Boolean(value), onChange: (nextValue) => change(field, nextValue) }));
|
|
@@ -26,6 +26,11 @@ export interface FieldSchema {
|
|
|
26
26
|
creatable: boolean;
|
|
27
27
|
updatable: boolean;
|
|
28
28
|
serverManaged: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Nullable field whose create request member is a Proto `optional`. The
|
|
31
|
+
* standard create form leaves it empty and omits it from the request.
|
|
32
|
+
*/
|
|
33
|
+
optional?: boolean;
|
|
29
34
|
relation?: FieldRelation;
|
|
30
35
|
}
|
|
31
36
|
/** Generated procedure permissions, including validated legacy exceptions. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abysstract/admin-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "React admin runtime, resource CRUD components and system pages for abysstract-admin.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@abysstract/admin-proto": "0.
|
|
56
|
+
"@abysstract/admin-proto": "0.3.0"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
59
|
"@ant-design/icons": "^5.4.0",
|