-
Notifications
You must be signed in to change notification settings - Fork 22
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
Avoid removing VMs from an archived/archiving plans. #1395
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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'; | ||
|
@@ -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( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why setting the whole comopnent as a state? make it much harder for React to compare, and not only the msg string? also, you will reduce the reputation in the code here of
instead of declaring it 3 times, only once.. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in current line 100 u can do after it |
||
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(); | ||
|
@@ -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]); | ||
|
||
|
@@ -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')} | ||
|
@@ -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> | ||
); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Archiving and Archived will probably be widely used, therefore it better to add them to a const file and prevent future typos
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree but current code is using the PlanPhase type based on strings and this type is used all over by comparing to strings.
Not complicated to refactor, but better do it in a follow up PR as well since touching other files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PlanPhase can be an enum and used in the compare planStatus === PlanPhase.Archiving etc... lets refactor it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@metalice
Sure!
But I really prefer not to do it as part of this PR, but rather solve it today in a follow up one, since:
forklift-console-plugin/packages/forklift-console-plugin/src/modules/Plans/utils/helpers/getPlanPhase.ts
Lines 120 to 124 in 3a656a5
Let's merge the opened PRs relevant for plan status and I'll handle this issue separately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A follow up PR: #1408