-
Notifications
You must be signed in to change notification settings - Fork 156
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
refactor: modal implementation #10212
Conversation
Thanks for opening this pull request! The maintainers of this repository would appreciate it if you would create a changelog item based on your changes. |
99e4909
to
36bc288
Compare
36bc288
to
b413395
Compare
|
display: inline-grid; | ||
grid-auto-flow: column; | ||
grid-auto-columns: 1fr; | ||
} |
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.
😍
packages/web-app-admin-settings/src/components/Groups/CreateGroupModal.vue
Show resolved
Hide resolved
packages/web-app-admin-settings/src/components/Users/CreateUserModal.vue
Show resolved
Hide resolved
await wrapper.vm.onConfirm() | ||
try { | ||
await wrapper.vm.onConfirm() | ||
} catch (error) {} |
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.
Hum? What is this good for?
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.
Since we test for an error here the test would fail otherwise. So we wouldn't be able to set any expectations afterwards.
packages/web-pkg/tests/unit/composables/piniaStores/useModals.spec.ts
Outdated
Show resolved
Hide resolved
revert: event === 'beforeUnmount' | ||
}) | ||
}, | ||
|
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.
Is this now handled anywhere else?
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.
No, but I didn't find a reason to keep it. Modals are being focused correctly due to the focus trap in OcModal
.
await Promise.all([ | ||
this.store.dispatch('clearDynamicNavItems'), | ||
this.store.dispatch('hideModal') | ||
]) |
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.
What did this even do?
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.
Closing a potentially open modal I guess 😄
state, | ||
actions, | ||
mutations | ||
} |
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.
bye bye we won't miss you
I'll create a follow-up PR which addresses all the resolved comments, coming right up. |
Description
Remove the modal from vuex store and integrates it into pinia instead. This change completely reworks how to work with modals. The main benefits and changes are:
How to use it
Modals can be dispatched via the
dispatchModal
method like so:The modal will automatically be removed when either the cancel or the confirm button has been clicked and the resulting promise resolved successfully. If needed, a modal can be removed manually via the provided method
removeModal
.It is also possible to register another modal while having a modal open. This will add the new modal to the top of the queue and immediately display it. After it closes, the previous modal will show again.
A modal which is present in the queue but not showing can be displayed via the method
setModalActive
.Custom components
Modals can have custom components with custom properties:
This will render the
CreateFolderComponent
inside the modal while still showing the cancel and confirm buttons at the bottom.It is also possible to define the
onConfirm
andonCancel
methods inside the component. They must be namedonConfirm
/onCancel
and be exposed viaexpose({ onConfirm, onCancel })
. Note that if these methods are defined inregisterModal
, they will take priority over defined methods in the component.Modal actions can be hidden if you need to implement custom actions inside the component:
Now you can implement these actions on your own. Note that you should still expose
onConfirm
/onCancel
viaexpose
and not call them directly with your actions. Register additional event handlers on the buttons instead:emit('confirm')
andemit('cancel')
. This ensures that the methods get called via the wrapping component which provides the benefits such as automatically closing the modal after confirm or cancel.Open questions / follow-ups
Modals
folders...Modal
to...ModalContent
?Related Issue
Types of changes