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

Avoid removing VMs from an archived/archiving plans. #1395

Merged
merged 1 commit into from
Dec 3, 2024

Conversation

sgratch
Copy link
Collaborator

@sgratch sgratch commented Nov 27, 2024

Reference: https://issues.redhat.com/browse/MTV-1713

Avoid removing VMs from an archived/archiving plans. If a plan's status is either archiving or archived, block the option to remove VMs for that plan.

Screenshots

Before

Screenshot from 2024-11-27 21-36-04

After

Screenshot from 2024-11-27 21-36-42

@sgratch sgratch requested a review from yaacov November 27, 2024 19:37
@codecov-commenter
Copy link

codecov-commenter commented Nov 27, 2024

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 36.21%. Comparing base (13484d0) to head (7c9a9f7).
Report is 136 commits behind head on main.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1395      +/-   ##
==========================================
- Coverage   36.81%   36.21%   -0.60%     
==========================================
  Files         158      159       +1     
  Lines        2548     2579      +31     
  Branches      599      614      +15     
==========================================
- Hits          938      934       -4     
- Misses       1428     1630     +202     
+ Partials      182       15     -167     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sgratch sgratch added the bug Categorizes issue or PR as related to a bug. label Nov 27, 2024
@sgratch sgratch added this to the 2.8.0 milestone Nov 27, 2024
@pcbailey
Copy link

lgtm

@@ -23,6 +24,15 @@ 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(
Copy link
Collaborator

@metalice metalice Nov 27, 2024

Choose a reason for hiding this comment

The 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

<AlertMessageForModals title={t('Error')} message={something} />,

instead of declaring it 3 times, only once..

Copy link
Collaborator

@metalice metalice Nov 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in current line 100 u can do after it
{msg && <AlertMessageForModals title={t('Error')} message={msg} />}

export const isPlanArchived = (plan: V1beta1Plan) => {
const planStatus = getPlanPhase({ obj: plan });

return planStatus === 'Archiving' || planStatus === 'Archived';
Copy link
Collaborator

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

Copy link
Collaborator Author

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.

Copy link
Collaborator

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

Copy link
Collaborator Author

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:

  1. it is not related to this fix and touches other components/pages so it's better to separate.
  2. It will generate unnecessary code conflicts since there is a merged code from me which is related to the plan status, e.g.
    export const isPlanArchived = (plan: V1beta1Plan) => {
    const planStatus = getPlanPhase({ obj: plan });
    return planStatus === 'Archiving' || planStatus === 'Archived';
    };

Let's merge the opened PRs relevant for plan status and I'll handle this issue separately.

Copy link
Collaborator Author

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

@sgratch sgratch force-pushed the avoid-removing-vms-for-archived-plan branch from a9e19b6 to d338c44 Compare December 2, 2024 15:50
@yaacov
Copy link
Member

yaacov commented Dec 2, 2024

Q: why do we show / enable the "remove virtual machine" button, in the case of archived/archiving plan ?

Reference: https://issues.redhat.com/browse/MTV-1713

Avoid removing VMs from an archived/archiving plans.
If a plan's status is either archiving or archived, block the option to
remove VMs for that plan.

Signed-off-by: Sharon Gratch <[email protected]>
@sgratch sgratch force-pushed the avoid-removing-vms-for-archived-plan branch from d338c44 to 7c9a9f7 Compare December 2, 2024 15:57
Copy link

sonarqubecloud bot commented Dec 2, 2024

@sgratch
Copy link
Collaborator Author

sgratch commented Dec 2, 2024

Q: why do we show / enable the "remove virtual machine" button, in the case of archived/archiving plan ?

In all use cases (1 vm left, archived), we enable the button on the vms list page and once clicking, show the confirmation/error popup modal
Screenshot from 2024-12-02 17-59-06

For an enhancement based on UX suggestion, I opened an issue: https://issues.redhat.com/browse/MTV-1727

@sgratch sgratch requested a review from metalice December 2, 2024 16:04
@metalice
Copy link
Collaborator

metalice commented Dec 3, 2024

/lgtm

@sgratch sgratch merged commit 645560a into kubev2v:main Dec 3, 2024
9 of 10 checks passed
sgratch added a commit to sgratch/forklift-console-plugin that referenced this pull request Dec 12, 2024
sgratch added a commit to sgratch/forklift-console-plugin that referenced this pull request Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Categorizes issue or PR as related to a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants