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

Implement input field component for keyword #482

Merged
merged 12 commits into from
May 2, 2018

Conversation

danielFangstrom
Copy link
Contributor

Summary

This PR can be summarized in the following changelog entry:

  • Adds a keyword input field component

Relevant technical choices:

  • Checks the keyword input and displays an error text under the field in case it finds comma separated words
  • Saves the result of the check (whether or not to show the error message) in the state

Test instructions

This PR can be tested by following these steps:

  • Run yarn install, yarn start, go to http://localhost:3333/, and go to the Keyword tab
  • Typing a single word in the input field should not display the error message
  • Typing two words separated by whitespace should not display the error message
  • Typing two or more words separated by commas should display the error message underneath the input field

Fixes #466

Copy link
Member

@igorschoester igorschoester left a comment

Choose a reason for hiding this comment

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

CR 🚧
The FormattedMessage from react-intl should be removed, including enzyme package. Other points are minor.

import React from "react";
import { FormattedMessage } from "react-intl";
import styled from "styled-components";
import colors from "../../../../style-guide/colors.json";
Copy link
Member

Choose a reason for hiding this comment

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

Please separate external and internal imports.


const ErrorText = styled.div`
font-size: 1em;
color: ${ colors.$color_red};
Copy link
Member

Choose a reason for hiding this comment

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

Please add a space before the };

/**
* Displays the error message
*
* @param {String} input The text of the input
Copy link
Member

Choose a reason for hiding this comment

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

That's a lot of spaces 🙂

);
}
return (
<ErrorText />
Copy link
Member

Choose a reason for hiding this comment

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

Why still render this when there is no error?

* @returns {Element} ErrorText The error message element
*/
displayErrorMessage( input = "" ) {
if ( this.state.showErrorMessage && input !== "" ) {
Copy link
Member

Choose a reason for hiding this comment

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

You could also do this in the JSX like:

return (
    { this.state.showErrorMessage && input !== "" && <ErrorText>
             <FormattedMessage />
         </ErrorText>
    }
);

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 decided to not use this in the end, since I changed the function to not render anything when there is no error, and I find the explicit function conditional I have to be more clear. Happy to change it though in case that would be more inline with other component's code style.

/**
* Constructs a KeywordInput component
*
* @param {Object} props The props for this input field component.
Copy link
Member

Choose a reason for hiding this comment

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

I would love some extra documentation here on the props themselves (id, onChange, label and keyword).


KeywordInput.propTypes = {
id: PropTypes.string.isRequired,
onChange: PropTypes.func,
Copy link
Member

Choose a reason for hiding this comment

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

I don't see this prop (onChange) actually being used anywhere. Is this something that you where planning on taking outside of this component before?

{ this.props.label }
</label>
<KeywordField type="text" id={ this.props.id }
onChange={ this.handleChange.bind( this ) }
Copy link
Member

Choose a reason for hiding this comment

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

Please bind this in the constructor, it only has to happen once, not on every render.

if ( this.state.showErrorMessage && input !== "" ) {
return (
<ErrorText>
<FormattedMessage
Copy link
Member

Choose a reason for hiding this comment

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

After confirming with @IreneStr, we will no longer be using react-intl in the future. Since you are explicitly adding the enzyme-react-intl package to test this and we might forget to remove this later. Please remove this component and test package (but still use role="alert" of course!).

package.json Outdated
@@ -80,6 +80,7 @@
"concurrently": "^3.5.0",
"enzyme": "^3.3.0",
"enzyme-adapter-react-16": "^1.1.1",
"enzyme-react-intl": "^2.0.0",
Copy link
Member

Choose a reason for hiding this comment

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

See earlier comment about react-intl. And for future notice, please also commit yarn.lock after changing something in package.json or already if some minor version got updated.

@igorschoester
Copy link
Member

CR 👍

@igorschoester igorschoester merged commit 421a6b1 into develop May 2, 2018
@igorschoester igorschoester deleted the 466-implement-keyword-input-field-component branch May 2, 2018 09:43
@igorschoester
Copy link
Member

ACC 👍

@igorschoester igorschoester modified the milestones: 4.0, 3.6 May 2, 2018
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