Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(explore): handle null control sections #20142

Merged
merged 2 commits into from
May 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions superset-frontend/src/explore/controlUtils/getControlConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,22 @@
import memoizeOne from 'memoize-one';
import { getChartControlPanelRegistry } from '@superset-ui/core';
import {
ControlPanelConfig,
ControlPanelSectionConfig,
expandControlConfig,
isControlPanelSectionConfig,
} from '@superset-ui/chart-controls';

/**
* Find control item from control panel config.
*/
export function findControlItem(
controlPanelSections: ControlPanelSectionConfig[],
controlPanelSections: (ControlPanelSectionConfig | null)[],
controlKey: string,
) {
return (
controlPanelSections
.filter(isControlPanelSectionConfig)
.map(section => section.controlSetRows)
.flat(2)
.find(
Expand All @@ -46,7 +49,7 @@ export function findControlItem(
}

const getMemoizedControlConfig = memoizeOne(
(controlKey, controlPanelConfig) => {
(controlKey, controlPanelConfig: ControlPanelConfig) => {
const { controlOverrides = {}, controlPanelSections = [] } =
controlPanelConfig;
const control = expandControlConfig(
Expand All @@ -62,5 +65,10 @@ export const getControlConfig = function getControlConfig(
vizType: string,
) {
const controlPanelConfig = getChartControlPanelRegistry().get(vizType) || {};
return getMemoizedControlConfig(controlKey, controlPanelConfig);
return getMemoizedControlConfig(
controlKey,
// TODO: the ChartControlPanelRegistry is incorrectly typed and needs to
// be fixed
controlPanelConfig as ControlPanelConfig,
);
};
78 changes: 40 additions & 38 deletions superset-frontend/src/explore/fixtures.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,47 +26,49 @@ import {
ControlPanelSectionConfig,
} from '@superset-ui/chart-controls';

export const controlPanelSectionsChartOptions: ControlPanelSectionConfig[] = [
{
label: t('Chart Options'),
expanded: true,
controlSetRows: [
[
'color_scheme',
{
name: 'rose_area_proportion',
config: {
type: 'CheckboxControl',
label: t('Use Area Proportions'),
description: t(
'Check if the Rose Chart should use segment area instead of ' +
'segment radius for proportioning',
),
default: false,
renderTrigger: true,
export const controlPanelSectionsChartOptions: (ControlPanelSectionConfig | null)[] =
[
null,
{
label: t('Chart Options'),
expanded: true,
controlSetRows: [
[
'color_scheme',
{
name: 'rose_area_proportion',
config: {
type: 'CheckboxControl',
label: t('Use Area Proportions'),
description: t(
'Check if the Rose Chart should use segment area instead of ' +
'segment radius for proportioning',
),
default: false,
renderTrigger: true,
},
},
},
],
[
{
name: 'stacked_style',
config: {
type: 'SelectControl',
label: t('Stacked Style'),
renderTrigger: true,
choices: [
['stack', 'stack'],
['stream', 'stream'],
['expand', 'expand'],
],
default: 'stack',
description: '',
],
[
{
name: 'stacked_style',
config: {
type: 'SelectControl',
label: t('Stacked Style'),
renderTrigger: true,
choices: [
['stack', 'stack'],
['stream', 'stream'],
['expand', 'expand'],
],
default: 'stack',
description: '',
},
},
},
],
],
],
},
];
},
];

export const controlPanelSectionsChartOptionsOnlyColorScheme: ControlPanelSectionConfig[] =
[
Expand Down
29 changes: 16 additions & 13 deletions superset-frontend/src/utils/getControlsForVizType.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,29 @@
*/

import memoize from 'lodash/memoize';
import { isControlPanelSectionConfig } from '@superset-ui/chart-controls';
import { getChartControlPanelRegistry } from '@superset-ui/core';
import { controls } from '../explore/controls';

const memoizedControls = memoize((vizType, controlPanel) => {
const controlsMap = {};
(controlPanel?.controlPanelSections || []).forEach(section => {
section.controlSetRows.forEach(row => {
row.forEach(control => {
if (!control) return;
if (typeof control === 'string') {
// For now, we have to look in controls.jsx to get the config for some controls.
// Once everything is migrated out, delete this if statement.
controlsMap[control] = controls[control];
} else if (control.name && control.config) {
// condition needed because there are elements, e.g. <hr /> in some control configs (I'm looking at you, FilterBox!)
controlsMap[control.name] = control.config;
}
(controlPanel?.controlPanelSections || [])
.filter(isControlPanelSectionConfig)
.forEach(section => {
section.controlSetRows.forEach(row => {
row.forEach(control => {
if (!control) return;
if (typeof control === 'string') {
// For now, we have to look in controls.jsx to get the config for some controls.
// Once everything is migrated out, delete this if statement.
controlsMap[control] = controls[control];
} else if (control.name && control.config) {
// condition needed because there are elements, e.g. <hr /> in some control configs (I'm looking at you, FilterBox!)
controlsMap[control.name] = control.config;
}
});
});
});
});
return controlsMap;
});

Expand Down