Introduce an onInit method for when a new viz_type is selected (#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
This commit is contained in:
Maxime Beauchemin
2018-02-27 22:36:52 -08:00
committed by GitHub
parent 404e2d552a
commit 264822b1ee
2 changed files with 14 additions and 0 deletions

View File

@@ -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;
}

View File

@@ -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'),