From 1421546baf321e472ee741a12c31747f660423da Mon Sep 17 00:00:00 2001 From: "Juan Picado @jotadeveloper" Date: Sat, 15 Dec 2018 21:03:51 +0100 Subject: [PATCH] chore: fix react/jsx-no-bind issues enable react/jsx-max-props-per-line --- .eslintrc | 4 +- src/webui/components/AutoComplete/index.js | 46 +++++++++++----------- src/webui/components/Login/index.js | 31 +++++++++------ src/webui/router.js | 19 +++++++-- 4 files changed, 60 insertions(+), 40 deletions(-) diff --git a/.eslintrc b/.eslintrc index 337b34bc7..4a768d92b 100644 --- a/.eslintrc +++ b/.eslintrc @@ -82,8 +82,8 @@ "react/jsx-indent-props": ["error", 2], "react/jsx-key": ["error"], "react/jsx-max-depth": ["warn", { "max": 2}], - "react/jsx-max-props-per-line": ["warn", {"maximum": 3, "when": "multiline" }], - "react/jsx-no-bind": ["warn"], + "react/jsx-max-props-per-line": ["error", {"maximum": 3, "when": "multiline" }], + "react/jsx-no-bind": ["error"], "react/jsx-no-comment-textnodes": ["warn"], "react/jsx-no-duplicate-props": ["warn"], "react/jsx-no-literals": ["warn"], diff --git a/src/webui/components/AutoComplete/index.js b/src/webui/components/AutoComplete/index.js index cd00a273d..cef571b32 100644 --- a/src/webui/components/AutoComplete/index.js +++ b/src/webui/components/AutoComplete/index.js @@ -96,30 +96,32 @@ const AutoComplete = ({ onSuggestionsFetchRequested: onSuggestionsFetch, onSuggestionsClearRequested: onCleanSuggestions, }; + const inputProps = { + value, + onChange, + placeholder, + startAdornment, + disableUnderline, + color, + onKeyDown, + onBlur, + }; + + // this format avoid arrow function eslint rule + function renderSuggestionsContainer({ containerProps, children, query }) { + return ( + + {suggestionsLoaded && children === null && query && renderMessage(SUGGESTIONS_RESPONSE.NO_RESULT)} + {suggestionsLoading && query && renderMessage(SUGGESTIONS_RESPONSE.LOADING)} + {suggestionsError && renderMessage(SUGGESTIONS_RESPONSE.FAILURE)} + {children} + + ); + } + return ( - ( - - {suggestionsLoaded && children === null && query && renderMessage(SUGGESTIONS_RESPONSE.NO_RESULT)} - {suggestionsLoading && query && renderMessage(SUGGESTIONS_RESPONSE.LOADING)} - {suggestionsError && renderMessage(SUGGESTIONS_RESPONSE.FAILURE)} - {children} - - )} - /> + ); }; diff --git a/src/webui/components/Login/index.js b/src/webui/components/Login/index.js index d32f904ff..6b1b359ac 100644 --- a/src/webui/components/Login/index.js +++ b/src/webui/components/Login/index.js @@ -31,9 +31,6 @@ export default class LoginModal extends Component { constructor(props) { super(props); - this.submitCredentials = this.submitCredentials.bind(this); - this.setCredentials = this.setCredentials.bind(this); - this.validateCredentials = this.validateCredentials.bind(this); this.state = { form: { username: { @@ -57,7 +54,7 @@ export default class LoginModal extends Component { * set login modal's username and password to current state * Required to login */ - setCredentials(name, e) { + setCredentials = (name, e) => { this.setState({ form: { ...this.state.form, @@ -70,7 +67,15 @@ export default class LoginModal extends Component { }); } - validateCredentials(event) { + setUsername = (event) => { + this.setCredentials('username', event); + } + + setPassword = (event) => { + this.setCredentials('password', event); + } + + validateCredentials = (event) => { // prevents default submit behavior event.preventDefault(); @@ -86,7 +91,7 @@ export default class LoginModal extends Component { }); } - async submitCredentials() { + submitCredentials = async () => { const { form: { username, password } } = this.state; await this.props.onSubmit(username.value, password.value); // let's wait for API response and then set @@ -99,8 +104,8 @@ export default class LoginModal extends Component { }); } - renderMessage(title, description) { - const errorMessage = ( + renderErrorMessage(title, description) { + return (
@@ -111,13 +116,15 @@ export default class LoginModal extends Component { {description}
); + } + renderMessage(title, description) { return (
- {errorMessage()} + {this.renderErrorMessage(title, description)}
); } @@ -141,7 +148,7 @@ export default class LoginModal extends Component { onClose={onCancel} open={visibility} > -
+ Login {this.renderLoginError(error)} @@ -153,7 +160,7 @@ export default class LoginModal extends Component { Username @@ -172,7 +179,7 @@ export default class LoginModal extends Component { Password { render() { - const { isUserLoggedIn, packages } = this.props; return ( - } /> - } /> - } /> + + + ); } + + renderHomePage = () => { + const { isUserLoggedIn, packages } = this.props; + + return ; + }; + + renderDetailPage = () => { + const { isUserLoggedIn } = this.props; + + return ; + }; } export default RouterApp;