Skip to content

Commit

Permalink
Fix crashing when switching viz type
Browse files Browse the repository at this point in the history
  • Loading branch information
kgabryje committed Feb 1, 2022
1 parent 06a0c0f commit 8349ccd
Showing 1 changed file with 21 additions and 34 deletions.
55 changes: 21 additions & 34 deletions superset-frontend/src/explore/components/ControlPanelsContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import React, {
useCallback,
useContext,
useEffect,
useMemo,
useRef,
useState,
} from 'react';
Expand Down Expand Up @@ -188,18 +189,6 @@ export const ControlPanelsContainer = (props: ControlPanelsContainerProps) => {

const prevDatasource = usePrevious(props.exploreState.datasource);

const [expandedQuerySections, setExpandedQuerySections] = useState<string[]>(
[],
);
const [expandedCustomizeSections, setExpandedCustomizeSections] = useState<
string[]
>([]);
const [querySections, setQuerySections] = useState<
ControlPanelSectionConfig[]
>([]);
const [customizeSections, setCustomizeSections] = useState<
ControlPanelSectionConfig[]
>([]);
const [showDatasourceAlert, setShowDatasourceAlert] = useState(false);

const containerRef = useRef<HTMLDivElement>(null);
Expand All @@ -219,22 +208,24 @@ export const ControlPanelsContainer = (props: ControlPanelsContainerProps) => {
prevDatasource,
]);

useEffect(() => {
const {
expandedQuerySections: newExpandedQuerySections,
expandedCustomizeSections: newExpandedCustomizeSections,
querySections: newQuerySections,
customizeSections: newCustomizeSections,
} = getState(
const {
expandedQuerySections,
expandedCustomizeSections,
querySections,
customizeSections,
} = useMemo(
() =>
getState(
props.form_data.viz_type,
props.exploreState.datasource,
props.datasource_type,
),
[
props.form_data.datasource,
props.form_data.viz_type,
props.exploreState.datasource,
props.datasource_type,
);
setExpandedQuerySections(newExpandedQuerySections);
setExpandedCustomizeSections(newExpandedCustomizeSections);
setQuerySections(newQuerySections);
setCustomizeSections(newCustomizeSections);
}, [props.form_data.datasource, props.form_data.viz_type]);
],
);

const resetTransferredControls = useCallback(() => {
ensureIsArray(props.exploreState.controlsTransferred).forEach(controlName =>
Expand Down Expand Up @@ -446,12 +437,10 @@ export const ControlPanelsContainer = (props: ControlPanelsContainerProps) => {
<Tabs.TabPane key="query" tab={t('Data')}>
<Collapse
bordered
activeKey={expandedQuerySections}
defaultActiveKey={expandedQuerySections}
expandIconPosition="right"
onChange={selection => {
setExpandedQuerySections(ensureIsArray(selection));
}}
ghost
key={`query-sections-${props.form_data.datasource}-${props.form_data.viz_type}`}
>
{showDatasourceAlert && <DatasourceAlert />}
{querySections.map(renderControlPanelSection)}
Expand All @@ -461,12 +450,10 @@ export const ControlPanelsContainer = (props: ControlPanelsContainerProps) => {
<Tabs.TabPane key="display" tab={t('Customize')}>
<Collapse
bordered
activeKey={expandedCustomizeSections}
defaultActiveKey={expandedCustomizeSections}
expandIconPosition="right"
onChange={selection => {
setExpandedCustomizeSections(ensureIsArray(selection));
}}
ghost
key={`customize-sections-${props.form_data.datasource}-${props.form_data.viz_type}`}
>
{customizeSections.map(renderControlPanelSection)}
</Collapse>
Expand Down

0 comments on commit 8349ccd

Please sign in to comment.