Skip to content

Commit

Permalink
Allow editing plan settings only for specific plan's statuses
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
sgratch committed Nov 27, 2024
1 parent 84a9896 commit 40e7bb5
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -40,6 +41,7 @@ export const PreserveClusterCpuModelDetailsItem: React.FC<PlanDetailsItemProps>
crumbs={['spec', 'preserveClusterCpuModel']}
onEdit={
canPatch &&
isPlanEditable(resource) &&
(() =>
showModal(
<EditPlanPreserveClusterCpuModel
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -40,6 +41,7 @@ export const PreserveStaticIPsDetailsItem: React.FC<PlanDetailsItemProps> = ({
crumbs={['spec', 'preserveStaticIPs']}
onEdit={
canPatch &&
isPlanEditable(resource) &&
(() =>
showModal(
<EditPlanPreserveStaticIPs
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -30,7 +31,11 @@ export const RootDiskDetailsItem: React.FC<PlanDetailsItemProps> = ({
helpContent={helpContent ?? defaultHelpContent}
moreInfoLink={VIRT_V2V_HELP_LINK}
crumbs={['spec', 'vms', 'rootDisk']}
onEdit={canPatch && (() => showModal(<EditRootDisk resource={resource} />))}
onEdit={
canPatch &&
isPlanEditable(resource) &&
(() => showModal(<EditRootDisk resource={resource} />))
}
/>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -43,6 +44,7 @@ export const SetLUKSEncryptionPasswordsDetailsItem: React.FC<PlanDetailsItemProp
crumbs={['spec', 'vms', 'luks']}
onEdit={
canPatch &&
isPlanEditable(resource) &&
(() =>
showModal(
<EditLUKSEncryptionPasswords
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -28,6 +29,7 @@ export const TargetNamespaceDetailsItem: React.FC<PlanDetailsItemProps> = ({
crumbs={['spec', 'targetNamespace ']}
onEdit={
canPatch &&
isPlanEditable(resource) &&
(() =>
showModal(
<EditPlanTargetNamespace
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -37,6 +38,7 @@ export const TransferNetworkDetailsItem: React.FC<PlanDetailsItemProps> = ({
crumbs={['spec', 'transferNetwork ']}
onEdit={
canPatch &&
isPlanEditable(resource) &&
(() =>
showModal(
<EditPlanTransferNetwork
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -38,6 +39,7 @@ export const WarmDetailsItem: React.FC<PlanDetailsItemProps> = ({
crumbs={['spec', 'warm ']}
onEdit={
canPatch &&
isPlanEditable(resource) &&
(() =>
showModal(<EditPlanWarm resource={resource} destinationProvider={destinationProvider} />))
}
Expand Down

0 comments on commit 40e7bb5

Please sign in to comment.