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

Enable expected Enter/Escape keys on Dashboard rename #1508

Merged
merged 4 commits into from
May 20, 2017

Conversation

cryptoquick
Copy link
Contributor

@cryptoquick cryptoquick commented May 19, 2017

  • CHANGELOG.md updated
  • Rebased/mergable
  • Tests pass
  • Sign CLA (if not already signed)

Connect #1420 #1421

The problem

Pressing escape for cancel or enter for submit doesn't do the expected thing when renaming a dashboard.

The Solution

Use a form and onSubmit handler for the title, and add a onKeyUp handler that detects escape and returns the contents of the component to its original state while canceling editing.

handleKeyUp(e) {
const {dashboard: {name}, onCancel} = this.props
if (e.key === 'Escape') {
this.setState({name})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like onCancel would already perform a setState({name}), and that this handleKeyUp method would simply call onCancel -- is this possible?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onCancel in DashboardPage.js does not do that, and it shouldn't. This is the proper place to do that. It has all the props information here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What purpose is this.setState serving here then? I just tested the code without it, and it seems to have the same effect.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! I had to think about that for a sec. onCancel actually unmounts the component, which, upon being mounted again, resets its state to what's specified in the constructor. Fair point, @jaredscheib ! This is why PR review is so important. 👍

render() {
const {onSave, onCancel} = this.props
const {name} = this.state

return (
<div className="page-header full-width">
<div className="page-header__container">
<div className="page-header__left">
<form className="page-header__left" onSubmit={this.handleFormSubmit}>
Copy link
Contributor

@jaredscheib jaredscheib May 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of using forms as it brings up the HTML5 autocomplete (and tooltips upon validation in the TVM). Either way, we should confirm with @nhaugo and @alexpaxton on the design / usage of HTML5 form validation tooltips + autofill in general in our app (ex. in TVM), as they feel discordant with the visual style and UX for the rest of the app.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've disabled autoComplete, it should help with the UX continuity.

@jaredscheib
Copy link
Contributor

jaredscheib commented May 19, 2017

Glad to see this – good work generally. A couple of notes for changes requested. Also, would request a more descriptive title for the PR, ex. "Enable expected Enter/Escape keys on Dashboard rename"

@cryptoquick cryptoquick changed the title Dashboard Rename improvements Enable expected Enter/Escape keys on Dashboard rename May 19, 2017
@cryptoquick
Copy link
Contributor Author

I've made the changes you requested, @jaredscheib 👍

@jaredscheib
Copy link
Contributor

jaredscheib commented May 19, 2017

😍 LGTM!

@jaredscheib jaredscheib merged commit 9c9ab89 into master May 20, 2017
@jaredscheib jaredscheib deleted the feature/dashboard-rename-improvements branch May 20, 2017 00:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants