Skip to content

Commit

Permalink
Simplify the code
Browse files Browse the repository at this point in the history
  • Loading branch information
ktmud committed Feb 26, 2021
1 parent ab8dfce commit e4e6172
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions superset-frontend/src/explore/reducers/getInitialState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,34 +68,29 @@ export default function getInitialState(
},
isDatasourceMetaLoading: false,
isStarred: false,
};

// Initial control state will to skip `control.mapStateToProps`
// because `state.controls` is undefined.
const controls: ControlStateMapping = getControlsState(
exploreState,
initialFormData,
);
const exploreStateWithControls = {
...exploreState,
controls,
// Initial control state will skip `control.mapStateToProps`
// because `bootstrapData.controls` is undefined.
controls: getControlsState(
bootstrapData,
initialFormData,
) as ControlStateMapping,
};

// apply initial mapStateToProps for all controls, must execute AFTER
// bootstrapState has initialized `controls`. Order of execution is not
// guaranteed, so controls shouldn't rely on the each other's mapped state.
Object.entries(controls).forEach(([key, controlState]) => {
controls[key] = applyMapStateToPropsToControl(
Object.entries(exploreState.controls).forEach(([key, controlState]) => {
exploreState.controls[key] = applyMapStateToPropsToControl(
controlState,
exploreStateWithControls,
exploreState,
);
});

const sliceFormData = slice
? getFormDataFromControls(getControlsState(exploreState, slice.form_data))
? getFormDataFromControls(getControlsState(bootstrapData, slice.form_data))
: null;

const chartKey: number = getChartKey(exploreState);
const chartKey: number = getChartKey(bootstrapData);

return {
charts: {
Expand All @@ -105,7 +100,7 @@ export default function getInitialState(
chartStatus: null,
chartUpdateEndTime: null,
chartUpdateStartTime: 0,
latestQueryFormData: getFormDataFromControls(controls),
latestQueryFormData: getFormDataFromControls(exploreState.controls),
sliceFormData,
queryController: null,
queriesResponse: null,
Expand All @@ -117,7 +112,7 @@ export default function getInitialState(
dashboards: [],
saveModalAlert: null,
},
explore: exploreStateWithControls,
explore: exploreState,
impressionId: shortid.generate(),
messageToasts: getToastsFromPyFlashMessages(
(bootstrapData.common || {}).flash_messages || [],
Expand Down

0 comments on commit e4e6172

Please sign in to comment.