mirror of
https://github.com/apache/superset.git
synced 2024-09-18 19:49:37 -04:00
fix(generic-chart-axes): set x-axis if unset and ff is enabled (#20107)
* fix(generic-chart-axes): set x-axis if unset and ff is enabled * simplify * simplify * continue cleanup * yet more cleanup
This commit is contained in:
parent
660af409a4
commit
0b3d3dd4ca
@ -19,13 +19,14 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { t, validateNonEmpty } from '@superset-ui/core';
|
import { t, validateNonEmpty } from '@superset-ui/core';
|
||||||
import {
|
import {
|
||||||
formatSelectOptionsForRange,
|
|
||||||
ColumnOption,
|
|
||||||
columnChoices,
|
columnChoices,
|
||||||
|
ColumnOption,
|
||||||
|
ColumnMeta,
|
||||||
ControlPanelConfig,
|
ControlPanelConfig,
|
||||||
|
ControlState,
|
||||||
|
formatSelectOptionsForRange,
|
||||||
sections,
|
sections,
|
||||||
SelectControlConfig,
|
SelectControlConfig,
|
||||||
ColumnMeta,
|
|
||||||
} from '@superset-ui/chart-controls';
|
} from '@superset-ui/chart-controls';
|
||||||
|
|
||||||
const config: ControlPanelConfig = {
|
const config: ControlPanelConfig = {
|
||||||
@ -46,10 +47,8 @@ const config: ControlPanelConfig = {
|
|||||||
choices: columnChoices(state?.datasource),
|
choices: columnChoices(state?.datasource),
|
||||||
}),
|
}),
|
||||||
// choices is from `mapStateToProps`
|
// choices is from `mapStateToProps`
|
||||||
default: (control: { choices?: string[] }) =>
|
default: (control: ControlState) =>
|
||||||
control.choices && control.choices.length > 0
|
control.choices?.[0]?.[0] || null,
|
||||||
? control.choices[0][0]
|
|
||||||
: null,
|
|
||||||
validators: [validateNonEmpty],
|
validators: [validateNonEmpty],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -17,11 +17,18 @@
|
|||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { t, validateNonEmpty } from '@superset-ui/core';
|
import {
|
||||||
|
FeatureFlag,
|
||||||
|
isFeatureEnabled,
|
||||||
|
t,
|
||||||
|
validateNonEmpty,
|
||||||
|
} from '@superset-ui/core';
|
||||||
import {
|
import {
|
||||||
ControlPanelsContainerProps,
|
ControlPanelsContainerProps,
|
||||||
|
ControlPanelState,
|
||||||
ControlSetItem,
|
ControlSetItem,
|
||||||
ControlSetRow,
|
ControlSetRow,
|
||||||
|
ControlState,
|
||||||
sharedControls,
|
sharedControls,
|
||||||
} from '@superset-ui/chart-controls';
|
} from '@superset-ui/chart-controls';
|
||||||
import { DEFAULT_LEGEND_FORM_DATA } from './types';
|
import { DEFAULT_LEGEND_FORM_DATA } from './types';
|
||||||
@ -143,7 +150,22 @@ export const xAxisControl: ControlSetItem = {
|
|||||||
config: {
|
config: {
|
||||||
...sharedControls.groupby,
|
...sharedControls.groupby,
|
||||||
label: t('X-axis'),
|
label: t('X-axis'),
|
||||||
default: null,
|
default: (
|
||||||
|
control: ControlState,
|
||||||
|
controlPanel: Partial<ControlPanelState>,
|
||||||
|
) => {
|
||||||
|
// default to the chosen time column if x-axis is unset and the
|
||||||
|
// GENERIC_CHART_AXES feature flag is enabled
|
||||||
|
const { value } = control;
|
||||||
|
if (value) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
const timeColumn = controlPanel?.form_data?.granularity_sqla;
|
||||||
|
if (isFeatureEnabled(FeatureFlag.GENERIC_CHART_AXES) && timeColumn) {
|
||||||
|
return timeColumn;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
},
|
||||||
multi: false,
|
multi: false,
|
||||||
description: t('Dimension to use on x-axis.'),
|
description: t('Dimension to use on x-axis.'),
|
||||||
validators: [validateNonEmpty],
|
validators: [validateNonEmpty],
|
||||||
|
@ -85,7 +85,7 @@ function handleMissingChoice<T = ControlType>(control: ControlState<T>) {
|
|||||||
|
|
||||||
export function applyMapStateToPropsToControl<T = ControlType>(
|
export function applyMapStateToPropsToControl<T = ControlType>(
|
||||||
controlState: ControlState<T>,
|
controlState: ControlState<T>,
|
||||||
controlPanelState: Partial<ControlPanelState>,
|
controlPanelState: Partial<ControlPanelState> | null,
|
||||||
) {
|
) {
|
||||||
const { mapStateToProps } = controlState;
|
const { mapStateToProps } = controlState;
|
||||||
let state = { ...controlState };
|
let state = { ...controlState };
|
||||||
@ -120,7 +120,7 @@ export function applyMapStateToPropsToControl<T = ControlType>(
|
|||||||
|
|
||||||
export function getControlStateFromControlConfig<T = ControlType>(
|
export function getControlStateFromControlConfig<T = ControlType>(
|
||||||
controlConfig: ControlConfig<T> | null,
|
controlConfig: ControlConfig<T> | null,
|
||||||
controlPanelState: Partial<ControlPanelState>,
|
controlPanelState: Partial<ControlPanelState> | null,
|
||||||
value?: JsonValue,
|
value?: JsonValue,
|
||||||
) {
|
) {
|
||||||
// skip invalid config values
|
// skip invalid config values
|
||||||
@ -130,10 +130,7 @@ export function getControlStateFromControlConfig<T = ControlType>(
|
|||||||
const controlState = { ...controlConfig, value } as ControlState<T>;
|
const controlState = { ...controlConfig, value } as ControlState<T>;
|
||||||
// only apply mapStateToProps when control states have been initialized
|
// only apply mapStateToProps when control states have been initialized
|
||||||
// or when explicitly didn't provide control panel state (mostly for testing)
|
// or when explicitly didn't provide control panel state (mostly for testing)
|
||||||
if (
|
if (controlPanelState?.controls || controlPanelState === null) {
|
||||||
(controlPanelState && controlPanelState.controls) ||
|
|
||||||
controlPanelState === null
|
|
||||||
) {
|
|
||||||
return applyMapStateToPropsToControl(controlState, controlPanelState);
|
return applyMapStateToPropsToControl(controlState, controlPanelState);
|
||||||
}
|
}
|
||||||
return controlState;
|
return controlState;
|
||||||
@ -155,7 +152,7 @@ export function getControlState(
|
|||||||
export function getAllControlsState(
|
export function getAllControlsState(
|
||||||
vizType: string,
|
vizType: string,
|
||||||
datasourceType: DatasourceType,
|
datasourceType: DatasourceType,
|
||||||
state: ControlPanelState,
|
state: ControlPanelState | null,
|
||||||
formData: QueryFormData,
|
formData: QueryFormData,
|
||||||
) {
|
) {
|
||||||
const controlsState = {};
|
const controlsState = {};
|
||||||
|
@ -64,9 +64,12 @@ export function getControlsState(state, inputFormData) {
|
|||||||
export function applyDefaultFormData(inputFormData) {
|
export function applyDefaultFormData(inputFormData) {
|
||||||
const datasourceType = inputFormData.datasource.split('__')[1];
|
const datasourceType = inputFormData.datasource.split('__')[1];
|
||||||
const vizType = inputFormData.viz_type;
|
const vizType = inputFormData.viz_type;
|
||||||
const controlsState = getAllControlsState(vizType, datasourceType, null, {
|
const controlsState = getAllControlsState(
|
||||||
...inputFormData,
|
vizType,
|
||||||
});
|
datasourceType,
|
||||||
|
null,
|
||||||
|
inputFormData,
|
||||||
|
);
|
||||||
const controlFormData = getFormDataFromControls(controlsState);
|
const controlFormData = getFormDataFromControls(controlsState);
|
||||||
|
|
||||||
const formData = {};
|
const formData = {};
|
||||||
|
Loading…
Reference in New Issue
Block a user