Skip to content

Commit

Permalink
chore(dashboard): Resolve form_data vs. formData in dashboard redux s…
Browse files Browse the repository at this point in the history
…tate
  • Loading branch information
codyml authored Jun 30, 2022
1 parent 932e304 commit edb1383
Show file tree
Hide file tree
Showing 12 changed files with 13 additions and 32 deletions.
17 changes: 0 additions & 17 deletions superset-frontend/spec/fixtures/mockChartQueries.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,6 @@ export default {
triggerQuery: false,
lastRendered: 0,
form_data: {
slice_id: sliceId,
viz_type: 'pie',
row_limit: 50000,
metric: 'sum__num',
since: '100 years ago',
groupby: ['gender'],
metrics: ['sum__num'],
compare_lag: '10',
limit: '25',
until: 'now',
granularity: 'ds',
markup_type: 'markdown',
where: '',
compare_suffix: 'o10Y',
datasource: datasourceId,
},
formData: {
datasource: datasourceId,
viz_type: 'pie',
slice_id: sliceId,
Expand Down
3 changes: 1 addition & 2 deletions superset-frontend/src/dashboard/actions/dashboardState.js
Original file line number Diff line number Diff line change
Expand Up @@ -489,8 +489,7 @@ export function addSliceToDashboard(id, component) {
const newChart = {
...initChart,
id,
form_data,
formData: applyDefaultFormData(form_data),
form_data: applyDefaultFormData(form_data),
};

return Promise.all([
Expand Down
5 changes: 2 additions & 3 deletions superset-frontend/src/dashboard/actions/hydrate.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ export const hydrateDashboard =
chartQueries[key] = {
...chart,
id: key,
form_data,
formData: applyDefaultFormData(form_data),
form_data: applyDefaultFormData(form_data),
};

slices[key] = {
Expand Down Expand Up @@ -316,7 +315,7 @@ export const hydrateDashboard =
const behaviors =
(
getChartMetadataRegistry().get(
chartQueries[chartId]?.formData?.viz_type,
chartQueries[chartId]?.form_data?.viz_type,
) ?? {}
)?.behaviors ?? [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('Chart', () => {
// from redux
maxRows: 666,
chart: chartQueries[queryId],
formData: chartQueries[queryId].formData,
formData: chartQueries[queryId].form_data,
datasource: mockDatasource[sliceEntities.slices[queryId].datasource],
slice: {
...sliceEntities.slices[queryId],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export const useInitialization = () => {
// do not load filter_box in reviewing
if (filterboxMigrationState === FILTER_BOX_MIGRATION_STATES.REVIEWING) {
charts = keyBy(
filter(charts, chart => chart.formData?.viz_type !== 'filter_box'),
filter(charts, chart => chart.form_data?.viz_type !== 'filter_box'),
'id',
);
const numberOfFilterbox = document.querySelectorAll(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { BuildTreeLeafTitle, TreeItem } from './types';

export const isShowTypeInTree = ({ type, meta }: LayoutItem, charts?: Charts) =>
(type === TAB_TYPE || type === CHART_TYPE || type === DASHBOARD_ROOT_TYPE) &&
(!charts || charts[meta?.chartId]?.formData?.viz_type !== 'filter_box');
(!charts || charts[meta?.chartId]?.form_data?.viz_type !== 'filter_box');

export const buildTree = (
node: LayoutItem,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ const FiltersConfigForm = (
}

Object.values(charts).forEach((chart: Chart) => {
const chartDatasetUid = chart.formData?.datasource;
const chartDatasetUid = chart.form_data?.datasource;
if (chartDatasetUid === undefined) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export const mostUsedDataset = (
let maxCount = 0;

Object.values(charts).forEach(chart => {
const { formData } = chart;
const { form_data: formData } = chart;
if (formData) {
const { datasource } = formData;
const count = (map.get(datasource) || 0) + 1;
Expand Down
3 changes: 1 addition & 2 deletions superset-frontend/src/dashboard/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,13 @@ export type ChartReducerInitialState = typeof chart;
// Ref: https://github.com/apache/superset/blob/dcac860f3e5528ecbc39e58f045c7388adb5c3d0/superset-frontend/src/dashboard/reducers/getInitialState.js#L120
export interface ChartQueryPayload extends Partial<ChartReducerInitialState> {
id: number;
formData: ChartProps['formData'];
form_data?: ChartProps['rawFormData'];
[key: string]: unknown;
}

/** Chart state of redux */
export type Chart = ChartState & {
formData: {
form_data: {
viz_type: string;
datasource: string;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export default function getFormDataWithExtraFilters({
}

const formData = {
...chart.formData,
...chart.form_data,
label_colors: labelColors,
shared_label_colors: sharedLabelColors,
...(colorScheme && { color_scheme: colorScheme }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('getFormDataWithExtraFilters', () => {
queryController: null,
queriesResponse: null,
triggerQuery: false,
formData: {
form_data: {
viz_type: 'filter_select',
filters: [
{
Expand All @@ -45,6 +45,7 @@ describe('getFormDataWithExtraFilters', () => {
},
],
datasource: '123',
url_params: {},
},
};
const mockArgs: GetFormDataWithExtraFiltersArguments = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function childChartsDidLoad({ chartQueries, layout, id }) {
const query = chartQueries[chartId] || {};

// filterbox's don't re-render, don't use stale update time
if (query.formData && query.formData.viz_type !== 'filter_box') {
if (query.form_data && query.form_data.viz_type !== 'filter_box') {
minQueryStartTime = Math.min(
query.chartUpdateStartTime,
minQueryStartTime,
Expand Down

0 comments on commit edb1383

Please sign in to comment.