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

Have KModal pass through their 'submit' and 'cancel' events to simplify other modals #5439

Merged

Conversation

jonboiser
Copy link
Contributor

@jonboiser jonboiser commented Apr 29, 2019

Summary

  1. Changes KModal to have its parent emit 'submit' or 'cancel' events if these listeners have not been set on KModal. The point of this is to remove some boilerplate like @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.
  2. For some modals, remove some coupling to Vuex (moving towards a full decoupling of modals from vuex so they are more like simple forms or input elements).
  3. Wrap the text in KButton in a span, so it doesn't add extra whitespace when KButton is set to be basic-link
  4. Fix a warning coming from CoreMenu

Reviewer guidance

  1. The simplest change is to delete lines like @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:

  • PR has the correct target branch and milestone
  • PR has 'needs review' or 'work-in-progress' label
  • If PR is ready for review, a reviewer has been added. (Don't use 'Assignees')
  • If this is an important user-facing change, PR or related issue has a 'changelog' label
  • If this includes an internal dependency change, a link to the diff is provided

Testing:

  • Contributor has fully tested the PR manually
  • If there are any front-end changes, before/after screenshots are included
  • Critical user journeys are covered by Gherkin stories
  • Critical and brittle code paths are covered by unit tests

Reviewer Checklist

  • Automated test coverage is satisfactory
  • PR is fully functional
  • PR has been tested for accessibility regressions
  • External dependency files were updated if necessary (yarn and pip)
  • Documentation is updated
  • Contributor is in AUTHORS.md

@jonboiser jonboiser added the TODO: needs review Waiting for review label Apr 29, 2019
@jonboiser jonboiser added this to the 0.12.y milestone Apr 29, 2019
@jonboiser jonboiser changed the title Consistent modals Have KModal pass through their 'submit' and 'cancel' events to simplify other modals Apr 29, 2019
@codecov
Copy link

codecov bot commented Apr 29, 2019

@indirectlylit indirectlylit changed the base branch from develop to release-v0.12.y May 10, 2019 05:04
Copy link
Contributor

@indirectlylit indirectlylit left a 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!

Copy link
Contributor

@indirectlylit indirectlylit left a 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');
Copy link
Contributor

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');
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor Author

@jonboiser jonboiser May 17, 2019

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.

Copy link
Contributor

@indirectlylit indirectlylit May 17, 2019

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'))

@jonboiser jonboiser added work-in-progress Not ready for review and removed TODO: needs review Waiting for review labels May 18, 2019
@jonboiser jonboiser added the TODO: needs review Waiting for review label May 20, 2019
@jonboiser
Copy link
Contributor Author

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.

@indirectlylit indirectlylit merged commit 7609fda into learningequality:release-v0.12.y May 20, 2019
@jonboiser jonboiser deleted the consistent-modals branch May 21, 2019 17:03
@jonboiser jonboiser removed TODO: needs review Waiting for review labels Jun 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
work-in-progress Not ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants