Skip to content
This repository was archived by the owner on Dec 20, 2025. It is now read-only.

feat(core): added useShowModal that passes the application to the context in showModal#9363

Closed
ranihorev wants to merge 1 commit into
spinnaker:masterfrom
ranihorev:use-show-modal
Closed

feat(core): added useShowModal that passes the application to the context in showModal#9363
ranihorev wants to merge 1 commit into
spinnaker:masterfrom
ranihorev:use-show-modal

Conversation

@ranihorev
Copy link
Copy Markdown
Contributor

Problem

Some components use the ApplicationContext inside of a modal, however, it's not part of the react tree and therefore can't use the context.

Solution

Added a new parameter - application - to showModal and created a new hook that passes the application from the context to showModal

Comment on lines +12 to +15
const appName = useApplicationContextSafe().name;
const { data, refetch } = useFetchApplicationManagementStatusQuery({ variables: { appName } });
const [toggleManagement] = useToggleManagementMutation();
const showModal = useShowModal();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It feels like the hook is adding a lot of code to do something simple. IMO it is more readable to fetch the application separately if it's needed, then pass the app context as a prop when invoking showModal. With the suggested approach (below), there is a consistent way to use showModal with or without the app prop, and the component will delegate which state is rendered based on the props.

Suggested change
const appName = useApplicationContextSafe().name;
const { data, refetch } = useFetchApplicationManagementStatusQuery({ variables: { appName } });
const [toggleManagement] = useToggleManagementMutation();
const showModal = useShowModal();
const appContext = useApplicationContextSafe();
const { data, refetch } = useFetchApplicationManagementStatusQuery({ variables: { appName: app.name } });
const [toggleManagement] = useToggleManagementMutation();
// later...
showModal(ResumeManagementModal, props, { maxWidth: MODAL_MAX_WIDTH }, appContext);

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.

That was my original implementation but I thought that it could be useful to add this abstraction so the consumer of the modal won't have deal with that. Does make it sense?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we call it useShowModalWithAppContext?

@christopherthielen
Copy link
Copy Markdown
Contributor

I think this problem would be better solved using react portals in showModal

@ranihorev
Copy link
Copy Markdown
Contributor Author

ranihorev commented Jun 22, 2021 via email

@christopherthielen
Copy link
Copy Markdown
Contributor

christopherthielen commented Jun 22, 2021

can you explain why adding a portal might break current uses? TBH I'm a bit surprised we arent already doing this in showModal too.

@ranihorev
Copy link
Copy Markdown
Contributor Author

ranihorev commented Jun 22, 2021 via email

@ranihorev
Copy link
Copy Markdown
Contributor Author

ranihorev commented Jun 24, 2021

When using portal event bubbling and contexts work differently (they work 🙃). While it probably won't affect the existing modal, I can't say that for sure.

The current workflow won't fit portal afaik. It has to be rendered as a react component and not via a function call (i.e. showModal). We might be able to add a separate workflow for that

@dbyron-sf dbyron-sf closed this Oct 2, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants