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

Allow editing plan settings only for specific plan's statuses #1393

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
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
Loading