-
Notifications
You must be signed in to change notification settings - Fork 902
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
base: master
Are you sure you want to change the base?
Conversation
…text in showModal
7bdb869
to
cd78bb0
Compare
const appName = useApplicationContextSafe().name; | ||
const { data, refetch } = useFetchApplicationManagementStatusQuery({ variables: { appName } }); | ||
const [toggleManagement] = useToggleManagementMutation(); | ||
const showModal = useShowModal(); |
There was a problem hiding this comment.
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.
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
?
I think this problem would be better solved using react portals in |
I agree, I was a bit surprised that we weren't using it but didn't want to
update the current implementation, because it might break some of the
existing usage unintentionally.
Maybe I should introduce a new hook. What do you think?
…On Tue, Jun 22, 2021 at 06:07 Chris Thielen ***@***.***> wrote:
I think this problem would be better solved using react portals in
showModal
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#9363 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEC2OROQD5AR27QWDCV27JTTT746FANCNFSM47AI5WYA>
.
|
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. |
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.
…On Tue, Jun 22, 2021 at 22:51 Chris Thielen ***@***.***> wrote:
can you explain why adding a portal might break current uses? TBH I'm a
bit surprised we arent already doing this in showModal.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#9363 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEC2ORJVG4HL6ZBZWHGQAUTTUDST3ANCNFSM47AI5WYA>
.
|
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. |
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
- toshowModal
and created a new hook that passes the application from the context toshowModal