From 18c22ee00941589dbc08957d0ab354f15f9bad1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adem=C3=ADlson=20F=2E=20Tonato?= Date: Mon, 25 Mar 2019 15:21:54 +0000 Subject: [PATCH 1/3] (refactor): remove unnecessary logic --- src/utils/repo-parsing.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/utils/repo-parsing.js b/src/utils/repo-parsing.js index 0d1c458e..0da1a26e 100644 --- a/src/utils/repo-parsing.js +++ b/src/utils/repo-parsing.js @@ -35,9 +35,8 @@ export function parseLanguages(repo) { const languages = get(repo, 'languages') if (Array.isArray(languages)) { return filter(languages, Boolean) - } else { - return [] } + return [] } export function parseEmail(repo) { @@ -52,15 +51,15 @@ export function parseRepositoryURL(repo) { if (Boolean(url)) { if (url.startsWith('git://github.com/')) { - url = url.replace('git://github.com/', 'https://github.com/') + return url.replace('git://github.com/', 'https://github.com/') } if (url.startsWith('git@github.com:')) { - url = url.replace('git@github.com:', 'https://github.com/') + return url.replace('git@github.com:', 'https://github.com/') } if (url.startsWith('https://github.com') && url.endsWith('.git')) { - url = url.replace('.git', '') + return url.replace('.git', '') } return url From e32209340b4abba0ad9b79efdb6fc051f111edd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adem=C3=ADlson=20F=2E=20Tonato?= <5417662+ftonato@users.noreply.github.com> Date: Tue, 26 Mar 2019 10:26:00 +0000 Subject: [PATCH 2/3] (refactor): updates let to const --- src/utils/repo-parsing.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/repo-parsing.js b/src/utils/repo-parsing.js index 0da1a26e..eb0c9f29 100644 --- a/src/utils/repo-parsing.js +++ b/src/utils/repo-parsing.js @@ -47,7 +47,7 @@ export function parseEmail(repo) { } export function parseRepositoryURL(repo) { - let url = get(repo, 'repositoryURL') + const url = get(repo, 'repositoryURL') if (Boolean(url)) { if (url.startsWith('git://github.com/')) { From 24f4b912533ff0628cdca54226275f88fbdf55fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adem=C3=ADlson=20F=2E=20Tonato?= Date: Thu, 28 Mar 2019 16:57:47 +0000 Subject: [PATCH 3/3] (refacotor): avoiding deeply nested control flow statements --- src/components/app/app.container.js | 53 +++++++++++++---------------- 1 file changed, 23 insertions(+), 30 deletions(-) diff --git a/src/components/app/app.container.js b/src/components/app/app.container.js index 196f9e1b..3cc97375 100644 --- a/src/components/app/app.container.js +++ b/src/components/app/app.container.js @@ -1,21 +1,17 @@ import { forEach } from '@code.gov/cautious' -import AppComponent from './app.component' -import { withRouter } from 'react-router-dom' -import { connect } from 'react-redux' -import loadProject from 'actions/load-project' import updateBrowseParams from 'actions/update-browse-params' import updateSearchParams from 'actions/update-search-params' import updateTaskParams from 'actions/update-task-params' -import { - getNormalizedURLSearchParams, - getSection -} from 'utils/url-parsing' -import { getConfigValue, now } from 'utils/other' import defaultState from 'constants/default-redux-store-state' +import { connect } from 'react-redux' +import { withRouter } from 'react-router-dom' +import { getConfigValue, now } from 'utils/other' +import { getNormalizedURLSearchParams, getSection } from 'utils/url-parsing' +import AppComponent from './app.component' export const mapStateToProps = () => { return { - plugins: getConfigValue('plugins'), + plugins: getConfigValue('plugins') } } @@ -28,15 +24,13 @@ export const mapDispatchToProps = dispatch => { if (section === 'browse' || section === 'search') { const filters = [] forEach(['agencies', 'languages', 'licenses', 'usageTypes'], key => { - console.log("key:", key) - if (parsed[key]) { - const values = parsed[key] - if (values) { - console.log("values:", values) - values.forEach(value => { - filters.push({ category: key, value, modified: now() }) - }) - } + console.log('key:', key) + const values = parsed[key] + if (values) { + console.log('values:', values) + values.forEach(value => { + filters.push({ category: key, value, modified: now() }) + }) } }) const params = { filters } @@ -55,13 +49,11 @@ export const mapDispatchToProps = dispatch => { } else if (section === 'tasks') { const filters = [] forEach(['agencies', 'languages', 'skillLevels', 'timeRequired', 'usageTypes'], key => { - if (parsed[key]) { - const values = parsed[key] - if (values) { - values.forEach(value => { - filters.push({ category: key, value, modified: now() }) - }) - } + const values = parsed[key] + if (values) { + values.forEach(value => { + filters.push({ category: key, value, modified: now() }) + }) } }) const params = { filters } @@ -69,14 +61,15 @@ export const mapDispatchToProps = dispatch => { params[key] = parsed[key] || defaultState.taskParams[key] }) dispatch(updateTaskParams(params)) - } else { } } - } } } -const AppContainer = connect(mapStateToProps, mapDispatchToProps)(AppComponent); +const AppContainer = connect( + mapStateToProps, + mapDispatchToProps +)(AppComponent) -export default withRouter(AppContainer); +export default withRouter(AppContainer)