Skip to content

Commit

Permalink
refactoring control changed code
Browse files Browse the repository at this point in the history
  • Loading branch information
GabeLoins committed Feb 24, 2018
1 parent 032d8c1 commit 584994c
Showing 1 changed file with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,24 @@ class ExploreViewContainer extends React.Component {
if (np.controls.datasource.value !== this.props.controls.datasource.value) {
this.props.actions.fetchDatasourceMetadata(np.form_data.datasource, true);
}
// if any control value changed and it's a display control
if (this.hasDisplayControlChanged(this.props.controls, np.controls)) {

const changedControlKeys = this.findChangedControlKeys(this.props.controls, np.controls);
if (this.hasDisplayControlChanged(changedControlKeys, np.controls)) {
this.props.actions.updateQueryFormData(
getFormDataFromControls(np.controls), this.props.chart.chartKey);
this.props.actions.renderTriggered(new Date().getTime(), this.props.chart.chartKey);
}
if (this.hasQueryControlChanged(this.props.controls, np.controls)) {
this.setState({ chartIsStale: true })
if (this.hasQueryControlChanged(changedControlKeys, np.controls)) {
this.setState({ chartIsStale: true });
}
}

/* eslint no-unused-vars: 0 */
componentDidUpdate(prevProps, prevState) {
this.triggerQueryIfNeeded();

if (this.hasDisplayControlChanged(prevProps.controls, this.props.controls)) {
const changedControlKeys = this.findChangedControlKeys(prevProps.controls, this.props.controls);
if (this.hasDisplayControlChanged(changedControlKeys, this.props.controls)) {
this.addHistory({});
}
}
Expand Down Expand Up @@ -126,20 +128,19 @@ class ExploreViewContainer extends React.Component {
return `${window.innerHeight - navHeight}px`;
}

hasDisplayControlChanged(prevControls, currentControls) {
return Object.keys(currentControls).some(key => (
currentControls[key].renderTrigger &&
findChangedControlKeys(prevControls, currentControls) {
return Object.keys(currentControls).filter(key => (
typeof prevControls[key] !== 'undefined' &&
!areObjectsEqual(currentControls[key].value, prevControls[key].value)
));
}

hasQueryControlChanged(prevControls, currentControls) {
return Object.keys(currentControls).some(key => (
!currentControls[key].renderTrigger &&
typeof prevControls[key] !== 'undefined' &&
!areObjectsEqual(currentControls[key].value, prevControls[key].value)
));
hasDisplayControlChanged(changedControlKeys, currentControls) {
return changedControlKeys.some(key => (currentControls[key].renderTrigger));
}

hasQueryControlChanged(changedControlKeys, currentControls) {
return changedControlKeys.some(key => !currentControls[key].renderTrigger);
}

triggerQueryIfNeeded() {
Expand Down

0 comments on commit 584994c

Please sign in to comment.