Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
kgabryje committed Jan 31, 2022
1 parent aba15f7 commit 639cbb6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/
import React from 'react';
import { styledShallow as shallow } from 'spec/helpers/theming';
import { render, screen } from 'spec/helpers/testing-library';
import {
DatasourceType,
getChartControlPanelRegistry,
Expand All @@ -30,9 +30,7 @@ import {
ControlPanelsContainerProps,
} from 'src/explore/components/ControlPanelsContainer';

describe('ControlPanelsContainer', () => {
let wrapper;

describe('ControlPanelsContainer2', () => {
beforeAll(() => {
getChartControlPanelRegistry().registerValue('table', {
controlPanelSections: [
Expand Down Expand Up @@ -96,9 +94,9 @@ describe('ControlPanelsContainer', () => {
}

it('renders ControlPanelSections', () => {
wrapper = shallow(<ControlPanelsContainer {...getDefaultProps()} />);
render(<ControlPanelsContainer {...getDefaultProps()} />);
expect(
wrapper.find('[data-test="collapsible-control-panel"]'),
).toHaveLength(5);
screen.getAllByTestId('collapsible-control-panel-header'),
).toHaveLength(4);
});
});
32 changes: 15 additions & 17 deletions superset-frontend/src/explore/components/ControlPanelsContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
/* eslint camelcase: 0 */
import React, { useCallback, useContext, useEffect, useState } from 'react';
import { useSelector } from 'react-redux';
import {
ensureIsArray,
t,
Expand Down Expand Up @@ -54,9 +53,9 @@ import Control from './Control';
import { ControlPanelAlert } from './ControlPanelAlert';

export type ControlPanelsContainerProps = {
exploreState: ExplorePageState['explore'];
actions: ExploreActions;
datasource_type: DatasourceType;
exploreState: ExplorePageState['explore'];
chart: ChartState;
controls: Record<string, ControlState>;
form_data: QueryFormData;
Expand Down Expand Up @@ -180,12 +179,8 @@ function getState(

export const ControlPanelsContainer = (props: ControlPanelsContainerProps) => {
const pluginContext = useContext(PluginContext);
const exploreState = useSelector<
ExplorePageState,
ExplorePageState['explore']
>(state => state.explore);

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

const [expandedQuerySections, setExpandedQuerySections] = useState<string[]>(
[],
Expand All @@ -204,12 +199,16 @@ export const ControlPanelsContainer = (props: ControlPanelsContainerProps) => {
useEffect(() => {
if (
prevDatasource &&
(exploreState.datasource?.id !== prevDatasource.id ||
exploreState.datasource?.type !== prevDatasource.type)
(props.exploreState.datasource?.id !== prevDatasource.id ||
props.exploreState.datasource?.type !== prevDatasource.type)
) {
setShowDatasourceAlert(true);
}
}, [exploreState.datasource, prevDatasource]);
}, [
props.exploreState.datasource?.id,
props.exploreState.datasource?.type,
prevDatasource,
]);

useEffect(() => {
const {
Expand All @@ -219,7 +218,7 @@ export const ControlPanelsContainer = (props: ControlPanelsContainerProps) => {
customizeSections: newCustomizeSections,
} = getState(
props.form_data.viz_type,
exploreState.datasource,
props.exploreState.datasource,
props.datasource_type,
);
setExpandedQuerySections(newExpandedQuerySections);
Expand All @@ -229,13 +228,13 @@ export const ControlPanelsContainer = (props: ControlPanelsContainerProps) => {
}, [props.form_data.datasource, props.form_data.viz_type]);

const resetTransferredControls = useCallback(() => {
ensureIsArray(exploreState.controlsTransferred).forEach(controlName =>
ensureIsArray(props.exploreState.controlsTransferred).forEach(controlName =>
props.actions.setControlValue(
controlName,
props.controls[controlName].default,
),
);
}, [props.actions, exploreState.controlsTransferred, props.controls]);
}, [props.actions, props.exploreState.controlsTransferred, props.controls]);

const handleClearFormClick = useCallback(() => {
resetTransferredControls();
Expand Down Expand Up @@ -314,7 +313,7 @@ export const ControlPanelsContainer = (props: ControlPanelsContainerProps) => {
}),
);
const PanelHeader = () => (
<span>
<span data-test="collapsible-control-panel-header">
<span>{label}</span>{' '}
{description && (
// label is only used in tooltip id (should probably call this prop `id`)
Expand All @@ -332,7 +331,6 @@ export const ControlPanelsContainer = (props: ControlPanelsContainerProps) => {

return (
<Collapse.Panel
data-test="collapsible-control-panel"
css={theme => css`
margin-bottom: 0;
box-shadow: none;
Expand Down Expand Up @@ -390,7 +388,7 @@ export const ControlPanelsContainer = (props: ControlPanelsContainerProps) => {
};

const hasControlsTransferred =
ensureIsArray(exploreState.controlsTransferred).length > 0;
ensureIsArray(props.exploreState.controlsTransferred).length > 0;

const DatasourceAlert = useCallback(
() =>
Expand All @@ -417,7 +415,7 @@ export const ControlPanelsContainer = (props: ControlPanelsContainerProps) => {
type="warning"
/>
),
[handleClearFormClick, hasControlsTransferred],
[handleClearFormClick, handleContinueClick, hasControlsTransferred],
);

const controlPanelRegistry = getChartControlPanelRegistry();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,7 @@ function ExploreViewContainer(props) {
datasourceType={props.datasource_type}
/>
<ConnectedControlPanelsContainer
exploreState={props.exploreState}
actions={props.actions}
form_data={props.form_data}
controls={props.controls}
Expand Down Expand Up @@ -674,6 +675,7 @@ function mapStateToProps(state) {
ownState: dataMask[form_data.slice_id ?? 0]?.ownState, // 0 - unsaved chart
impressionId,
user: explore.user,
exploreState: explore,
reports,
};
}
Expand Down

0 comments on commit 639cbb6

Please sign in to comment.