Skip to content

Commit

Permalink
Small refactor to read url params in render function
Browse files Browse the repository at this point in the history
  • Loading branch information
jloleysens committed Jun 2, 2020
1 parent 0f5f80a commit dc5470a
Showing 1 changed file with 7 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ export class IndexTable extends Component {
super(props);

this.state = {
includeHiddenIndices: false,
selectedIndicesMap: {},
};
}
Expand All @@ -117,25 +116,17 @@ export class IndexTable extends Component {
this.setState({ filterError: e });
}
}

this.syncFromUrlParams();
}
componentWillUnmount() {
clearInterval(this.interval);
}

componentDidUpdate() {
this.syncFromUrlParams();
}

syncFromUrlParams() {
readURLParams() {
const { location } = this.props;
const { includeHiddenIndices } = qs.parse((location && location.search) || '');

const nextValue = includeHiddenIndices === 'true';
if (this.state.includeHiddenIndices !== nextValue) {
this.setState({ includeHiddenIndices: nextValue });
}
return {
includeHiddenIndices: includeHiddenIndices === 'true',
};
}

setIncludeHiddenParam(hidden) {
Expand Down Expand Up @@ -446,6 +437,8 @@ export class IndexTable extends Component {
pager,
} = this.props;

const { includeHiddenIndices } = this.readURLParams();

let emptyState;

if (indicesLoading) {
Expand Down Expand Up @@ -497,7 +490,7 @@ export class IndexTable extends Component {
<EuiSwitch
id="checkboxShowHiddenIndices"
data-test-subj="indexTableIncludeHiddenIndicesToggle"
checked={this.state.includeHiddenIndices}
checked={includeHiddenIndices}
onChange={(event) => this.setIncludeHiddenParam(event.target.checked)}
label={
<FormattedMessage
Expand Down

0 comments on commit dc5470a

Please sign in to comment.