From 40e7bb55e3554cf030bf7130a0e56fcb90ef2f61 Mon Sep 17 00:00:00 2001 From: Sharon Gratch Date: Wed, 27 Nov 2024 15:21:31 +0200 Subject: [PATCH] Allow editing plan settings only for specific plan's statuses Reference: https://issues.redhat.com/browse/MTV-1713 Enable editing of plan details -> settings fields only for the following plan statuses: Unknown', 'Canceled', 'Error', 'Failed', 'vmError', 'Warning', 'Ready and disable the edit option for all others. Signed-off-by: Sharon Gratch --- .../modules/Plans/utils/helpers/getPlanPhase.ts | 14 ++++++++++++++ .../PreserveClusterCpuModelDetailsItem.tsx | 2 ++ .../components/PreserveStaticIPsDetailsItem.tsx | 2 ++ .../components/RootDiskDetailsItem.tsx | 7 ++++++- .../SetLUKSEncryptionPasswordsDetailsItem.tsx | 2 ++ .../components/TargetNamespaceDetailsItem.tsx | 2 ++ .../components/TransferNetworkDetailsItem.tsx | 2 ++ .../SettingsSection/components/WarmDetailsItem.tsx | 2 ++ 8 files changed, 32 insertions(+), 1 deletion(-) diff --git a/packages/forklift-console-plugin/src/modules/Plans/utils/helpers/getPlanPhase.ts b/packages/forklift-console-plugin/src/modules/Plans/utils/helpers/getPlanPhase.ts index 1b70175bf..44dd18a5b 100644 --- a/packages/forklift-console-plugin/src/modules/Plans/utils/helpers/getPlanPhase.ts +++ b/packages/forklift-console-plugin/src/modules/Plans/utils/helpers/getPlanPhase.ts @@ -103,5 +103,19 @@ export const isPlanSucceeded = (plan: V1beta1Plan) => { return conditions?.includes('Succeeded'); }; +export const isPlanEditable = (plan: V1beta1Plan) => { + const planStatus = getPlanPhase({ obj: plan }); + + return ( + planStatus === 'Unknown' || + planStatus === 'Canceled' || + planStatus === 'Error' || + planStatus === 'Failed' || + planStatus === 'vmError' || + planStatus === 'Warning' || + planStatus === 'Ready' + ); +}; + const getConditions = (obj: V1beta1Plan) => obj?.status?.conditions?.filter((c) => c.status === 'True').map((c) => c.type); diff --git a/packages/forklift-console-plugin/src/modules/Plans/views/details/components/SettingsSection/components/PreserveClusterCpuModelDetailsItem.tsx b/packages/forklift-console-plugin/src/modules/Plans/views/details/components/SettingsSection/components/PreserveClusterCpuModelDetailsItem.tsx index 3772d869f..65b16f6fe 100644 --- a/packages/forklift-console-plugin/src/modules/Plans/views/details/components/SettingsSection/components/PreserveClusterCpuModelDetailsItem.tsx +++ b/packages/forklift-console-plugin/src/modules/Plans/views/details/components/SettingsSection/components/PreserveClusterCpuModelDetailsItem.tsx @@ -1,4 +1,5 @@ import React from 'react'; +import { isPlanEditable } from 'src/modules/Plans/utils'; import { useModal } from 'src/modules/Providers/modals'; import { DetailsItem } from 'src/modules/Providers/utils'; import { useForkliftTranslation } from 'src/utils/i18n'; @@ -40,6 +41,7 @@ export const PreserveClusterCpuModelDetailsItem: React.FC crumbs={['spec', 'preserveClusterCpuModel']} onEdit={ canPatch && + isPlanEditable(resource) && (() => showModal( = ({ crumbs={['spec', 'preserveStaticIPs']} onEdit={ canPatch && + isPlanEditable(resource) && (() => showModal( = ({ helpContent={helpContent ?? defaultHelpContent} moreInfoLink={VIRT_V2V_HELP_LINK} crumbs={['spec', 'vms', 'rootDisk']} - onEdit={canPatch && (() => showModal())} + onEdit={ + canPatch && + isPlanEditable(resource) && + (() => showModal()) + } /> ); }; diff --git a/packages/forklift-console-plugin/src/modules/Plans/views/details/components/SettingsSection/components/SetLUKSEncryptionPasswordsDetailsItem.tsx b/packages/forklift-console-plugin/src/modules/Plans/views/details/components/SettingsSection/components/SetLUKSEncryptionPasswordsDetailsItem.tsx index 4ad01e9f8..3658fab51 100644 --- a/packages/forklift-console-plugin/src/modules/Plans/views/details/components/SettingsSection/components/SetLUKSEncryptionPasswordsDetailsItem.tsx +++ b/packages/forklift-console-plugin/src/modules/Plans/views/details/components/SettingsSection/components/SetLUKSEncryptionPasswordsDetailsItem.tsx @@ -1,4 +1,5 @@ import React from 'react'; +import { isPlanEditable } from 'src/modules/Plans/utils'; import { useModal } from 'src/modules/Providers/modals'; import { DetailsItem } from 'src/modules/Providers/utils'; import { useForkliftTranslation } from 'src/utils/i18n'; @@ -43,6 +44,7 @@ export const SetLUKSEncryptionPasswordsDetailsItem: React.FC showModal( = ({ crumbs={['spec', 'targetNamespace ']} onEdit={ canPatch && + isPlanEditable(resource) && (() => showModal( = ({ crumbs={['spec', 'transferNetwork ']} onEdit={ canPatch && + isPlanEditable(resource) && (() => showModal( = ({ crumbs={['spec', 'warm ']} onEdit={ canPatch && + isPlanEditable(resource) && (() => showModal()) }