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

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ranihorev
Copy link
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
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
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
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
Contributor

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

@ranihorev
Copy link
Contributor Author

ranihorev commented Jun 22, 2021 via email

@christopherthielen
Copy link
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
Contributor Author

ranihorev commented Jun 22, 2021 via email

@ranihorev
Copy link
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

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.

3 participants