Skip to content

Fixes #39047 - replace useForemanModal in BulkActions#11626

Merged
jeremylenz merged 1 commit intoKatello:masterfrom
Lukshio:remove_useForemanModal_Bulk
Feb 6, 2026
Merged

Fixes #39047 - replace useForemanModal in BulkActions#11626
jeremylenz merged 1 commit intoKatello:masterfrom
Lukshio:remove_useForemanModal_Bulk

Conversation

@Lukshio
Copy link
Copy Markdown
Contributor

@Lukshio Lukshio commented Jan 30, 2026

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:

  • Introduce a centralized bulk modal state helper to manage open/close state for host bulk action modals.
  • Update host actions bar and all bulk action modals to use the new bulk modal state instead of the deprecated useForemanModal hook.

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

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 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.
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.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@Lukshio Lukshio force-pushed the remove_useForemanModal_Bulk branch 2 times, most recently from 44474c9 to 5da1e04 Compare January 30, 2026 16:55
Comment thread webpack/global_index.js Outdated
Copy link
Copy Markdown
Contributor

@MariaAga MariaAga left a comment

Choose a reason for hiding this comment

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

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

@Lukshio Lukshio force-pushed the remove_useForemanModal_Bulk branch from 5da1e04 to 0aea5a0 Compare February 4, 2026 10:31
Comment thread webpack/components/extensions/Hosts/BulkActions/bulkModalState.js Outdated
Copy link
Copy Markdown
Member

@jeremylenz jeremylenz left a comment

Choose a reason for hiding this comment

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

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 = {};
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

@jeremylenz jeremylenz Feb 5, 2026

Choose a reason for hiding this comment

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

Another option would be to refactor the Katello modals so they (or their parent components) manage their own open states.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Comment thread webpack/components/extensions/Hosts/BulkActions/bulkModalState.js Outdated
Comment thread webpack/components/extensions/Hosts/BulkActions/bulkModalState.js Outdated
Copy link
Copy Markdown
Member

@jeremylenz jeremylenz left a comment

Choose a reason for hiding this comment

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

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.

@Lukshio
Copy link
Copy Markdown
Contributor Author

Lukshio commented Feb 5, 2026

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.

@Lukshio Lukshio force-pushed the remove_useForemanModal_Bulk branch from 0aea5a0 to 050215b Compare February 5, 2026 12:06
Comment thread webpack/components/extensions/Hosts/BulkActions/bulkModalState.js Outdated
Comment thread webpack/components/extensions/Hosts/BulkActions/bulkModalState.js
Comment thread webpack/components/extensions/Hosts/BulkActions/bulkModalState.js Outdated
@Lukshio Lukshio force-pushed the remove_useForemanModal_Bulk branch from 050215b to 04bf199 Compare February 5, 2026 16:07
@Lukshio
Copy link
Copy Markdown
Contributor Author

Lukshio commented Feb 5, 2026

Fix lint errors + rename function to openBulkModal

@Lukshio
Copy link
Copy Markdown
Contributor Author

Lukshio commented Feb 6, 2026

Thank you for all the reviews, is there anything to be edited?

Copy link
Copy Markdown
Member

@jeremylenz jeremylenz left a comment

Choose a reason for hiding this comment

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

Thanks @Lukshio

Works fine in my testing. I suppose this is the best alternative for now. ACK 👍

@jeremylenz jeremylenz merged commit 7bfca4b into Katello:master Feb 6, 2026
24 of 26 checks passed
@nadjaheitmann
Copy link
Copy Markdown
Contributor

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.

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

@jeremylenz
Copy link
Copy Markdown
Member

If the best solution is to use the existing code, I'd say let's remove it from Katello and put it in Foreman.

@nadjaheitmann
Copy link
Copy Markdown
Contributor

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.

@nadjaheitmann
Copy link
Copy Markdown
Contributor

@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.

@jeremylenz
Copy link
Copy Markdown
Member

If someone would open a PR adding it to Foreman and another removing from Katello, I would approve them :)

@nadjaheitmann
Copy link
Copy Markdown
Contributor

nadjaheitmann commented Mar 4, 2026

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

@Lukshio
Copy link
Copy Markdown
Contributor Author

Lukshio commented Mar 4, 2026

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.

nadjaheitmann pushed a commit to ATIX-AG/foreman that referenced this pull request Mar 5, 2026
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
ofedoren pushed a commit to theforeman/foreman that referenced this pull request Mar 6, 2026
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
@Lukshio Lukshio deleted the remove_useForemanModal_Bulk branch May 4, 2026 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants