-
-
Notifications
You must be signed in to change notification settings - Fork 317
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 component #828
Conversation
60676eb
to
279aaa9
Compare
@pavish would you like to take an early look at the direction I'm heading here? I ended up changing course somewhat in the midst of implementing this. I still have more work to do here within But in In the ticket, I originally proposed using a string as a way to tie the modal trigger to its content. With that approach, I don't like that it's possible for two separate modals to unintentionally collide by having the same identifying string. With the new direction I'm heading, we avoid that collision risk. We also avoid the requirement to use context for the It's worth noting that |
54a7171
to
8c6db29
Compare
846bd2a
to
47a4b79
Compare
@seancolsen and I discussed over a private call and decided on the following:
|
@pavish this is ready for review now. |
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.
@seancolsen This PR looks good to me. As mentioned in description, feel free to take up styling issues in a subsequent PR.
I have a few minor comments here, which I think can also be taken care of in the subsequent PR. I'll leave the call to you.
* Stores the ID of the currently opened modal | ||
*/ | ||
export default class ActiveModalStore implements Writable<number | undefined> { | ||
private openModalId = writable<number | undefined>(undefined); |
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.
I think we can allow id to be a string as well
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.
Addressed in 1b56cb6
|
||
const dispatch = createEventDispatcher(); | ||
|
||
// Additional classes | ||
export let isOpen = false; | ||
// eslint-disable-next-line no-undef-init |
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.
We can add this to eslintrc file, to disable this rule globally.
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.
Addressed in 42c4ff4
export default class ModalVisibilityStore implements Writable<boolean> { | ||
id: number; | ||
|
||
activeModalStore: ActiveModalStore; |
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.
activeModalStore
could be made private.
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.
Addressed in 19a40bb
if (shouldBecomeVisible) { | ||
return this.id; | ||
} | ||
return undefined; |
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.
The value returned here should be openModelId
instead of undefined
.
If modal A is currently open and we do BModalVisibilityStore.update((isOpen) => false);
on modal B whose isOpen
is already false
, it will close the current open modal A.
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.
Thanks for catching this! Addressed in 929d300. Though it's worth pointing out that I'm still returning undefined
in the case where the modal is currently visible and the updater specifies that the modal should no longer be visible.
Thanks for the review @pavish . Even though I added a few more commits after your review, I'm setting this PR to auto-merge because my additional changes are very small and should be in-line with your suggestions. |
Fixes #750
Pavish and I have discussed this PR on a call, so it's best that he review it to pick up where we left off.
Notes
Existing Mathesar modals
Reflections
After I got the modals working well in Storybook, I set forth trying to clean up the Mathesar modals a bit. To my chagrin however, I realized that some of the code I was hoping to simplify with these modal improvements actually was no better off.
For example in this code
the
{#if}
seems unnecessary. But I see now that its purpose is to re-mount theAddEditSchema
component.Also, I was hoping to have
Modal
containAddEditSchema
instead of the other way around, because that's the pattern I've been used to seeing in the past. I see now that there are some benefits to havingAddEditSchema
containModal
.There are several other small points like this that would be much faster to describe on a call and not worth typing out in here.
Basically, I feel a bit sheepish for coming full circle with this modal design back to a design that's strikingly similar to what we already have. The
Modal.svelte
file is definitely more robust now, but aside from that, this PR feels a bit underwhelming.Going forward
I do still want to do some clean up of our existing modals -- and I think I can even address some of the points in the previous section. But I'd like it to be in a subsequent PR. Review/discussion will be more focused. And (more importantly), I'd like to get the toast system merged, and implement #759. With a toast system and a confirmation system, then we can go clean up quite a bit at the same time. For example, some modals have additional state that we can offload to the toast system. And the majority of existing modals can be replaced by the confirmation system. I think it'll be most efficient to do that clean up all in one pass.
Checklist
Update index.md
).master
branch of the repositoryDeveloper Certificate of Origin
Developer Certificate of Origin