Skip to content
Open
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
73 changes: 67 additions & 6 deletions datahub-web-react/src/app/searchV2/filters/FilterOption.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import { Checkbox, Pill } from '@components';
import { Checkbox, Pill, Tooltip } from '@components';
import { CaretUp } from '@phosphor-icons/react/dist/csr/CaretUp';
import React, { useState } from 'react';
import styled from 'styled-components';

import { generateColor } from '@app/entityV2/shared/components/styled/StyledTag';
import { SingleEntityIcon } from '@app/searchV2/autoCompleteV2/components/icon/SingleEntityIcon';
import ParentEntities from '@app/searchV2/filters/ParentEntities';
import {
DisambiguatingParent,
getContainerPathSegments,
getFullContainerPath,
} from '@app/searchV2/filters/containerDisambiguation';
import { Label } from '@app/searchV2/filters/styledComponents';
import { FilterOptionType } from '@app/searchV2/filters/types';
import {
Expand Down Expand Up @@ -89,13 +95,35 @@ const LabelWrapper = styled.div`
line-height: normal;
`;

// getContainerPathSegments keeps paths short; the overflow rules are only a backstop for wide glyphs.
const ContainerPath = styled.span`
display: block;
max-width: 240px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
`;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Full names clipped after keepWhole

Medium Severity

When keepWhole is set, the full parent name is rendered with no hidden text. ContainerPath then clips that string with overflow: hidden and an end ellipsis, so names that differ only in the middle can still look identical in the list.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit fe891b5. Configure here.


const ContainerOption = styled.div`
display: flex;
align-items: center;
gap: 8px;
min-width: 0;
`;

const ElidedSegment = styled.span`
cursor: help;
`;

interface Props {
filterOption: FilterOptionType;
selectedFilterOptions: FilterOptionType[];
setSelectedFilterOptions: (filterValues: FilterOptionType[]) => void;
nestedOptions?: FilterOptionType[];
addPadding?: boolean;
includeCount?: boolean;
// Parent containers (nearest first) to prefix to the label so it differs from same-named options.
containerParents?: DisambiguatingParent[];
}

export default function FilterOption({
Expand All @@ -105,10 +133,12 @@ export default function FilterOption({
nestedOptions,
addPadding,
includeCount = true,
containerParents,
}: Props) {
const [areChildrenVisible, setAreChildrenVisible] = useState(true);
const { field, value, count, entity } = filterOption;
const entityRegistry = useEntityRegistry();
const getEntityLabel = (e: Entity) => entityRegistry.getDisplayName(e.type, e);
const { label } = getFilterIconAndLabel(field, value, entityRegistry, entity || null, 14, filterOption.displayName);
const showParentEntityPath = field === DOMAINS_FILTER_NAME && entity?.type === EntityType.Domain;
const isSubTypeFilter = field === TYPE_NAMES_FILTER_NAME;
Expand All @@ -134,6 +164,12 @@ export default function FilterOption({
}
}

const defaultLabel = filterOption.entity ? (
<EntitySelectOption entity={filterOption.entity} />
) : (
<Label style={{ maxWidth: 150 }}>{isSubTypeFilter ? capitalizeFirstLetterOnly(label as string) : label}</Label>
);

return (
<>
<FilterOptionWrapper addPadding={addPadding} onClick={updateFilterValues}>
Expand All @@ -145,12 +181,37 @@ export default function FilterOption({
</ParentWrapper>
)}
<LabelCountWrapper>
{filterOption.entity ? (
<EntitySelectOption entity={filterOption.entity} />
{entity && containerParents?.length ? (
<ContainerOption>
<SingleEntityIcon entity={entity} size={16} />
<ContainerPath data-testid="filter-option-container-path">
{getContainerPathSegments(
getEntityLabel(entity),
containerParents,
getEntityLabel,
).map((segment, index) => {
const text = index ? `.${segment.text}` : segment.text;
return (
<Tooltip
key={segment.key}
title={
segment.hidden ?? getFullContainerPath(entity, getEntityLabel)
}
>
{segment.hidden ? (
<ElidedSegment data-testid="filter-option-container-path-elided">
{text}
</ElidedSegment>
) : (
<span>{text}</span>
)}
</Tooltip>
);
})}
</ContainerPath>
</ContainerOption>
) : (
<Label style={{ maxWidth: 150 }}>
{isSubTypeFilter ? capitalizeFirstLetterOnly(label as string) : label}
</Label>
defaultLabel

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Checkbox name ignores disambiguated path

Medium Severity

Disambiguated container rows draw a parent path, but the checkbox aria-label and data-testid still use the plain label from getFilterIconAndLabel. Same-named containers stay identical to assistive tech, and those test ids collide.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit fe891b5. Configure here.

)}
{nestedOptions && nestedOptions.length > 0 && (
<ArrowButton
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { MockedProvider } from '@apollo/client/testing';
import { render, screen } from '@testing-library/react';
import React from 'react';

import FilterOption from '@app/searchV2/filters/FilterOption';
import { TYPE_NAMES_FILTER_NAME } from '@app/searchV2/utils/constants';
import TestPageContainer from '@utils/test-utils/TestPageContainer';

describe('FilterOption', () => {
it('shows sub-type labels capitalized', () => {
render(
<MockedProvider mocks={[]} addTypename={false}>
<TestPageContainer>
<FilterOption
filterOption={{ field: TYPE_NAMES_FILTER_NAME, value: 'external table', count: 2 }}
selectedFilterOptions={[]}
setSelectedFilterOptions={vi.fn()}
/>
</TestPageContainer>
</MockedProvider>,
);

expect(screen.getByText(/^External table/)).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
import {
DisambiguatingParent,
formatContainerPath,
getContainerDisambiguationParents,
getContainerPathSegments,
getFullContainerPath,
} from '@app/searchV2/filters/containerDisambiguation';

import { Container, Entity, EntityType } from '@types';

const container = (urn: string, name: string, parents: Entity[] = []): Container =>
({
urn,
type: EntityType.Container,
properties: { name },
parentContainers: { count: parents.length, containers: parents },
}) as unknown as Container;

const getLabel = (entity: Entity) => (entity as Container).properties?.name || entity.urn;

const option = (entity: Entity) => ({ value: entity.urn, entity });

const names = (parents: DisambiguatingParent[] | undefined) => parents?.map((parent) => getLabel(parent.entity));

const lakehouseA = container('urn:li:container:lakehouse_a', 'lakehouse_a');
const lakehouseB = container('urn:li:container:lakehouse_b', 'lakehouse_b');
const petshopEast = container('urn:li:container:petshop_east', 'petshop_east', [lakehouseA]);
const petshopWest = container('urn:li:container:petshop_west', 'petshop_west', [lakehouseA]);
const centralA = container('urn:li:container:central_a', 'petshop_central', [lakehouseA]);
const centralB = container('urn:li:container:central_b', 'petshop_central', [lakehouseB]);

describe('getContainerDisambiguationParents', () => {
it('adds only the nearest parent when it tells same-named containers apart', () => {
const eastStore = container('urn:li:container:east_store', 'store', [petshopEast, lakehouseA]);
const westStore = container('urn:li:container:west_store', 'store', [petshopWest, lakehouseA]);

const result = getContainerDisambiguationParents([option(eastStore), option(westStore)], getLabel);

expect(names(result.get(eastStore.urn))).toEqual(['petshop_east']);
expect(names(result.get(westStore.urn))).toEqual(['petshop_west']);
});

it('adds as many levels as it takes when the nearest parents share a name too', () => {
const supplyA = container('urn:li:container:supply_a', 'supply', [centralA, lakehouseA]);
const supplyB = container('urn:li:container:supply_b', 'Supply ', [centralB, lakehouseB]);

const result = getContainerDisambiguationParents([option(supplyA), option(supplyB)], getLabel);

expect(names(result.get(supplyA.urn))).toEqual(['petshop_central', 'lakehouse_a']);
expect(names(result.get(supplyB.urn))).toEqual(['petshop_central', 'lakehouse_b']);
expect(result.get(supplyA.urn)?.map((parent) => parent.shared)).toEqual([true, false]);
});

it('leaves unique names and non-container options alone', () => {
const inventory = container('urn:li:container:inventory', 'inventory', [petshopEast]);
const tag = { urn: 'urn:li:tag:store', type: EntityType.Tag } as Entity;
const store = container('urn:li:container:east_store', 'store', [petshopEast]);

const result = getContainerDisambiguationParents(
[option(inventory), option(store), { value: tag.urn, entity: tag }, { value: 'no-entity' }],
getLabel,
);

expect(result.size).toBe(0);
});

it('shows the whole chain when no level tells the options apart', () => {
const storeOne = container('urn:li:container:store_1', 'store', [petshopEast, lakehouseA]);
const storeTwo = container('urn:li:container:store_2', 'store', [petshopEast, lakehouseA]);
const rootStore = container('urn:li:container:store_root', 'store');

const result = getContainerDisambiguationParents(
[option(storeOne), option(storeTwo), option(rootStore)],
getLabel,
);

expect(names(result.get(storeOne.urn))).toEqual(['petshop_east', 'lakehouse_a']);
expect(names(result.get(storeTwo.urn))).toEqual(['petshop_east', 'lakehouse_a']);
expect(result.has(rootStore.urn)).toBe(false);
});
});

describe('container paths', () => {
it('formats parents outermost first, ending with the label', () => {
expect(formatContainerPath('supply', [centralA, lakehouseA], getLabel)).toBe(
'lakehouse_a.petshop_central.supply',
);
});

it('builds the full path from all parent containers, or just the name without parents', () => {
const supply = container('urn:li:container:supply_a', 'supply', [centralA, lakehouseA]);

expect(getFullContainerPath(supply, getLabel)).toBe('lakehouse_a.petshop_central.supply');
expect(
getFullContainerPath({ urn: 'urn:li:container:bare', type: EntityType.Container } as Entity, getLabel),
).toBe('urn:li:container:bare');
});
});

describe('getContainerPathSegments', () => {
const chain = (...labels: string[]) => labels.map((label) => container(`urn:li:container:${label}`, label));
const parentsOf = (shared: string[], ...labels: string[]): DisambiguatingParent[] =>
chain(...labels).map((entity) => ({ entity, shared: shared.includes(getLabel(entity)), keepWhole: false }));
const text = (segments: { text: string }[]) => segments.map((segment) => segment.text).join('.');

it('shows a short path whole', () => {
expect(getContainerPathSegments('store', parentsOf([], 'petshop_east', 'lakehouse_a'), getLabel)).toEqual([
{ key: 'urn:li:container:lakehouse_a', text: 'lakehouse_a' },
{ key: 'urn:li:container:petshop_east', text: 'petshop_east' },
{ key: 'self', text: 'store' },
]);
});

it('collapses the levels the whole group shares in a long path', () => {
const middle = ['department', 'petshop_central', 'region', 'warehouse'];
const parents = parentsOf(middle, ...middle, 'lakehouse_alpha');

expect(getContainerPathSegments('supply', parents, getLabel)).toEqual([
{ key: 'urn:li:container:lakehouse_alpha', text: 'lakeho\u2026e_alpha', hidden: 'lakehouse_alpha' },
{
key: 'collapsed:urn:li:container:warehouse',
text: '\u2026',
hidden: 'warehouse.region.petshop_central.department',
},
{ key: 'self', text: 'supply' },
]);
});

it('shortens long names in the middle so names that differ at either end stay apart', () => {
const archive = 'petshop_loyalty_programme_archive_2019_to_2024';

expect(getContainerPathSegments('store', parentsOf([], archive), getLabel)).toEqual([
{ key: `urn:li:container:${archive}`, text: 'petsho\u2026to_2024', hidden: archive },
{ key: 'self', text: 'store' },
]);
});

it('keeps every level that differs, so long paths that need several levels stay apart', () => {
const lakeA = container('urn:li:container:lake_a', 'petshop_lakehouse_a');
const lakeB = container('urn:li:container:lake_b', 'petshop_lakehouse_b');
const central = (urn: string, lake: Entity) => container(urn, 'petshop_central_region', [lake]);
const east = container('urn:li:container:east_a', 'petshop_east_region', [lakeA]);
const supplies = [
container('urn:li:container:supply_1', 'supply', [central('urn:li:container:central_a', lakeA), lakeA]),
container('urn:li:container:supply_2', 'supply', [central('urn:li:container:central_b', lakeB), lakeB]),
container('urn:li:container:supply_3', 'supply', [east, lakeA]),
];

const parents = getContainerDisambiguationParents(supplies.map(option), getLabel);
const labels = supplies.map((supply) =>
text(getContainerPathSegments('supply', parents.get(supply.urn) || [], getLabel)),
);

expect(new Set(labels).size).toBe(3);
expect(labels).toContain('petsho\u2026house_a.petshop_east_region.supply');
});
});
Loading
Loading