feat: Add controlGroups to formData (#9740)
This commit is contained in:
parent
453806fc4c
commit
5485eb993c
|
|
@ -23,7 +23,9 @@ import { t } from '@superset-ui/translation';
|
||||||
import {
|
import {
|
||||||
getControlConfig,
|
getControlConfig,
|
||||||
getControlState,
|
getControlState,
|
||||||
|
getFormDataFromControls,
|
||||||
applyMapStateToPropsToControl,
|
applyMapStateToPropsToControl,
|
||||||
|
getAllControlsState,
|
||||||
} from '../../../src/explore/controlUtils';
|
} from '../../../src/explore/controlUtils';
|
||||||
import ColumnOption from '../../../src/components/ColumnOption';
|
import ColumnOption from '../../../src/components/ColumnOption';
|
||||||
|
|
||||||
|
|
@ -107,6 +109,7 @@ describe('controlUtils', () => {
|
||||||
name: 'all_columns',
|
name: 'all_columns',
|
||||||
config: {
|
config: {
|
||||||
type: 'SelectControl',
|
type: 'SelectControl',
|
||||||
|
controlGroup: 'columns',
|
||||||
multi: true,
|
multi: true,
|
||||||
label: t('Columns'),
|
label: t('Columns'),
|
||||||
default: [],
|
default: [],
|
||||||
|
|
@ -246,4 +249,12 @@ describe('controlUtils', () => {
|
||||||
expect(control.validationErrors).toEqual(['cannot be empty']);
|
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' });
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -22,8 +22,13 @@ import * as SECTIONS from './controlPanels/sections';
|
||||||
|
|
||||||
export function getFormDataFromControls(controlsState) {
|
export function getFormDataFromControls(controlsState) {
|
||||||
const formData = {};
|
const formData = {};
|
||||||
|
formData.controlGroups = {};
|
||||||
Object.keys(controlsState).forEach(controlName => {
|
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;
|
return formData;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -125,6 +125,7 @@ const timeColumnOption = {
|
||||||
|
|
||||||
const groupByControl = {
|
const groupByControl = {
|
||||||
type: 'SelectControl',
|
type: 'SelectControl',
|
||||||
|
controlGroup: 'groupby',
|
||||||
multi: true,
|
multi: true,
|
||||||
freeForm: true,
|
freeForm: true,
|
||||||
label: t('Group by'),
|
label: t('Group by'),
|
||||||
|
|
@ -156,6 +157,7 @@ const groupByControl = {
|
||||||
|
|
||||||
const metrics = {
|
const metrics = {
|
||||||
type: 'MetricsControl',
|
type: 'MetricsControl',
|
||||||
|
controlGroup: 'metrics',
|
||||||
multi: true,
|
multi: true,
|
||||||
label: t('Metrics'),
|
label: t('Metrics'),
|
||||||
validators: [validateNonEmpty],
|
validators: [validateNonEmpty],
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue