From 9b65408501131f01d481d68e62835fb53b15a725 Mon Sep 17 00:00:00 2001 From: Maurice Date: Sat, 29 Jan 2022 18:05:37 +0100 Subject: [PATCH 1/2] Changed custom Id logic to enable optional custom IDs --- src/form/EntityForm.tsx | 6 ++++-- src/models/entities.ts | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/form/EntityForm.tsx b/src/form/EntityForm.tsx index 1264f253a..3648a0032 100644 --- a/src/form/EntityForm.tsx +++ b/src/form/EntityForm.tsx @@ -188,7 +188,7 @@ export function EntityForm({ previousValues: initialValues }), [schemaOrResolver, path, entityId, internalValue]); - const mustSetCustomId: boolean = (status === "new" || status === "copy") && !!schema.customId; + const mustSetCustomId: boolean = (status === "new" || status === "copy") && (!!schema.customId && schema.customId !== "optional"); const underlyingChanges: Partial> = useMemo(() => { if (initialValues && status === "existing") { @@ -225,7 +225,9 @@ export function EntityForm({ savedEntityId = entity.id; } else if (status === "new" || status === "copy") { if (schema.customId) { - if (!customId) throw Error("Form misconfiguration when saving, customId should be set"); + if (schema.customId !== "optional" && !customId) { + throw Error("Form misconfiguration when saving, customId should be set"); + } savedEntityId = customId; } } else { diff --git a/src/models/entities.ts b/src/models/entities.ts index bd523bad4..5f4a69636 100644 --- a/src/models/entities.ts +++ b/src/models/entities.ts @@ -19,11 +19,12 @@ export interface EntitySchema { /** * If this property is not set, the property will be created by the * datasource. - * You can set the value to true to allow the users to choose the ID. + * You can set the value to 'optional' to force the users to choose the ID. + * You can set the value to 'allowed' to allow the users to choose the ID. If the ID is empty, an automatic ID will be set. * You can also pass a set of values (as an EnumValues object) to allow them * to pick from only those */ - customId?: boolean | EnumValues; + customId?: 'required' | 'optional' | EnumValues; /** * Set of properties that compose an entity From c92b98c800a0dc77b03f6e90e4f428e9b4a70927 Mon Sep 17 00:00:00 2001 From: Maurice Date: Mon, 31 Jan 2022 17:35:55 +0100 Subject: [PATCH 2/2] Prevented breaking change --- src/models/entities.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/models/entities.ts b/src/models/entities.ts index 5f4a69636..57e83357c 100644 --- a/src/models/entities.ts +++ b/src/models/entities.ts @@ -19,12 +19,12 @@ export interface EntitySchema { /** * If this property is not set, the property will be created by the * datasource. - * You can set the value to 'optional' to force the users to choose the ID. - * You can set the value to 'allowed' to allow the users to choose the ID. If the ID is empty, an automatic ID will be set. + * You can set the value to 'true' to force the users to choose the ID. + * You can set the value to 'optional' to allow the users to choose the ID. If the ID is empty, an automatic ID will be set. * You can also pass a set of values (as an EnumValues object) to allow them * to pick from only those */ - customId?: 'required' | 'optional' | EnumValues; + customId?: boolean | "optional" | EnumValues; /** * Set of properties that compose an entity