Make instant controls store state in URL (#4449)

* Add to history on instant control change

* Update latestQueryFormData on render triggered

* Add new message type

* Update latestQueryFormData in UPDATE_QUERY_FORM_DATA
This commit is contained in:
Beto Dealmeida
2018-02-20 17:08:07 -08:00
committed by Maxime Beauchemin
parent d4a2f4ef36
commit c3176579e0
3 changed files with 26 additions and 6 deletions

View File

@@ -76,16 +76,20 @@ class ExploreViewContainer extends React.Component {
this.props.actions.fetchDatasourceMetadata(np.form_data.datasource, true);
}
// if any control value changed and it's an instant control
if (Object.keys(np.controls).some(key => (np.controls[key].renderTrigger &&
typeof this.props.controls[key] !== 'undefined' &&
!areObjectsEqual(np.controls[key].value, this.props.controls[key].value)))
) {
if (this.instantControlChanged(this.props.controls, np.controls)) {
this.props.actions.updateQueryFormData(
getFormDataFromControls(np.controls), this.props.chart.chartKey);
this.props.actions.renderTriggered(new Date().getTime(), this.props.chart.chartKey);
}
}
componentDidUpdate() {
/* eslint no-unused-vars: 0 */
componentDidUpdate(prevProps, prevState) {
this.triggerQueryIfNeeded();
if (this.instantControlChanged(prevProps.controls, this.props.controls)) {
this.addHistory({});
}
}
componentWillUnmount() {
@@ -117,6 +121,14 @@ class ExploreViewContainer extends React.Component {
return `${window.innerHeight - navHeight}px`;
}
instantControlChanged(prevControls, currentControls) {
return Object.keys(currentControls).some(key => (
currentControls[key].renderTrigger &&
typeof prevControls[key] !== 'undefined' &&
!areObjectsEqual(currentControls[key].value, prevControls[key].value)
));
}
triggerQueryIfNeeded() {
if (this.props.chart.triggerQuery && !this.hasErrors()) {
this.props.actions.runQuery(this.props.form_data, false,