Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dashboard): Page crashing when cross filter applied on adhoc column #23215

Merged
merged 2 commits into from
Feb 27, 2023
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 @@ -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