mirror of
https://github.com/apache/superset.git
synced 2024-09-06 22:07:34 -04:00
fix: Pivot Table Conditional Formatting Doesn't Show All Options (#19071)
* fix: Pivot Table Conditional Formatting Doesn't Show All Options * PR comments * PR comments
This commit is contained in:
parent
62ad574c24
commit
0e0beceac1
@ -171,6 +171,8 @@ export type TabOverride = 'data' | 'customize' | boolean;
|
|||||||
* bubbled up to the control header, section header and query panel header.
|
* bubbled up to the control header, section header and query panel header.
|
||||||
* - warning: text shown as a tooltip on a warning icon in the control's header
|
* - warning: text shown as a tooltip on a warning icon in the control's header
|
||||||
* - error: text shown as a tooltip on a error icon in the control's header
|
* - error: text shown as a tooltip on a error icon in the control's header
|
||||||
|
* - shouldMapStateToProps: a function that receives the previous and current app state
|
||||||
|
* and determines if the control needs to recalculate it's props based on the new state.
|
||||||
* - mapStateToProps: a function that receives the App's state and return an object of k/v
|
* - mapStateToProps: a function that receives the App's state and return an object of k/v
|
||||||
* to overwrite configuration at runtime. This is useful to alter a component based on
|
* to overwrite configuration at runtime. This is useful to alter a component based on
|
||||||
* anything external to it, like another control's value. For instance it's possible to
|
* anything external to it, like another control's value. For instance it's possible to
|
||||||
@ -198,6 +200,13 @@ export interface BaseControlConfig<
|
|||||||
/**
|
/**
|
||||||
* Add additional props to chart control.
|
* Add additional props to chart control.
|
||||||
*/
|
*/
|
||||||
|
shouldMapStateToProps?: (
|
||||||
|
prevState: ControlPanelState,
|
||||||
|
state: ControlPanelState,
|
||||||
|
controlState: ControlState,
|
||||||
|
// TODO: add strict `chartState` typing (see superset-frontend/src/explore/types)
|
||||||
|
chartState?: AnyDict,
|
||||||
|
) => boolean;
|
||||||
mapStateToProps?: (
|
mapStateToProps?: (
|
||||||
state: ControlPanelState,
|
state: ControlPanelState,
|
||||||
controlState: ControlState,
|
controlState: ControlState,
|
||||||
|
@ -170,7 +170,10 @@ const config: ControlPanelConfig = {
|
|||||||
configFormLayout: {
|
configFormLayout: {
|
||||||
[GenericDataType.NUMERIC]: [[radarMetricMaxValue]],
|
[GenericDataType.NUMERIC]: [[radarMetricMaxValue]],
|
||||||
},
|
},
|
||||||
mapStateToProps(explore, control, chart) {
|
shouldMapStateToProps() {
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
mapStateToProps(explore, _, chart) {
|
||||||
const values =
|
const values =
|
||||||
(explore?.controls?.metrics?.value as QueryFormMetric[]) ??
|
(explore?.controls?.metrics?.value as QueryFormMetric[]) ??
|
||||||
[];
|
[];
|
||||||
|
@ -66,6 +66,7 @@ const config: ControlPanelConfig = {
|
|||||||
config: {
|
config: {
|
||||||
...sharedControls.metrics,
|
...sharedControls.metrics,
|
||||||
validators: [validateNonEmpty],
|
validators: [validateNonEmpty],
|
||||||
|
rerender: ['conditional_formatting'],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -457,7 +457,10 @@ const config: ControlPanelConfig = {
|
|||||||
label: t('Customize columns'),
|
label: t('Customize columns'),
|
||||||
description: t('Further customize how to display each column'),
|
description: t('Further customize how to display each column'),
|
||||||
renderTrigger: true,
|
renderTrigger: true,
|
||||||
mapStateToProps(explore, control, chart) {
|
shouldMapStateToProps() {
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
mapStateToProps(explore, _, chart) {
|
||||||
return {
|
return {
|
||||||
queryResponse: chart?.queriesResponse?.[0] as
|
queryResponse: chart?.queriesResponse?.[0] as
|
||||||
| ChartDataResponseResult
|
| ChartDataResponseResult
|
||||||
@ -478,7 +481,10 @@ const config: ControlPanelConfig = {
|
|||||||
description: t(
|
description: t(
|
||||||
'Apply conditional color formatting to numeric columns',
|
'Apply conditional color formatting to numeric columns',
|
||||||
),
|
),
|
||||||
mapStateToProps(explore, control, chart) {
|
shouldMapStateToProps() {
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
mapStateToProps(explore, _, chart) {
|
||||||
const verboseMap = explore?.datasource?.verbose_map ?? {};
|
const verboseMap = explore?.datasource?.verbose_map ?? {};
|
||||||
const { colnames, coltypes } =
|
const { colnames, coltypes } =
|
||||||
chart?.queriesResponse?.[0] ?? {};
|
chart?.queriesResponse?.[0] ?? {};
|
||||||
|
@ -187,6 +187,7 @@ function getState(
|
|||||||
export const ControlPanelsContainer = (props: ControlPanelsContainerProps) => {
|
export const ControlPanelsContainer = (props: ControlPanelsContainerProps) => {
|
||||||
const pluginContext = useContext(PluginContext);
|
const pluginContext = useContext(PluginContext);
|
||||||
|
|
||||||
|
const prevState = usePrevious(props.exploreState);
|
||||||
const prevDatasource = usePrevious(props.exploreState.datasource);
|
const prevDatasource = usePrevious(props.exploreState.datasource);
|
||||||
|
|
||||||
const [showDatasourceAlert, setShowDatasourceAlert] = useState(false);
|
const [showDatasourceAlert, setShowDatasourceAlert] = useState(false);
|
||||||
@ -221,7 +222,7 @@ export const ControlPanelsContainer = (props: ControlPanelsContainerProps) => {
|
|||||||
props.datasource_type,
|
props.datasource_type,
|
||||||
),
|
),
|
||||||
[
|
[
|
||||||
props.form_data.datasource,
|
props.exploreState.datasource,
|
||||||
props.form_data.viz_type,
|
props.form_data.viz_type,
|
||||||
props.datasource_type,
|
props.datasource_type,
|
||||||
],
|
],
|
||||||
@ -245,6 +246,22 @@ export const ControlPanelsContainer = (props: ControlPanelsContainerProps) => {
|
|||||||
setShowDatasourceAlert(false);
|
setShowDatasourceAlert(false);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const shouldRecalculateControlState = ({
|
||||||
|
name,
|
||||||
|
config,
|
||||||
|
}: CustomControlItem): boolean => {
|
||||||
|
const { controls, chart, exploreState } = props;
|
||||||
|
|
||||||
|
return Boolean(
|
||||||
|
config.shouldMapStateToProps?.(
|
||||||
|
prevState || exploreState,
|
||||||
|
exploreState,
|
||||||
|
controls[name],
|
||||||
|
chart,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const renderControl = ({ name, config }: CustomControlItem) => {
|
const renderControl = ({ name, config }: CustomControlItem) => {
|
||||||
const { controls, chart, exploreState } = props;
|
const { controls, chart, exploreState } = props;
|
||||||
const { visibility } = config;
|
const { visibility } = config;
|
||||||
@ -255,11 +272,8 @@ export const ControlPanelsContainer = (props: ControlPanelsContainerProps) => {
|
|||||||
const controlData = {
|
const controlData = {
|
||||||
...config,
|
...config,
|
||||||
...controls[name],
|
...controls[name],
|
||||||
// if `mapStateToProps` accept three arguments, it means it needs chart
|
...(shouldRecalculateControlState({ name, config })
|
||||||
// state, too. Since it's may be expensive to run mapStateToProps for every
|
? config?.mapStateToProps?.(exploreState, controls[name], chart)
|
||||||
// re-render, we only run this when the chart plugin explicitly ask for this.
|
|
||||||
...(config.mapStateToProps?.length === 3
|
|
||||||
? config.mapStateToProps(exploreState, controls[name], chart)
|
|
||||||
: // for other controls, `mapStateToProps` is already run in
|
: // for other controls, `mapStateToProps` is already run in
|
||||||
// controlUtils/getControlState.ts
|
// controlUtils/getControlState.ts
|
||||||
undefined),
|
undefined),
|
||||||
|
Loading…
Reference in New Issue
Block a user