Skip to content

Commit

Permalink
Introduce an onInit method for when a new viz_type is selected (apach…
Browse files Browse the repository at this point in the history
…e#4491)

* Introduce an onInit method for when a new viz_type is selected

This allows for clearing certain controls where/when needed. For
instance here, when loading deck_scatter, even if there was a time
granularity picked for the previous viz_type, we want to unselect it.

* making it functional

(cherry picked from commit 264822b)
  • Loading branch information
mistercrunch committed Feb 28, 2018
1 parent 4ac697e commit a223cf6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions superset/assets/javascripts/explore/stores/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ export function getControlsState(state, form_data) {
control.value = formData[k] !== undefined ? formData[k] : control.default;
controlsState[k] = control;
});
if (viz.onInit) {
return viz.onInit(controlsState);
}
return controlsState;
}

Expand Down
11 changes: 11 additions & 0 deletions superset/assets/javascripts/explore/stores/visTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,17 @@ export const visTypes = {
deck_scatter: {
label: t('Deck.gl - Scatter plot'),
requiresTime: true,
onInit: controlState => ({
...controlState,
time_grain_sqla: {
...controlState.time_grain_sqla,
value: null,
},
granularity: {
...controlState.granularity,
value: null,
},
}),
controlPanelSections: [
{
label: t('Query'),
Expand Down

0 comments on commit a223cf6

Please sign in to comment.