Skip to content

Commit

Permalink
show but disable button when plan is not editable
Browse files Browse the repository at this point in the history
  • Loading branch information
jschuler committed Dec 16, 2024
1 parent c94fceb commit 69a6afe
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@
"The current certificate does not match the certificate fetched from URL. Manually validate the fingerprint before proceeding.": "The current certificate does not match the certificate fetched from URL. Manually validate the fingerprint before proceeding.",
"The edit mappings button is disabled if the plan started running and at least one virtual machine was migrated successfully or when the plan status does not enable editing.": "The edit mappings button is disabled if the plan started running and at least one virtual machine was migrated successfully or when the plan status does not enable editing.",
"The edit virtual machines button is disabled if the plan started running and at least one virtual machine was migrated successfully.": "The edit virtual machines button is disabled if the plan started running and at least one virtual machine was migrated successfully.",
"The edit virtual machines button is disabled while the plan is not editable.": "The edit virtual machines button is disabled while the plan is not editable.",
"The interval in minutes for precopy. Default value is 60.": "The interval in minutes for precopy. Default value is 60.",
"The interval in seconds for snapshot pooling. Default value is 10.": "The interval in seconds for snapshot pooling. Default value is 10.",
"The limit for CPU usage by the controller, specified in milliCPU. Default value is 500m.": "The limit for CPU usage by the controller, specified in milliCPU. Default value is 500m.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@ import {
StandardPageWithSelectionProps,
} from 'src/components/page/StandardPageWithSelection';
import { usePlanMigration } from 'src/modules/Plans/hooks/usePlanMigration';
import {
isPlanArchived,
isPlanEditable,
isPlanExecuting,
isPlanSucceeded,
} from 'src/modules/Plans/utils';
import { isPlanArchived, isPlanExecuting } from 'src/modules/Plans/utils';
import { hasSomeCompleteRunningVMs } from 'src/modules/Plans/views/details/utils';
import { useForkliftTranslation } from 'src/utils/i18n';

Expand Down Expand Up @@ -252,9 +247,8 @@ export const MigrationVirtualMachinesList: FC<{ obj: PlanData }> = ({ obj }) =>
}));

const isExecuting = isPlanExecuting(plan);
const planSucceeded = isPlanSucceeded(plan);
const isArchived = isPlanArchived(plan);
const disableEdit = hasSomeCompleteRunningVMs(plan) || !isPlanEditable(plan);
const someVMsMigrated = hasSomeCompleteRunningVMs(plan);

// If plan executing and not archived (happens when archiving a running plan), allow to cancel vms, o/w remove from plan
let actions: PageGlobalActions;
Expand All @@ -264,8 +258,8 @@ export const MigrationVirtualMachinesList: FC<{ obj: PlanData }> = ({ obj }) =>
<MigrationVMsCancelButton selectedIds={selectedIds || []} migration={lastMigration} />
),
];
} else if (!planSucceeded) {
actions = disableEdit
} else {
actions = someVMsMigrated
? [({ selectedIds }) => <PlanVMsDeleteButton selectedIds={selectedIds || []} plan={plan} />]
: [() => <PlanVMsEditButton plan={plan} />];
}
Expand Down Expand Up @@ -298,7 +292,7 @@ export const MigrationVirtualMachinesList: FC<{ obj: PlanData }> = ({ obj }) =>
GlobalActionToolbarItems: actions,
};

return !planSucceeded && (isExecuting || disableEdit) ? (
return isExecuting || someVMsMigrated ? (
<PageWithSelection {...extendedProps} />
) : (
<PageWithExpansion {...extendedProps} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,23 @@ export const PlanVMsEditButton: FC<{
}> = ({ plan }) => {
const { t } = useForkliftTranslation();
const { showModal } = useModal();
const disableEdit = hasSomeCompleteRunningVMs(plan) || !isPlanEditable(plan);
const planEditable = isPlanEditable(plan);
const someVMsMigrated = hasSomeCompleteRunningVMs(plan);
const disableEdit = someVMsMigrated || !planEditable;

const onClick = () => {
showModal(<PlanVMsEditModal plan={plan} editAction="VMS" />);
};

return disableEdit ? (
<Tooltip
content={t(
'The edit virtual machines button is disabled if the plan started running and at least one virtual machine was migrated successfully.',
)}
content={
!planEditable
? t('The edit virtual machines button is disabled while the plan is not editable.')
: t(
'The edit virtual machines button is disabled if the plan started running and at least one virtual machine was migrated successfully.',
)
}
>
<Button variant="secondary" onClick={onClick} isAriaDisabled>
{t('Edit virtual machines')}
Expand Down

0 comments on commit 69a6afe

Please sign in to comment.