Skip to content

Commit

Permalink
Merge pull request #1395 from sgratch/avoid-removing-vms-for-archived…
Browse files Browse the repository at this point in the history
…-plan

Avoid removing VMs from an archived/archiving plans.
  • Loading branch information
sgratch authored Dec 3, 2024
2 parents 3a656a5 + 7c9a9f7 commit 645560a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
"Delete Provider": "Delete Provider",
"Delete StorageMap": "Delete StorageMap",
"Delete virtual machines from migration plan": "Delete virtual machines from migration plan",
"Deleting virtual machines from an archived migration plan is not allowed.": "Deleting virtual machines from an archived migration plan is not allowed.",
"Description": "Description",
"Details": "Details",
"Determines the frequency with which the system checks the status of snapshot creation or removal during oVirt warm migration. The default value is 10 seconds.": "Determines the frequency with which the system checks the status of snapshot creation or removal during oVirt warm migration. The default value is 10 seconds.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
StandardPageWithSelectionProps,
} from 'src/components/page/StandardPageWithSelection';
import { usePlanMigration } from 'src/modules/Plans/hooks/usePlanMigration';
import { isPlanExecuting } from 'src/modules/Plans/utils';
import { isPlanArchived, isPlanExecuting } from 'src/modules/Plans/utils';
import { useForkliftTranslation } from 'src/utils/i18n';

import { loadUserSettings, ResourceFieldFactory } from '@kubev2v/common';
Expand Down Expand Up @@ -244,10 +244,11 @@ export const MigrationVirtualMachinesList: FC<{ obj: PlanData }> = ({ obj }) =>
}));

const isExecuting = isPlanExecuting(plan);
const isArchived = isPlanArchived(plan);

// If plan executing allow to cancel vms, o/w remove from 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;
if (isExecuting) {
if (isExecuting && !isArchived) {
actions = [
({ selectedIds }) => (
<MigrationVMsCancelButton selectedIds={selectedIds || []} migration={lastMigration} />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { ReactNode, useCallback, useState } from 'react';
import { isPlanArchived } from 'src/modules/Plans/utils';
import { useToggle } from 'src/modules/Providers/hooks';
import { AlertMessageForModals, useModal } from 'src/modules/Providers/modals';
import { useForkliftTranslation } from 'src/utils/i18n';
Expand All @@ -23,17 +24,20 @@ export const PlanVMsDeleteModal: React.FC<PlanVMsDeleteModalProps> = ({ plan, se
const vms = (plan?.spec?.vms || []).filter((vm) => !selected.includes(vm.id)) || [];

React.useEffect(() => {
if (isPlanArchived(plan)) {
setAlertMessage(
t('Deleting virtual machines from an archived migration plan is not allowed.'),
);
return;
}
if (vms.length < 1) {
setAlertMessage(
<AlertMessageForModals
title={t('Error')}
message={t(
'All virtual machines planned for migration are selected for deletion, deleting all virtual machines from a migration plan is not allowed.',
)}
/>,
t(
'All virtual machines planned for migration are selected for deletion, deleting all virtual machines from a migration plan is not allowed.',
),
);
}
}, [vms]);
}, [vms, plan]);

const handleSave = useCallback(async () => {
toggleIsLoading();
Expand All @@ -51,10 +55,7 @@ export const PlanVMsDeleteModal: React.FC<PlanVMsDeleteModalProps> = ({ plan, se
toggleModal();
} catch (err) {
toggleIsLoading();

setAlertMessage(
<AlertMessageForModals title={t('Error')} message={err.message || err.toString()} />,
);
setAlertMessage(err.message || err.toString());
}
}, [selected]);

Expand All @@ -63,7 +64,7 @@ export const PlanVMsDeleteModal: React.FC<PlanVMsDeleteModalProps> = ({ plan, se
key="confirm"
onClick={handleSave}
variant="danger"
isDisabled={vms.length < 1}
isDisabled={vms.length < 1 || isPlanArchived(plan)}
isLoading={isLoading}
>
{t('Delete')}
Expand All @@ -86,8 +87,7 @@ export const PlanVMsDeleteModal: React.FC<PlanVMsDeleteModalProps> = ({ plan, se
<div className="forklift-edit-modal-body">
{t('Are you sure you want to delete this virtual machines from the migration plan?')}
</div>

{alertMessage}
{alertMessage && <AlertMessageForModals title={t('Error')} message={alertMessage} />}
</Modal>
);
};

0 comments on commit 645560a

Please sign in to comment.