Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: disableOnEdit KeyValuePair #3316

Merged
merged 8 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/extensibility/60-form-widgets.md
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ These are the available `KeyValuePair` widget parameters:
| **inputInfo** | No | string | A string below the input field that shows how to fill in the input. You can use the {{ [`name`] (`link`) }} format to display a `name` instead of a `link. |
| **description** | No | string | A string displayed in a tooltip when you hover over a question mark icon, next to the input's label. The default value is taken from the CustomResourceDefintion (CRD). |
| **defaultExpanded** | No | boolean | Specifies if the widget should be expanded by default. Defaults to `false`. |
| **disableOnEdit** | No | boolean | Disables all key value pairs in edit mode, defaults to `false`. |
kevin-kho marked this conversation as resolved.
Show resolved Hide resolved

See the following example:

Expand Down
4 changes: 4 additions & 0 deletions public/schemas/schema-form.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ $widgets:
const: KeyValuePair
then:
properties:
disableOnEdit:
type: boolean
description: a boolean which specifies if KeyValuePair is disabled on edit.
kevin-kho marked this conversation as resolved.
Show resolved Hide resolved
default: false
keyEnum:
type: array
description: An array of options to generate a key input field with a dropdown
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,16 @@ 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 && editMode ? value.keySeq().toArray() : [];

const { tFromStoreKeys, t: tExt } = useGetTranslation();
const { t } = useTranslation();

Expand Down Expand Up @@ -123,6 +129,10 @@ export function KeyValuePairRenderer({
title={titleTranslation}
initialValue={valueInfo.type === 'object' ? {} : ''}
defaultOpen={schema.get('defaultExpanded') ?? false}
lockedKeys={disabledKeys}
lockedValues={disabledKeys}
disableOnEdit={disableOnEdit}
editMode={editMode}
{...getPropsFromSchema(schema, required, tExt)}
/>
);
Expand Down
11 changes: 9 additions & 2 deletions src/shared/ResourceForm/fields/KeyValueField.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export function KeyValueField({
lockedKeys = [],
lockedValues = [],
required,
disableOnEdit,
editMode,
...props
}) {
const { t } = useTranslation();
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -156,6 +161,8 @@ export function KeyValueField({
]}
actions={actions}
required={required}
disableOnEdit={disableOnEdit}
editMode={editMode}
{...props}
/>
);
Expand Down
4 changes: 3 additions & 1 deletion src/shared/ResourceForm/fields/MultiInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export function MultiInput({
newItemAction,
newItemActionWidth = 1,
inputInfo,
disableOnEdit,
editMode,
...props
}) {
const { t } = useTranslation();
Expand Down Expand Up @@ -186,7 +188,7 @@ export function MultiInput({
{!isLast(index) && (
<div className="bsl-col-md--1">
<Button
disabled={readOnly}
disabled={readOnly || (disableOnEdit && editMode)}
className={classnames({
hidden: isEntryLocked(entry),
})}
Expand Down
Loading