This is an automated email from the ASF dual-hosted git repository. suddjian pushed a commit to branch dynamic-plugin-import in repository https://gitbox.apache.org/repos/asf/incubator-superset.git
commit a21221878b056b29936aec253e495ac294005ef6 Author: David Aaron Suddjian <[email protected]> AuthorDate: Thu Jul 2 10:45:43 2020 -0700 memoize appropriately --- superset-frontend/src/explore/controlUtils.js | 119 ++++++++++++++------------ 1 file changed, 64 insertions(+), 55 deletions(-) diff --git a/superset-frontend/src/explore/controlUtils.js b/superset-frontend/src/explore/controlUtils.js index 8ce05d9..627cba1 100644 --- a/superset-frontend/src/explore/controlUtils.js +++ b/superset-frontend/src/explore/controlUtils.js @@ -69,22 +69,25 @@ function findControlItem(controlPanelSections, controlKey) { return null; } -export const getControlConfig = memoizeOne(function getControlConfig( - controlKey, - vizType, -) { +const getMemoizedControlConfig = memoizeOne( + (controlKey, controlPanelConfig) => { + const { + controlOverrides = {}, + controlPanelSections = [], + } = controlPanelConfig; + + const control = expandControlConfig( + findControlItem(controlPanelSections, controlKey), + controlOverrides, + ); + return control?.config || control; + }, +); + +export const getControlConfig = function getControlConfig(controlKey, vizType) { const controlPanelConfig = getChartControlPanelRegistry().get(vizType) || {}; - const { - controlOverrides = {}, - controlPanelSections = [], - } = controlPanelConfig; - - const control = expandControlConfig( - findControlItem(controlPanelSections, controlKey), - controlOverrides, - ); - return control?.config || control; -}); + return getMemoizedControlConfig(controlKey, controlPanelConfig); +}; function handleMissingChoice(control) { // If the value is not valid anymore based on choices, clear it @@ -169,53 +172,59 @@ export function getControlState(controlKey, vizType, state, value) { ); } +const getMemoizedSectionsToRender = memoizeOne( + (datasourceType, controlPanelConfig) => { + const { + sectionOverrides = {}, + controlOverrides, + controlPanelSections = [], + } = controlPanelConfig; + + // default control panel sections + const sections = { ...SECTIONS }; + + // apply section overrides + Object.entries(sectionOverrides).forEach(([section, overrides]) => { + if (typeof overrides === 'object' && overrides.constructor === Object) { + sections[section] = { + ...sections[section], + ...overrides, + }; + } else { + sections[section] = overrides; + } + }); + + const { datasourceAndVizType, sqlaTimeSeries, druidTimeSeries } = sections; + const timeSection = + datasourceType === 'table' ? sqlaTimeSeries : druidTimeSeries; + + return [] + .concat(datasourceAndVizType, timeSection, controlPanelSections) + .filter(section => !!section) + .map(section => { + const { controlSetRows } = section; + return { + ...section, + controlSetRows: + controlSetRows?.map(row => + row.map(item => expandControlConfig(item, controlOverrides)), + ) || [], + }; + }); + }, +); + /** * Get the clean and processed control panel sections */ -export const sectionsToRender = memoizeOne(function sectionsToRender( +export const sectionsToRender = function sectionsToRender( vizType, datasourceType, ) { const controlPanelConfig = getChartControlPanelRegistry().get(vizType) || {}; - const { - sectionOverrides = {}, - controlOverrides, - controlPanelSections = [], - } = controlPanelConfig; - - // default control panel sections - const sections = { ...SECTIONS }; - - // apply section overrides - Object.entries(sectionOverrides).forEach(([section, overrides]) => { - if (typeof overrides === 'object' && overrides.constructor === Object) { - sections[section] = { - ...sections[section], - ...overrides, - }; - } else { - sections[section] = overrides; - } - }); - - const { datasourceAndVizType, sqlaTimeSeries, druidTimeSeries } = sections; - const timeSection = - datasourceType === 'table' ? sqlaTimeSeries : druidTimeSeries; - - return [] - .concat(datasourceAndVizType, timeSection, controlPanelSections) - .filter(section => !!section) - .map(section => { - const { controlSetRows } = section; - return { - ...section, - controlSetRows: - controlSetRows?.map(row => - row.map(item => expandControlConfig(item, controlOverrides)), - ) || [], - }; - }); -}); + return getMemoizedSectionsToRender(datasourceType, controlPanelConfig); +}; export function getAllControlsState(vizType, datasourceType, state, formData) { const controlsState = {};
