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(explore): Denormalize form data in echarts, world map and nvd3 bar and line charts #20313

Merged
merged 3 commits into from
Jun 9, 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
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ const config: ControlPanelConfig = {
Boolean(controls?.color_by.value === ColorBy.country),
},
},
denormalizeFormData: formData => ({
...formData,
metrics: formData.standardizedFormData.standardizedState.metrics,
}),
};

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

export default config;
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ const config: ControlPanelConfig = {
],
controlOverrides: {
groupby: {
label: t('Dimensions'),
validators: [validateNonEmpty],
mapStateToProps: (state, controlState) => {
const groupbyProps =
Expand Down Expand Up @@ -134,6 +133,17 @@ const config: ControlPanelConfig = {
rerender: ['groupby'],
},
},
denormalizeFormData: formData => {
const columns =
formData.standardizedFormData.standardizedState.columns.filter(
col => !ensureIsArray(formData.groupby).includes(col),
);
return {
...formData,
metrics: formData.standardizedFormData.standardizedState.metrics,
columns,
};
},
};

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

export default config;
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import { t } from '@superset-ui/core';
import { ensureIsArray, t } from '@superset-ui/core';
import {
D3_FORMAT_DOCS,
D3_FORMAT_OPTIONS,
Expand Down Expand Up @@ -136,5 +136,16 @@ const config: ControlPanelConfig = {
),
},
},
denormalizeFormData: formData => {
const groupby =
formData.standardizedFormData.standardizedState.columns.filter(
col => !ensureIsArray(formData.columns).includes(col),
);
return {
...formData,
metrics: formData.standardizedFormData.standardizedState.metrics,
groupby,
};
},
};
export default config;
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ const config: ControlPanelConfig = {
},
};
},
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 @@ -39,7 +39,6 @@ const config: ControlPanelConfig = {
name: 'groupby',
config: {
...sharedControls.groupby,
label: t('Dimensions'),
description: t('Columns to group by'),
},
},
Expand Down Expand Up @@ -309,6 +308,11 @@ const config: ControlPanelConfig = {
],
},
],
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 @@ -320,6 +320,10 @@ const controlPanel: ControlPanelConfig = {
],
},
],
denormalizeFormData: formData => ({
...formData,
metric: formData.standardizedFormData.standardizedState.metrics[0],
}),
};

export default controlPanel;
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@
* under the License.
*/
import React from 'react';
import { FeatureFlag, isFeatureEnabled, t } from '@superset-ui/core';
import {
ensureIsArray,
FeatureFlag,
isFeatureEnabled,
t,
} from '@superset-ui/core';
import { cloneDeep } from 'lodash';
import {
ControlPanelConfig,
Expand Down Expand Up @@ -452,6 +457,21 @@ const config: ControlPanelConfig = {
],
},
],
denormalizeFormData: formData => {
const groupby =
formData.standardizedFormData.standardizedState.columns.filter(
col => !ensureIsArray(formData.groupby_b).includes(col),
);
const metrics =
formData.standardizedFormData.standardizedState.metrics.filter(
metric => !ensureIsArray(formData.metrics_b).includes(metric),
);
return {
...formData,
metrics,
groupby,
};
},
};

export default config;
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ const config: ControlPanelConfig = {
],
},
],
denormalizeFormData: formData => ({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the denormalizeFormData is consistent for most charts, so maybe we can abstract out a generic function?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Different viz have different control names, for example, the BigNumber supported 1 metric and 0 dimension, the metrics in SFD should pick only one, and drop other columns.

...formData,
metrics: formData.standardizedFormData.standardizedState.metrics,
groupby: formData.standardizedFormData.standardizedState.columns,
}),
};

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

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

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

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

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

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

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

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

export default config;