Skip to content

Commit

Permalink
fix(dashboard): Page crashing when cross filter applied on adhoc colu…
Browse files Browse the repository at this point in the history
…mn (#23215)
  • Loading branch information
kgabryje authored Feb 27, 2023
1 parent dcd3e00 commit ad5ee1c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ import userEvent from '@testing-library/user-event';
import React from 'react';
import { render, screen } from 'spec/helpers/testing-library';
import { FilterBarOrientation } from 'src/dashboard/types';
import { IndicatorStatus } from '../../selectors';
import { CrossFilterIndicator, IndicatorStatus } from '../../selectors';
import CrossFilterTag from './CrossFilterTag';

const mockedProps = {
const mockedProps: {
filter: CrossFilterIndicator;
orientation: FilterBarOrientation;
removeCrossFilter: (filterId: number) => void;
} = {
filter: {
name: 'test',
emitterId: 1,
Expand All @@ -46,6 +50,25 @@ test('CrossFilterTag should render', () => {
expect(container).toBeInTheDocument();
});

test('CrossFilterTag with adhoc column should render', () => {
const props = {
...mockedProps,
filter: {
...mockedProps.filter,
column: {
label: 'My column',
sqlExpression: 'country_name',
expressionType: 'SQL' as const,
},
},
};

const { container } = setup(props);
expect(container).toBeInTheDocument();
expect(screen.getByText('My column')).toBeInTheDocument();
expect(screen.getByText('Italy')).toBeInTheDocument();
});

test('Column and value should be visible', () => {
setup(mockedProps);
expect(screen.getByText('country_name')).toBeInTheDocument();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import React from 'react';
import { styled, css, useTheme } from '@superset-ui/core';
import { styled, css, useTheme, getColumnLabel } from '@superset-ui/core';
import { CrossFilterIndicator } from 'src/dashboard/components/nativeFilters/selectors';
import { Tag } from 'src/components';
import { Tooltip } from 'src/components/Tooltip';
Expand Down Expand Up @@ -62,6 +62,7 @@ const CrossFilterTag = (props: {
useCSSTextTruncation<HTMLSpanElement>();
const [valueRef, valueIsTruncated] = useCSSTextTruncation<HTMLSpanElement>();

const columnLabel = getColumnLabel(filter.column ?? '');
return (
<StyledTag
css={css`
Expand All @@ -76,9 +77,9 @@ const CrossFilterTag = (props: {
closable
onClose={() => removeCrossFilter(filter.emitterId)}
>
<Tooltip title={columnIsTruncated ? filter.column : null}>
<Tooltip title={columnIsTruncated ? columnLabel : null}>
<StyledCrossFilterColumn ref={columnRef}>
{filter.column}
{columnLabel}
</StyledCrossFilterColumn>
</Tooltip>
<Tooltip title={valueIsTruncated ? filter.value : null}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
isFeatureEnabled,
NativeFilterType,
NO_TIME_RANGE,
QueryFormColumn,
} from '@superset-ui/core';
import { TIME_FILTER_MAP } from 'src/explore/constants';
import { getChartIdsInFilterBoxScope } from 'src/dashboard/util/activeDashboardFilters';
Expand Down Expand Up @@ -151,7 +152,7 @@ const getRejectedColumns = (chart: any): Set<string> =>
);

export type Indicator = {
column?: string;
column?: QueryFormColumn;
name: string;
value?: any;
status?: IndicatorStatus;
Expand Down

0 comments on commit ad5ee1c

Please sign in to comment.