Skip to content

Commit efc6ac3

Browse files
chriscollins3456Chris CollinsChris Collins
authored
fix(ui) Filter search through schemas based on non-editable tags and terms as well (#5942)
* filter based on non-editable tags and terms as well * update function name for consistency Co-authored-by: Chris Collins <[email protected]> Co-authored-by: Chris Collins <[email protected]>
1 parent a14617b commit efc6ac3

File tree

3 files changed

+94
-32
lines changed

3 files changed

+94
-32
lines changed

datahub-web-react/src/app/entity/shared/tabs/Dataset/Schema/__tests__/filterSchemaRows.test.ts

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ describe('filterSchemaRows', () => {
3535
expect(expandedRowsFromFilter).toMatchObject(new Set());
3636
});
3737

38-
it('should properly filter schema rows based on tags', () => {
38+
it('should properly filter schema rows based on editable tags', () => {
3939
const editableSchemaMetadata = {
4040
editableSchemaFieldInfo: [
4141
{ fieldPath: 'customer', globalTags: { tags: [{ tag: sampleTag }] }, glossaryTerms: null },
@@ -53,7 +53,7 @@ describe('filterSchemaRows', () => {
5353
expect(expandedRowsFromFilter).toMatchObject(new Set());
5454
});
5555

56-
it('should properly filter schema rows based on glossary terms', () => {
56+
it('should properly filter schema rows based on editable glossary terms', () => {
5757
const editableSchemaMetadata = {
5858
editableSchemaFieldInfo: [
5959
{ fieldPath: 'shipment', globalTags: null, glossaryTerms: { terms: [{ term: glossaryTerm1 }] } },
@@ -119,4 +119,42 @@ describe('filterSchemaRows', () => {
119119
]);
120120
expect(expandedRowsFromFilter).toMatchObject(new Set(['customer', 'customer.child1']));
121121
});
122+
123+
it('should properly filter schema rows based on non-editable tags', () => {
124+
const rowsWithTags = [
125+
{ fieldPath: 'customer' },
126+
{ fieldPath: 'testing', globalTags: { tags: [{ tag: sampleTag }] } },
127+
{ fieldPath: 'shipment' },
128+
] as SchemaField[];
129+
const editableSchemaMetadata = { editableSchemaFieldInfo: [] };
130+
const filterText = sampleTag.properties.name;
131+
const { filteredRows, expandedRowsFromFilter } = filterSchemaRows(
132+
rowsWithTags,
133+
editableSchemaMetadata,
134+
filterText,
135+
testEntityRegistry,
136+
);
137+
138+
expect(filteredRows).toMatchObject([{ fieldPath: 'testing' }]);
139+
expect(expandedRowsFromFilter).toMatchObject(new Set());
140+
});
141+
142+
it('should properly filter schema rows based on non-editable glossary terms', () => {
143+
const rowsWithTerms = [
144+
{ fieldPath: 'customer' },
145+
{ fieldPath: 'testing' },
146+
{ fieldPath: 'shipment', glossaryTerms: { terms: [{ term: glossaryTerm1 }] } },
147+
] as SchemaField[];
148+
const editableSchemaMetadata = { editableSchemaFieldInfo: [] };
149+
const filterText = glossaryTerm1.properties?.name as string;
150+
const { filteredRows, expandedRowsFromFilter } = filterSchemaRows(
151+
rowsWithTerms,
152+
editableSchemaMetadata,
153+
filterText,
154+
testEntityRegistry,
155+
);
156+
157+
expect(filteredRows).toMatchObject([{ fieldPath: 'shipment' }]);
158+
expect(expandedRowsFromFilter).toMatchObject(new Set());
159+
});
122160
});

datahub-web-react/src/app/entity/shared/tabs/Dataset/Schema/utils/filterSchemaRows.ts

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,35 @@
11
import { EntityType, SchemaField } from '../../../../../../../types.generated';
22
import EntityRegistry from '../../../../../EntityRegistry';
33

4+
function matchesTagsOrTerms(field: SchemaField, filterText: string, entityRegistry: EntityRegistry) {
5+
return (
6+
field.globalTags?.tags?.find((tagAssociation) =>
7+
entityRegistry.getDisplayName(EntityType.Tag, tagAssociation.tag).toLocaleLowerCase().includes(filterText),
8+
) ||
9+
field.glossaryTerms?.terms?.find((termAssociation) =>
10+
entityRegistry
11+
.getDisplayName(EntityType.GlossaryTerm, termAssociation.term)
12+
.toLocaleLowerCase()
13+
.includes(filterText),
14+
)
15+
);
16+
}
17+
418
// returns list of fieldPaths for fields that have Terms or Tags matching the filterText
519
function getFilteredFieldPathsByMetadata(editableSchemaMetadata: any, entityRegistry, filterText) {
620
return (
721
editableSchemaMetadata?.editableSchemaFieldInfo
8-
.filter((fieldInfo) => {
9-
return (
10-
fieldInfo.globalTags?.tags.find((tagAssociation) =>
11-
entityRegistry
12-
.getDisplayName(EntityType.Tag, tagAssociation.tag)
13-
.toLocaleLowerCase()
14-
.includes(filterText),
15-
) ||
16-
fieldInfo.glossaryTerms?.terms.find((termAssociation) =>
17-
entityRegistry
18-
.getDisplayName(EntityType.GlossaryTerm, termAssociation.term)
19-
.toLocaleLowerCase()
20-
.includes(filterText),
21-
)
22-
);
23-
})
22+
.filter((fieldInfo) => matchesTagsOrTerms(fieldInfo, filterText, entityRegistry))
2423
.map((fieldInfo) => fieldInfo.fieldPath) || []
2524
);
2625
}
2726

28-
function shouldInclude(
29-
fieldName: string,
30-
fullFieldPath: string,
31-
filterText: string,
32-
filteredFieldPathsByMetadata: any,
33-
) {
34-
return fieldName.toLocaleLowerCase().includes(filterText) || filteredFieldPathsByMetadata.includes(fullFieldPath);
27+
function matchesEditableTagsOrTerms(field: SchemaField, filteredFieldPathsByEditableMetadata: any) {
28+
return filteredFieldPathsByEditableMetadata.includes(field.fieldPath);
29+
}
30+
31+
function matchesFieldName(fieldName: string, filterText: string) {
32+
return fieldName.toLocaleLowerCase().includes(filterText);
3533
}
3634

3735
export function filterSchemaRows(
@@ -44,7 +42,7 @@ export function filterSchemaRows(
4442
if (!filterText) return { filteredRows: rows, expandedRowsFromFilter: new Set() };
4543
const formattedFilterText = filterText.toLocaleLowerCase();
4644

47-
const filteredFieldPathsByMetadata = getFilteredFieldPathsByMetadata(
45+
const filteredFieldPathsByEditableMetadata = getFilteredFieldPathsByMetadata(
4846
editableSchemaMetadata,
4947
entityRegistry,
5048
formattedFilterText,
@@ -53,12 +51,20 @@ export function filterSchemaRows(
5351
const expandedRowsFromFilter = new Set();
5452

5553
rows.forEach((row) => {
56-
if (shouldInclude(row.fieldPath, row.fieldPath, formattedFilterText, filteredFieldPathsByMetadata)) {
54+
if (
55+
matchesFieldName(row.fieldPath, formattedFilterText) ||
56+
matchesEditableTagsOrTerms(row, filteredFieldPathsByEditableMetadata) ||
57+
matchesTagsOrTerms(row, formattedFilterText, entityRegistry) // non-editable tags and terms
58+
) {
5759
finalFieldPaths.add(row.fieldPath);
5860
}
5961
const splitFieldPath = row.fieldPath.split('.');
6062
const fieldName = splitFieldPath.slice(-1)[0];
61-
if (shouldInclude(fieldName, row.fieldPath, formattedFilterText, filteredFieldPathsByMetadata)) {
63+
if (
64+
matchesFieldName(fieldName, formattedFilterText) ||
65+
matchesEditableTagsOrTerms(row, filteredFieldPathsByEditableMetadata) ||
66+
matchesTagsOrTerms(row, formattedFilterText, entityRegistry)
67+
) {
6268
// if we match specifically on this field (not just its parent), add and expand all parents
6369
splitFieldPath.reduce((previous, current) => {
6470
finalFieldPaths.add(previous);

datahub-web-react/src/app/shared/tags/TagTermGroup.tsx

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,13 @@ export default function TagTermGroup({
210210
>
211211
<Tag closable={false} style={{ cursor: 'pointer' }}>
212212
<BookOutlined style={{ marginRight: '3%' }} />
213-
{entityRegistry.getDisplayName(EntityType.GlossaryTerm, term.term)}
213+
<Highlight
214+
style={{ marginLeft: 0 }}
215+
matchStyle={highlightMatchStyle}
216+
search={highlightText}
217+
>
218+
{entityRegistry.getDisplayName(EntityType.GlossaryTerm, term.term)}
219+
</Highlight>
214220
</Tag>
215221
</TermLink>
216222
</HoverEntityTooltip>
@@ -231,7 +237,11 @@ export default function TagTermGroup({
231237
}}
232238
>
233239
<BookOutlined style={{ marginRight: '3%' }} />
234-
<Highlight matchStyle={highlightMatchStyle} search={highlightText}>
240+
<Highlight
241+
style={{ marginLeft: 0 }}
242+
matchStyle={highlightMatchStyle}
243+
search={highlightText}
244+
>
235245
{entityRegistry.getDisplayName(EntityType.GlossaryTerm, term.term)}
236246
</Highlight>
237247
</Tag>
@@ -258,7 +268,11 @@ export default function TagTermGroup({
258268
$color={tag?.tag?.properties?.colorHex}
259269
closable={false}
260270
>
261-
<Highlight matchStyle={highlightMatchStyle} search={highlightText}>
271+
<Highlight
272+
style={{ marginLeft: 0 }}
273+
matchStyle={highlightMatchStyle}
274+
search={highlightText}
275+
>
262276
{displayName}
263277
</Highlight>
264278
</StyledTag>
@@ -286,7 +300,11 @@ export default function TagTermGroup({
286300
removeTag(tag);
287301
}}
288302
>
289-
<Highlight matchStyle={highlightMatchStyle} search={highlightText}>
303+
<Highlight
304+
style={{ marginLeft: 0 }}
305+
matchStyle={highlightMatchStyle}
306+
search={highlightText}
307+
>
290308
{displayName}
291309
</Highlight>
292310
</StyledTag>

0 commit comments

Comments
 (0)