Fixes #39047 - replace useForemanModal in BulkActions#11626
Fixes #39047 - replace useForemanModal in BulkActions#11626jeremylenz merged 1 commit intoKatello:masterfrom
Conversation
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The modal IDs (e.g. 'bulk-packages-wizard', 'bulk-errata-wizard', etc.) are now duplicated across ActionsBar and the various bulk modal scenes; consider extracting them into shared constants to avoid typo bugs and make future refactors safer.
- In
BulkAssignCVEnvsModalScenethe indentation aroundallowMultipleContentViewsand theif (!orgId) return null;block is inconsistent with the surrounding code, which makes the control flow harder to read; aligning these lines would improve clarity. - The global
modalStateandlistenersobjects inbulkModalState.jsintroduce hidden shared state; if these components are ever mounted/unmounted dynamically or used in tests, consider encapsulating this in a React context or a more explicit state container to avoid subtle cross-component coupling.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The modal IDs (e.g. 'bulk-packages-wizard', 'bulk-errata-wizard', etc.) are now duplicated across ActionsBar and the various bulk modal scenes; consider extracting them into shared constants to avoid typo bugs and make future refactors safer.
- In `BulkAssignCVEnvsModalScene` the indentation around `allowMultipleContentViews` and the `if (!orgId) return null;` block is inconsistent with the surrounding code, which makes the control flow harder to read; aligning these lines would improve clarity.
- The global `modalState` and `listeners` objects in `bulkModalState.js` introduce hidden shared state; if these components are ever mounted/unmounted dynamically or used in tests, consider encapsulating this in a React context or a more explicit state container to avoid subtle cross-component coupling.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
44474c9 to
5da1e04
Compare
MariaAga
left a comment
There was a problem hiding this comment.
Thanks! except the extra empty line in global_index.js it looks good to me.
Tested with packit that all the modal open/close and show up as expected
5da1e04 to
0aea5a0
Compare
jeremylenz
left a comment
There was a problem hiding this comment.
Comments below, and one general question: Why is useBulkModalOpen in Katello? If there are any other plugins that need to keep track of modal state like this, useBulkModalOpen should really be in Foreman.
| @@ -0,0 +1,23 @@ | |||
| import { useEffect, useState } from 'react'; | |||
|
|
|||
| const modalState = {}; | |||
There was a problem hiding this comment.
This is kind of a crazy solution but after thinking about it I think it's right. Refs are component-scoped so don't fit here. Context is too tied to the React tree so also doesn't fit. I guess vanilla JS to the rescue :D
There was a problem hiding this comment.
Unfortunately, Katello is the only one that uses the useForemanModal function to manage modal states. Because the components are mounted using globalFill, there are not many options. The easiest way would be to mount it in the ActionBar component. However, it gets dismounted when the user clicks on the menu and closes it. Therefore, it should either stay open or the plugin mount should be refactored. Neither option is ideal because it requires changes to the core. The same problem occurs with the context; it also gets dismounted. To avoid using Redux, this may be the only way to deal with it.
There was a problem hiding this comment.
Another option would be to refactor the Katello modals so they (or their parent components) manage their own open states.
There was a problem hiding this comment.
I tried to find some way to do it like that. But I always ended up with this solution. I always end up on the same issue with mounts and opening from ActionBar menu.
There was a problem hiding this comment.
One more thing to note - in testing another bug with @nofaralfasi we noticed that moving away from useForemanModal moves your modal's API request earlier:
useForemanModal: API request is only made when modal is opened, even without a conditional check
Now: API request is made immediately on page load, unless you add a conditional in your modal
This may or may not have user impact.
This behavior could be caused by the filter function instead of delete. Now I partially changed the behavior using delete, and I couldn't recreate the API issue. |
0aea5a0 to
050215b
Compare
050215b to
04bf199
Compare
|
Fix lint errors + rename function to openBulkModal |
|
Thank you for all the reviews, is there anything to be edited? |
jeremylenz
left a comment
There was a problem hiding this comment.
Thanks @Lukshio
Works fine in my testing. I suppose this is the best alternative for now. ACK 👍
Nice addition! May I also ask why this is not directly in Foreman? I'd love to have this for another PR and I'd hate to duplicate the code: theforeman/foreman_puppet#429 |
|
If the best solution is to use the existing code, I'd say let's remove it from Katello and put it in Foreman. |
I can test it. I have basically copied the Katello logic to the foreman_puppet PR, so I assume it will work there as well. |
|
@jeremylenz @Lukshio I tested the 'useBulkModalOpen' in my foreman_puppet PR and it works very well. I copied the code manually to Foreman and imported it from there. +1 for moving this to Foreman directly! Would be very much appreciated. |
|
If someone would open a PR adding it to Foreman and another removing from Katello, I would approve them :) |
|
I have created theforeman/foreman#10893 in Foreman. It probably also makes sense to directly apply the fix there rather than just copying over the code... Edit: Just found that one :) theforeman/foreman#10834 |
|
Hi, @nadjaheitmann @jeremylenz Thank you for bringing it up. I will review the PR for the core and then, as part of this process, create a new issue and PR to change the import in Katello. |
The fix was originally implemented in Katello but can also be used for other plugins, so it makes more sense to have it in Foreman core: Katello/katello#11626
The fix was originally implemented in Katello but can also be used for other plugins, so it makes more sense to have it in Foreman core: Katello/katello#11626
Replacement of useForemanModal hook before its deprecation
Summary by Sourcery
Replace deprecated Foreman modal usage in host bulk actions with a shared custom bulk modal state mechanism.
Enhancements: