fix(explore): DndColumnSelect not handling controls with "multi: false" (#14737)

* fix(explore): DndColumnSelect not handling controls with multi={false}

* Implement translations for singular and plural cases

* Fix test
This commit is contained in:
Kamil Gabryjelski
2021-05-24 09:53:46 +02:00
committed by GitHub
parent 6d33432b58
commit d03c608ce1
4 changed files with 17 additions and 3 deletions

View File

@@ -17,6 +17,7 @@
* under the License.
*/
import React, { useState } from 'react';
import { tn } from '@superset-ui/core';
import { ColumnMeta } from '@superset-ui/chart-controls';
import { isEmpty } from 'lodash';
import { LabelProps } from 'src/explore/components/controls/DndColumnSelectControl/types';
@@ -28,7 +29,7 @@ import { DndItemType } from 'src/explore/components/DndItemType';
import { StyledColumnOption } from 'src/explore/components/optionRenderers';
export const DndColumnSelect = (props: LabelProps) => {
const { value, options } = props;
const { value, options, multi = true } = props;
const optionSelector = new OptionSelector(options, value);
const [values, setValues] = useState<ColumnMeta[]>(optionSelector.values);
@@ -44,6 +45,7 @@ export const DndColumnSelect = (props: LabelProps) => {
};
const canDrop = (item: DatasourcePanelDndItem) =>
(multi || optionSelector.values.length === 0) &&
!optionSelector.has((item.value as ColumnMeta).column_name);
const onClickClose = (index: number) => {
@@ -77,6 +79,8 @@ export const DndColumnSelect = (props: LabelProps) => {
canDrop={canDrop}
valuesRenderer={valuesRenderer}
accept={DndItemType.Column}
displayGhostButton={multi || optionSelector.values.length === 0}
ghostButtonText={tn('Drop column', 'Drop columns', multi ? 2 : 1)}
{...props}
/>
);