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: Add controlGroups to formData #9740

Merged
merged 1 commit into from May 6, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions superset-frontend/spec/javascripts/explore/controlUtils_spec.jsx
Expand Up @@ -23,7 +23,9 @@ import { t } from '@superset-ui/translation';
import {
getControlConfig,
getControlState,
getFormDataFromControls,
applyMapStateToPropsToControl,
getAllControlsState,
} from '../../../src/explore/controlUtils';
import ColumnOption from '../../../src/components/ColumnOption';

Expand Down Expand Up @@ -107,6 +109,7 @@ describe('controlUtils', () => {
name: 'all_columns',
config: {
type: 'SelectControl',
controlGroup: 'columns',
Copy link
Member Author

Choose a reason for hiding this comment

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

Naming suggestions are welcomed. I went between requestGroup and controlGroup, bud decided in favor of controlGroup, as I expect it will be more intuitive for viz developers.

multi: true,
label: t('Columns'),
default: [],
Expand Down Expand Up @@ -246,4 +249,12 @@ describe('controlUtils', () => {
expect(control.validationErrors).toEqual(['cannot be empty']);
});
});

describe('controlGroup', () => {
it('in formData', () => {
const controlsState = getAllControlsState('table', 'table', {}, {});
const formData = getFormDataFromControls(controlsState);
expect(formData.controlGroups).toEqual({ all_columns: 'columns' });
});
});
});
7 changes: 6 additions & 1 deletion superset-frontend/src/explore/controlUtils.js
Expand Up @@ -22,8 +22,13 @@ import * as SECTIONS from './controlPanels/sections';

export function getFormDataFromControls(controlsState) {
const formData = {};
formData.controlGroups = {};
Object.keys(controlsState).forEach(controlName => {
formData[controlName] = controlsState[controlName].value;
const control = controlsState[controlName];
formData[controlName] = control.value;
if (control.hasOwnProperty('controlGroup')) {
formData.controlGroups[controlName] = control.controlGroup;
}
});
return formData;
}
Expand Down
2 changes: 2 additions & 0 deletions superset-frontend/src/explore/controls.jsx
Expand Up @@ -125,6 +125,7 @@ const timeColumnOption = {

const groupByControl = {
type: 'SelectControl',
controlGroup: 'groupby',
multi: true,
freeForm: true,
label: t('Group by'),
Expand Down Expand Up @@ -156,6 +157,7 @@ const groupByControl = {

const metrics = {
type: 'MetricsControl',
controlGroup: 'metrics',
multi: true,
label: t('Metrics'),
validators: [validateNonEmpty],
Expand Down