Skip to content
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 @@ -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';
Expand All @@ -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);

Expand All @@ -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) => {
Expand Down Expand Up @@ -77,6 +79,8 @@ export const DndColumnSelect = (props: LabelProps) => {
canDrop={canDrop}
valuesRenderer={valuesRenderer}
accept={DndItemType.Column}
displayGhostButton={multi || optionSelector.values.length === 0}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Bycatch: could we add singular/plural support while we're at it? ghostButtonText={tn('Drop column', 'Drop columns', multi ? 2 : 1)}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks! I also changed it in DndMetricSelect
image

ghostButtonText={tn('Drop column', 'Drop columns', multi ? 2 : 1)}
{...props}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,10 @@ const defaultProps = {

test('renders with default props', () => {
render(<DndMetricSelect {...defaultProps} />, { useDnd: true });
expect(screen.getByText('Drop column or metric')).toBeInTheDocument();
});

test('renders with default props and multi = true', () => {
render(<DndMetricSelect {...defaultProps} multi />, { useDnd: true });
expect(screen.getByText('Drop columns or metrics')).toBeInTheDocument();
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import React, { useCallback, useEffect, useMemo, useState } from 'react';
import { ensureIsArray, Metric, t } from '@superset-ui/core';
import { ensureIsArray, Metric, tn } from '@superset-ui/core';
import { ColumnMeta } from '@superset-ui/chart-controls';
import { isEqual } from 'lodash';
import { usePrevious } from 'src/common/hooks/usePrevious';
Expand Down Expand Up @@ -268,7 +268,11 @@ export const DndMetricSelect = (props: any) => {
canDrop={canDrop}
valuesRenderer={valuesRenderer}
accept={[DndItemType.Column, DndItemType.Metric]}
ghostButtonText={t('Drop columns or metrics')}
ghostButtonText={tn(
'Drop column or metric',
'Drop columns or metrics',
multi ? 2 : 1,
)}
displayGhostButton={multi || value.length === 0}
{...props}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export interface LabelProps<T = string[] | string> {
value?: T;
onChange: (value?: T) => void;
options: { string: ColumnMeta };
multi?: boolean;
}

export interface DndColumnSelectProps<
Expand Down