-
Notifications
You must be signed in to change notification settings - Fork 717
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
Have KModal pass through their 'submit' and 'cancel' events to simplify other modals #5439
Have KModal pass through their 'submit' and 'cancel' events to simplify other modals #5439
Conversation
Since it will also interecpt keyup.esc on the privacy modal
Codecov Report
|
This reverts commit ec04c7f.
e11c822
to
46f5354
Compare
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.
looks good to me, thank you!
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.
actually - question:
It looks like in a number of places we might be emitting events twice? E.g. once immediately due to v-on...
, and again inside a custom event handler?
@@ -84,7 +85,7 @@ | |||
this.saveDismissedNotification(this.id); | |||
} | |||
this.removeNotification(this.id); | |||
this.$emit('closeModal'); | |||
this.$emit('submit'); |
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 it necessary to emit anything here? I think the v-on
will do this for you?
callCreateGroup() { | ||
this.formSubmitted = true; | ||
if (this.formIsValid) { | ||
this.submitting = true; | ||
this.createGroup({ groupName: this.name, classId: this.classId }).then(() => { | ||
this.$emit('success'); | ||
this.$emit('submit'); |
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.
won't this emit submit twice? Once for v-on="$listeners"
and once here?
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.
CreateGroupModal only emits 'submit' once. I think if you explicitly set a @submit=customListener
, it sort of overwrites the {submit: parentListener}
hidden in v-on="$listeners
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.
Interestingly, though, if you remove this $emit
, the event from CreateGroupModal does not appear in the devtools, but it seems that it still goes through the GroupsPage, which is not really what I want since i want to wait till the promise is resolved before emitting 'submit'.
I'm just going to remove the v-on="listeners"
for the handful of modals that might emit the same event asynchronously.
In the future, I would like to to remove async behavior API calls from modals, and delegate them to the parents of modals. So modals just synchronously emit events and data, basically.
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.
yeah that seems reasonable.
another alternative is for modals that handle their own internal async code, to explicitly emit an event that's not submit
or cancel
. For example:
.then(() => this.$emit('finished'))
63b3d8b
to
6c9dd77
Compare
I've changed this so that every KModal simply re-emits "cancel" and/or "submit". Also added a warning on KModal in case someone shows a button, but doesnt actually register a listener for the button click. |
Summary
@submit="$emit('submit')
in the components that wrap the base KModal, and to reduce the amount variations on these event names (e.g.@close
,@success
, etc.) that appear in the code (in support of future work towards Apply consistent patterns for all modals #5320). This makes the events of something like AssignmentCopyModal the same as the basic KModal.Reviewer guidance
@submit="$emit('submit')
from wrapped KModals, which should just work. The more complicated handlers like@submit="handleSubmit
where handleSubmit may also emit or have complicated side-effects may take a little more checking.References
…
Contributor Checklist
PR process:
Testing:
Reviewer Checklist
yarn
andpip
)