Fix conditional logic

Original code:

```js
const listTitle = this.props.match.params.slug === 'languages' || 'databases' ? this.renderListTitle() : '';
```

Is interpreted as:

```js
const listTitle = ( this.props.match.params.slug === 'languages' || 'databases' ) ? this.renderListTitle() : '' ;
```

Been `databases` always been evaluate as `true`, this is the same that:

```js
const listTitle = this.renderListTitle();
```

Clearly is not the intention. I refactor this peace of code with what I think was the real intention; looking just
the code, not knowing is this is the desire behavior
This commit is contained in:
Alberto Maturano 2018-10-04 12:36:16 -05:00
parent ff003a6b58
commit d7ffb9e50e

View File

@ -397,8 +397,8 @@ export class HomePage extends React.Component { // eslint-disable-line react/pre
// if custom view display render specificComponent
const Component = this.components[specificComponent];
const addRequiredInputDesign = this.props.match.params.slug === 'databases';
const listTitle = this.props.match.params.slug === 'languages' || 'databases' ? this.renderListTitle() : '';
const listButtonLabel = this.props.match.params.slug === 'languages' || 'databases' ? this.renderListButtonLabel() : '';
const listTitle = ['languages', 'databases'].includes(this.props.match.params.slug) ? this.renderListTitle() : '';
const listButtonLabel = ['languages', 'databases'].includes(this.props.match.params.slug) ? this.renderListButtonLabel() : '';
// check if HeaderNav component needs to render a form or a list
const renderListComponent = this.props.match.params.slug === 'databases';