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

feat: standardized form_data #20010

Merged
merged 27 commits into from
Jun 5, 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
17 changes: 17 additions & 0 deletions superset-frontend/packages/superset-ui-chart-controls/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import type {
JsonValue,
Metric,
QueryFormData,
QueryFormMetric,
QueryFormColumn,
} from '@superset-ui/core';
import { sharedControls } from './shared-controls';
import sharedControlComponents from './shared-controls/components';
Expand Down Expand Up @@ -340,11 +342,26 @@ export interface ControlPanelSectionConfig {
controlSetRows: ControlSetRow[];
}

export interface StandardizedState {
metrics: QueryFormMetric[];
columns: QueryFormColumn[];
}

export interface StandardizedFormDataInterface {
zhaoyongjie marked this conversation as resolved.
Show resolved Hide resolved
standardizedState: StandardizedState;
memorizedFormData: Map<string, QueryFormData>;
}

export interface ControlPanelConfig {
controlPanelSections: (ControlPanelSectionConfig | null)[];
controlOverrides?: ControlOverrides;
sectionOverrides?: SectionOverrides;
onInit?: (state: ControlStateMapping) => void;
denormalizeFormData?: (
formData: QueryFormData & {
standardizedFormData: StandardizedFormDataInterface;
},
) => QueryFormData;
}

export type ControlOverrides = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,8 @@ export default {
label: t('Number format'),
},
},
denormalizeFormData: formData => ({
...formData,
metric: formData.standardizedFormData.standardizedState.metrics[0],
}),
} as ControlPanelConfig;
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,10 @@ const config: ControlPanelConfig = {
label: t('Number format'),
},
},
denormalizeFormData: formData => ({
...formData,
metric: formData.standardizedFormData.standardizedState.metrics[0],
}),
};

export default config;
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,11 @@ const config: ControlPanelConfig = {
default: 100,
},
},
denormalizeFormData: formData => ({
...formData,
metric: formData.standardizedFormData.standardizedState.metrics[0],
groupby: formData.standardizedFormData.standardizedState.columns,
}),
};

export default config;
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,10 @@ const config: ControlPanelConfig = {
default: rowLimit,
},
},
denormalizeFormData: formData => ({
...formData,
metrics: formData.standardizedFormData.standardizedState.metrics,
}),
};

export default config;
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
import React from 'react';
import {
ensureIsArray,
QueryFormMetric,
smartDateFormatter,
t,
Expand Down Expand Up @@ -367,6 +368,17 @@ const config: ControlPanelConfig = {
],
},
],
denormalizeFormData: formData => {
const groupbyColumns =
formData.standardizedFormData.standardizedState.columns.filter(
col => !ensureIsArray(formData.groupbyRows).includes(col),
);
return {
...formData,
metrics: formData.standardizedFormData.standardizedState.metrics,
groupbyColumns,
};
},
};

export default config;
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,11 @@ const config: ControlPanelConfig = {
],
},
],
denormalizeFormData: formData => ({
...formData,
metrics: formData.standardizedFormData.standardizedState.metrics,
groupby: formData.standardizedFormData.standardizedState.columns,
}),
};

export default config;
1 change: 1 addition & 0 deletions superset-frontend/src/explore/controlUtils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ export * from './getControlConfig';
export * from './getControlState';
export * from './getFormDataFromControls';
export * from './getControlValuesCompatibleWithDatasource';
export * from './standardizedFormData';
Loading