From 440268749b27a7ae69af9ac07dd04e6170be1cc9 Mon Sep 17 00:00:00 2001 From: Kevin Ho Date: Wed, 7 Aug 2024 15:09:19 -0700 Subject: [PATCH 1/8] added disableOnEdit for KeyValuePair widget --- public/schemas/schema-form.yaml | 4 ++++ .../Extensibility/components-form/KeyValuePairRenderer.js | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/public/schemas/schema-form.yaml b/public/schemas/schema-form.yaml index 32df824e17..0f9c814ad4 100644 --- a/public/schemas/schema-form.yaml +++ b/public/schemas/schema-form.yaml @@ -153,6 +153,10 @@ $widgets: const: KeyValuePair then: properties: + disableOnEdit: + type: boolean + description: a boolean which specifies if field is disabled on edit. + default: false keyEnum: type: array description: An array of options to generate a key input field with a dropdown diff --git a/src/components/Extensibility/components-form/KeyValuePairRenderer.js b/src/components/Extensibility/components-form/KeyValuePairRenderer.js index 702d41676b..69fa3ceb63 100644 --- a/src/components/Extensibility/components-form/KeyValuePairRenderer.js +++ b/src/components/Extensibility/components-form/KeyValuePairRenderer.js @@ -77,10 +77,15 @@ export function KeyValuePairRenderer({ required, resource, nestingLevel = 0, + editMode, + ...props }) { // TODO the value obtained by ui-schema is undefined for this component value = getObjectValueWorkaround(schema, resource, storeKeys, value); + const disableOnEdit = schema.get('disableOnEdit') || false; + const disabledKeys = disableOnEdit ? value.keySeq().toArray() : []; + const { tFromStoreKeys, t: tExt } = useGetTranslation(); const { t } = useTranslation(); @@ -123,6 +128,8 @@ export function KeyValuePairRenderer({ title={titleTranslation} initialValue={valueInfo.type === 'object' ? {} : ''} defaultOpen={schema.get('defaultExpanded') ?? false} + lockedKeys={disabledKeys} + lockedValues={disabledKeys} {...getPropsFromSchema(schema, required, tExt)} /> ); From aa4a78a821aa21387f115c799141e6b6ad914e68 Mon Sep 17 00:00:00 2001 From: Kevin Ho Date: Fri, 23 Aug 2024 08:30:29 -0700 Subject: [PATCH 2/8] updated schema-form.yaml for keyvalue pair --- public/schemas/schema-form.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/schemas/schema-form.yaml b/public/schemas/schema-form.yaml index 0f9c814ad4..76e5dec254 100644 --- a/public/schemas/schema-form.yaml +++ b/public/schemas/schema-form.yaml @@ -155,7 +155,7 @@ $widgets: properties: disableOnEdit: type: boolean - description: a boolean which specifies if field is disabled on edit. + description: a boolean which specifies if KeyValuePair is disabled on edit. default: false keyEnum: type: array From 8ae32b5e772b9286854b402c94c6f95d29c557ea Mon Sep 17 00:00:00 2001 From: Kevin Ho Date: Fri, 23 Aug 2024 09:52:37 -0700 Subject: [PATCH 3/8] fixed kvp always disabling --- .../Extensibility/components-form/KeyValuePairRenderer.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/Extensibility/components-form/KeyValuePairRenderer.js b/src/components/Extensibility/components-form/KeyValuePairRenderer.js index 69fa3ceb63..4ae8caff4b 100644 --- a/src/components/Extensibility/components-form/KeyValuePairRenderer.js +++ b/src/components/Extensibility/components-form/KeyValuePairRenderer.js @@ -84,7 +84,8 @@ export function KeyValuePairRenderer({ value = getObjectValueWorkaround(schema, resource, storeKeys, value); const disableOnEdit = schema.get('disableOnEdit') || false; - const disabledKeys = disableOnEdit ? value.keySeq().toArray() : []; + const disabledKeys = + disableOnEdit && editMode ? value.keySeq().toArray() : []; const { tFromStoreKeys, t: tExt } = useGetTranslation(); const { t } = useTranslation(); From e6d92e8d9bd517c41a7e83ec2d196959eaa1e929 Mon Sep 17 00:00:00 2001 From: Kevin Ho Date: Fri, 23 Aug 2024 15:06:47 -0700 Subject: [PATCH 4/8] added disabling of key value pairs entry on edit --- .../components-form/KeyValuePairRenderer.js | 2 ++ src/shared/ResourceForm/fields/KeyValueField.js | 11 +++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/components/Extensibility/components-form/KeyValuePairRenderer.js b/src/components/Extensibility/components-form/KeyValuePairRenderer.js index 4ae8caff4b..31d7224c00 100644 --- a/src/components/Extensibility/components-form/KeyValuePairRenderer.js +++ b/src/components/Extensibility/components-form/KeyValuePairRenderer.js @@ -131,6 +131,8 @@ export function KeyValuePairRenderer({ defaultOpen={schema.get('defaultExpanded') ?? false} lockedKeys={disabledKeys} lockedValues={disabledKeys} + disableOnEdit={disableOnEdit} + editMode={editMode} {...getPropsFromSchema(schema, required, tExt)} /> ); diff --git a/src/shared/ResourceForm/fields/KeyValueField.js b/src/shared/ResourceForm/fields/KeyValueField.js index 34b47410a3..db76e2402c 100644 --- a/src/shared/ResourceForm/fields/KeyValueField.js +++ b/src/shared/ResourceForm/fields/KeyValueField.js @@ -22,6 +22,8 @@ export function KeyValueField({ lockedKeys = [], lockedValues = [], required, + disableOnEdit, + editMode, ...props }) { const { t } = useTranslation(); @@ -85,7 +87,8 @@ export function KeyValueField({ {input.key({ fullWidth: true, className: 'full-width', - disabled: lockedKeys.includes(value?.key), + disabled: + lockedKeys.includes(value?.key) || (disableOnEdit && editMode), key: 'key', value: value?.key || '', ref: ref, @@ -110,7 +113,9 @@ export function KeyValueField({ onKeyDown: e => focus(e), value: dataValue(value), placeholder: t('components.key-value-field.enter-value'), - disabled: lockedValues.includes(value?.key), + disabled: + lockedValues.includes(value?.key) || + (disableOnEdit && editMode), setValue: val => { setValue({ ...value, @@ -156,6 +161,8 @@ export function KeyValueField({ ]} actions={actions} required={required} + disableOnEdit={disableOnEdit} + editMode={editMode} {...props} /> ); From e8da83175472b43a2ac8692ed4a903e2badd52ae Mon Sep 17 00:00:00 2001 From: Kevin Ho Date: Fri, 23 Aug 2024 15:07:08 -0700 Subject: [PATCH 5/8] added disabling of delete button on edit --- src/shared/ResourceForm/fields/MultiInput.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/shared/ResourceForm/fields/MultiInput.js b/src/shared/ResourceForm/fields/MultiInput.js index f57291e20a..ebbc11a630 100644 --- a/src/shared/ResourceForm/fields/MultiInput.js +++ b/src/shared/ResourceForm/fields/MultiInput.js @@ -29,6 +29,8 @@ export function MultiInput({ newItemAction, newItemActionWidth = 1, inputInfo, + disableOnEdit, + editMode, ...props }) { const { t } = useTranslation(); @@ -186,7 +188,7 @@ export function MultiInput({ {!isLast(index) && (