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

Disable Required Toggle When No Subtags Are Enabled #48381

Merged
merged 6 commits into from
Sep 4, 2024
4 changes: 3 additions & 1 deletion src/pages/workspace/tags/WorkspaceViewTagsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,9 @@ function WorkspaceViewTagsPage({route}: WorkspaceViewTagsProps) {
/>
);
};

if (!Object.values(currentPolicyTag?.tags ?? {}).some((tag) => tag.enabled)) {
Tag.setPolicyTagsRequired(policyID, false, route.params.orderWeight)
Copy link
Contributor

Choose a reason for hiding this comment

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

Caution

There's currently an issue with the implementation which would block this from being merged, basically there's an infinite loop of the setPolicyTagsRequired call (see video below) which needs to be fixed such that:

  1. The call would only be made once when all subtags are Disabled.
  2. The call would not be made again when the page is refreshed and the tags RHP (right hand panel) is re-opened (like it does in the video towards the end).
call-loop-issue.mov

cc @Shahidullah-Muffakir I will be able to pick-up the review and complete the checklist once the issue is fixed and the fix works as expected.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it. We can update the condition to:

    if (!!currentPolicyTag?.required && !Object.values(currentPolicyTag?.tags ?? {}).some((tag) => tag.enabled)) {
        Tag.setPolicyTagsRequired(policyID, false, route.params.orderWeight);
    };
    

This will ensure the call is only made when needed and only once. I’ve tested it, and it works as expected. Let me know what you think. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ikevin127 I pushed the changes, Please take a look when you can. Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for addressing the issues, I'll move forward with the review!

}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (!Object.values(currentPolicyTag?.tags ?? {}).some((tag) => tag.enabled)) {
Tag.setPolicyTagsRequired(policyID, false, route.params.orderWeight)
}
if (!Object.values(currentPolicyTag?.tags ?? {}).some((tag) => tag.enabled)) {
Tag.setPolicyTagsRequired(policyID, false, route.params.orderWeight);
}

⚠️ @Shahidullah-Muffakir Next time after you are done with the changes, please run npm run prettier in order to prettify the code, otherwise the prettier related checks for the PR will fail.

In this case the ; (semicolon) was missing at the end of the setPolicyTagsRequired function call.
Additionally, I added some spacing on top and bottom of the if for better readability.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it, I will add the semicolon and adjust the spacing in this PR. I'll also make sure to run npm run prettier in my upcoming PRs. Thank you.

const navigateToEditTag = () => {
Navigation.navigate(ROUTES.WORKSPACE_EDIT_TAGS.getRoute(route.params.policyID, currentPolicyTag?.orderWeight));
};
Expand Down
Loading