Skip to content

Commit

Permalink
fix(plugin-chart-table): Resetting controls when switching query mode (
Browse files Browse the repository at this point in the history
  • Loading branch information
kgabryje authored Apr 20, 2022
1 parent 9c20299 commit fcc8080
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
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

0 comments on commit fcc8080

Please sign in to comment.