mirror of
https://github.com/apache/superset.git
synced 2024-09-16 02:29:39 -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 { t, validateNonEmpty } from '@superset-ui/core';
|
||||
import {
|
||||
formatSelectOptionsForRange,
|
||||
ColumnOption,
|
||||
columnChoices,
|
||||
ColumnOption,
|
||||
ColumnMeta,
|
||||
ControlPanelConfig,
|
||||
ControlState,
|
||||
formatSelectOptionsForRange,
|
||||
sections,
|
||||
SelectControlConfig,
|
||||
ColumnMeta,
|
||||
} from '@superset-ui/chart-controls';
|
||||
|
||||
const config: ControlPanelConfig = {
|
||||
@ -46,10 +47,8 @@ const config: ControlPanelConfig = {
|
||||
choices: columnChoices(state?.datasource),
|
||||
}),
|
||||
// choices is from `mapStateToProps`
|
||||
default: (control: { choices?: string[] }) =>
|
||||
control.choices && control.choices.length > 0
|
||||
? control.choices[0][0]
|
||||
: null,
|
||||
default: (control: ControlState) =>
|
||||
control.choices?.[0]?.[0] || null,
|
||||
validators: [validateNonEmpty],
|
||||
},
|
||||
},
|
||||
|
@ -17,11 +17,18 @@
|
||||
* under the License.
|
||||
*/
|
||||
import React from 'react';
|
||||
import { t, validateNonEmpty } from '@superset-ui/core';
|
||||
import {
|
||||
FeatureFlag,
|
||||
isFeatureEnabled,
|
||||
t,
|
||||
validateNonEmpty,
|
||||
} from '@superset-ui/core';
|
||||
import {
|
||||
ControlPanelsContainerProps,
|
||||
ControlPanelState,
|
||||
ControlSetItem,
|
||||
ControlSetRow,
|
||||
ControlState,
|
||||
sharedControls,
|
||||
} from '@superset-ui/chart-controls';
|
||||
import { DEFAULT_LEGEND_FORM_DATA } from './types';
|
||||
@ -143,7 +150,22 @@ export const xAxisControl: ControlSetItem = {
|
||||
config: {
|
||||
...sharedControls.groupby,
|
||||
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,
|
||||
description: t('Dimension to use on x-axis.'),
|
||||
validators: [validateNonEmpty],
|
||||
|
@ -85,7 +85,7 @@ function handleMissingChoice<T = ControlType>(control: ControlState<T>) {
|
||||
|
||||
export function applyMapStateToPropsToControl<T = ControlType>(
|
||||
controlState: ControlState<T>,
|
||||
controlPanelState: Partial<ControlPanelState>,
|
||||
controlPanelState: Partial<ControlPanelState> | null,
|
||||
) {
|
||||
const { mapStateToProps } = controlState;
|
||||
let state = { ...controlState };
|
||||
@ -120,7 +120,7 @@ export function applyMapStateToPropsToControl<T = ControlType>(
|
||||
|
||||
export function getControlStateFromControlConfig<T = ControlType>(
|
||||
controlConfig: ControlConfig<T> | null,
|
||||
controlPanelState: Partial<ControlPanelState>,
|
||||
controlPanelState: Partial<ControlPanelState> | null,
|
||||
value?: JsonValue,
|
||||
) {
|
||||
// skip invalid config values
|
||||
@ -130,10 +130,7 @@ export function getControlStateFromControlConfig<T = ControlType>(
|
||||
const controlState = { ...controlConfig, value } as ControlState<T>;
|
||||
// only apply mapStateToProps when control states have been initialized
|
||||
// or when explicitly didn't provide control panel state (mostly for testing)
|
||||
if (
|
||||
(controlPanelState && controlPanelState.controls) ||
|
||||
controlPanelState === null
|
||||
) {
|
||||
if (controlPanelState?.controls || controlPanelState === null) {
|
||||
return applyMapStateToPropsToControl(controlState, controlPanelState);
|
||||
}
|
||||
return controlState;
|
||||
@ -155,7 +152,7 @@ export function getControlState(
|
||||
export function getAllControlsState(
|
||||
vizType: string,
|
||||
datasourceType: DatasourceType,
|
||||
state: ControlPanelState,
|
||||
state: ControlPanelState | null,
|
||||
formData: QueryFormData,
|
||||
) {
|
||||
const controlsState = {};
|
||||
|
@ -64,9 +64,12 @@ export function getControlsState(state, inputFormData) {
|
||||
export function applyDefaultFormData(inputFormData) {
|
||||
const datasourceType = inputFormData.datasource.split('__')[1];
|
||||
const vizType = inputFormData.viz_type;
|
||||
const controlsState = getAllControlsState(vizType, datasourceType, null, {
|
||||
...inputFormData,
|
||||
});
|
||||
const controlsState = getAllControlsState(
|
||||
vizType,
|
||||
datasourceType,
|
||||
null,
|
||||
inputFormData,
|
||||
);
|
||||
const controlFormData = getFormDataFromControls(controlsState);
|
||||
|
||||
const formData = {};
|
||||
|
Loading…
Reference in New Issue
Block a user