From e0ec7cba0391002055d67d30d2ce54cd2ded5cd3 Mon Sep 17 00:00:00 2001 From: yaacov Date: Sun, 16 Jun 2024 11:26:23 +0300 Subject: [PATCH] Don't let user edit empty vddk image without empty flag Signed-off-by: yaacov --- .../EditProviderVDDKImage/EditProviderVDDKImage.tsx | 9 ++++++--- .../Providers/modals/EditProviderVDDKImage/index.ts | 2 +- .../{onVddkConfirm.tsx => onNoneEmptyVddkConfirm.tsx} | 6 +++++- 3 files changed, 12 insertions(+), 5 deletions(-) rename packages/forklift-console-plugin/src/modules/Providers/modals/EditProviderVDDKImage/{onVddkConfirm.tsx => onNoneEmptyVddkConfirm.tsx} (93%) diff --git a/packages/forklift-console-plugin/src/modules/Providers/modals/EditProviderVDDKImage/EditProviderVDDKImage.tsx b/packages/forklift-console-plugin/src/modules/Providers/modals/EditProviderVDDKImage/EditProviderVDDKImage.tsx index b1734cef6..78e3fca11 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/modals/EditProviderVDDKImage/EditProviderVDDKImage.tsx +++ b/packages/forklift-console-plugin/src/modules/Providers/modals/EditProviderVDDKImage/EditProviderVDDKImage.tsx @@ -10,7 +10,7 @@ import { validateVDDKImage } from '../../utils/validators'; import { EditModal, EditModalProps } from '../EditModal'; import { onEmptyVddkConfirm } from './onEmptyVddkConfirm'; -import { onVddkConfirm } from './onVddkConfirm'; +import { onNoneEmptyVddkConfirm } from './onNoneEmptyVddkConfirm'; export type EditProviderVDDKImageProps = Modify< EditModalProps, @@ -67,8 +67,8 @@ export const EditProviderVDDKImage: React.FC = (prop label={props?.label || t('VDDK init image')} model={ProviderModel} body={body} - validationHook={isEmptyImage ? validateEmptyVDDKImage : validateVDDKImage} - onConfirmHook={isEmptyImage ? onEmptyVddkConfirm : onVddkConfirm} + validationHook={isEmptyImage ? validateEmptyVDDKImage : validateNoneEmptyVDDKImage} + onConfirmHook={isEmptyImage ? onEmptyVddkConfirm : onNoneEmptyVddkConfirm} InputComponent={isEmptyImage ? EmptyVddkTextInput : VddkTextInput} /> ); @@ -89,3 +89,6 @@ const EmptyVddkTextInput: React.FC = () => ( // Validation of empty vddk image const validateEmptyVDDKImage = () => validateVDDKImage(undefined); + +// Validation of none empty vddk image, make sure it's not undefined +const validateNoneEmptyVDDKImage = (value) => validateVDDKImage(value || ''); diff --git a/packages/forklift-console-plugin/src/modules/Providers/modals/EditProviderVDDKImage/index.ts b/packages/forklift-console-plugin/src/modules/Providers/modals/EditProviderVDDKImage/index.ts index b6f0977bd..7a7e730f1 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/modals/EditProviderVDDKImage/index.ts +++ b/packages/forklift-console-plugin/src/modules/Providers/modals/EditProviderVDDKImage/index.ts @@ -1,5 +1,5 @@ // @index('./*.tsx', f => `export * from '${f.path}';`) export * from './EditProviderVDDKImage'; export * from './onEmptyVddkConfirm'; -export * from './onVddkConfirm'; +export * from './onNoneEmptyVddkConfirm'; // @endindex diff --git a/packages/forklift-console-plugin/src/modules/Providers/modals/EditProviderVDDKImage/onVddkConfirm.tsx b/packages/forklift-console-plugin/src/modules/Providers/modals/EditProviderVDDKImage/onNoneEmptyVddkConfirm.tsx similarity index 93% rename from packages/forklift-console-plugin/src/modules/Providers/modals/EditProviderVDDKImage/onVddkConfirm.tsx rename to packages/forklift-console-plugin/src/modules/Providers/modals/EditProviderVDDKImage/onNoneEmptyVddkConfirm.tsx index 5e62de1eb..a47ccee4a 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/modals/EditProviderVDDKImage/onVddkConfirm.tsx +++ b/packages/forklift-console-plugin/src/modules/Providers/modals/EditProviderVDDKImage/onNoneEmptyVddkConfirm.tsx @@ -13,7 +13,11 @@ import { OnConfirmHookType } from '../EditModal'; * @param {any} options.newValue - The new value for the 'vddkInitImage' spec settings. * @returns {Promise} - The modified resource. */ -export const onVddkConfirm: OnConfirmHookType = async ({ resource, model, newValue: value }) => { +export const onNoneEmptyVddkConfirm: OnConfirmHookType = async ({ + resource, + model, + newValue: value, +}) => { const provider = resource as V1beta1Provider; const vddkInitImage: string = value as string; let op: string;