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(plugin-chart-table): Resetting controls when switching query mode #19792

Merged
merged 1 commit into from
Apr 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
10 changes: 10 additions & 0 deletions superset-frontend/plugins/plugin-chart-table/src/controlPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ const all_columns: typeof sharedControls.groupby = {
: [],
}),
visibility: isRawMode,
resetOnHide: false,
};

const dnd_all_columns: typeof sharedControls.groupby = {
Expand All @@ -140,6 +141,7 @@ const dnd_all_columns: typeof sharedControls.groupby = {
return newState;
},
visibility: isRawMode,
resetOnHide: false,
};

const percent_metrics: typeof sharedControls.metrics = {
Expand All @@ -150,6 +152,7 @@ const percent_metrics: typeof sharedControls.metrics = {
),
multi: true,
visibility: isAggMode,
resetOnHide: false,
mapStateToProps: ({ datasource, controls }, controlState) => ({
columns: datasource?.columns || [],
savedMetrics: datasource?.metrics || [],
Expand Down Expand Up @@ -190,6 +193,7 @@ const config: ControlPanelConfig = {
name: 'groupby',
override: {
visibility: isAggMode,
resetOnHide: false,
mapStateToProps: (
state: ControlPanelState,
controlState: ControlState,
Expand Down Expand Up @@ -220,6 +224,7 @@ const config: ControlPanelConfig = {
override: {
validators: [],
visibility: isAggMode,
resetOnHide: false,
mapStateToProps: (
{ controls, datasource, form_data }: ControlPanelState,
controlState: ControlState,
Expand Down Expand Up @@ -263,6 +268,7 @@ const config: ControlPanelConfig = {
name: 'timeseries_limit_metric',
override: {
visibility: isAggMode,
resetOnHide: false,
},
},
{
Expand All @@ -277,6 +283,7 @@ const config: ControlPanelConfig = {
choices: datasource?.order_by_choices || [],
}),
visibility: isRawMode,
resetOnHide: false,
},
},
],
Expand Down Expand Up @@ -329,6 +336,7 @@ const config: ControlPanelConfig = {
),
default: false,
visibility: isAggMode,
resetOnHide: false,
},
},
{
Expand All @@ -339,6 +347,7 @@ const config: ControlPanelConfig = {
default: true,
description: t('Whether to sort descending or ascending'),
visibility: isAggMode,
resetOnHide: false,
},
},
],
Expand All @@ -353,6 +362,7 @@ const config: ControlPanelConfig = {
'Show total aggregations of selected metrics. Note that row limit does not apply to the result.',
),
visibility: isAggMode,
resetOnHide: false,
},
},
],
Expand Down
5 changes: 4 additions & 1 deletion superset-frontend/src/explore/components/Control.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export type ControlProps = {
renderTrigger?: boolean;
default?: JsonValue;
isVisible?: boolean;
resetOnHide?: boolean;
};

/**
Expand All @@ -65,6 +66,7 @@ export default function Control(props: ControlProps) {
type,
hidden,
isVisible,
resetOnHide = true,
} = props;

const [hovered, setHovered] = useState(false);
Expand All @@ -79,7 +81,8 @@ export default function Control(props: ControlProps) {
wasVisible === true &&
isVisible === false &&
props.default !== undefined &&
!isEqual(props.value, props.default)
!isEqual(props.value, props.default) &&
resetOnHide
) {
// reset control value if setting to invisible
setControlValue?.(name, props.default);
Expand Down