Skip to content

Commit

Permalink
feat: Add controlGroups to formData (#9740)
Browse files Browse the repository at this point in the history
  • Loading branch information
villebro authored May 6, 2020
1 parent 453806f commit 5485eb9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
11 changes: 11 additions & 0 deletions superset-frontend/spec/javascripts/explore/controlUtils_spec.jsx
Original file line number Diff line number Diff line change
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',
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 5485eb9

Please sign in to comment.