Skip to content

Commit 93473d9

Browse files
committed
refactor how Pills is rendered
1 parent 0a56041 commit 93473d9

File tree

2 files changed

+47
-48
lines changed

2 files changed

+47
-48
lines changed

datahub-web-react/src/app/previewV2/DefaultPreviewCardFooter.tsx

+26-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import React from 'react';
1+
import { LineageTabContext } from '@app/entityV2/shared/tabs/Lineage/LineageTabContext';
2+
import { useMatchedFieldsForList } from '@app/search/context/SearchResultContext';
3+
import React, { useContext } from 'react';
24
import styled from 'styled-components';
35
import { Divider } from 'antd';
46
import Pills from './Pills';
@@ -104,7 +106,23 @@ const DefaultPreviewCardFooter: React.FC<DefaultPreviewCardFooterProps> = ({
104106
paths,
105107
isFullViewCard,
106108
}) => {
107-
const shouldRenderPillsRow = [glossaryTerms.length, tags.length, owners.length].some(Boolean);
109+
const groupedMatches = useMatchedFieldsForList('fieldLabels');
110+
const { lineageDirection, isColumnLevelLineage, selectedColumn } = useContext(LineageTabContext);
111+
112+
const showGlossaryTerms = entityHasCapability(entityCapabilities, EntityCapabilityType.GLOSSARY_TERMS);
113+
const showTags = entityHasCapability(entityCapabilities, EntityCapabilityType.TAGS);
114+
const showOwners = entityHasCapability(entityCapabilities, EntityCapabilityType.OWNERS);
115+
116+
// Only show the column paths pill on datasets who actually have columns to show
117+
const shouldShowPaths =
118+
!!paths?.length && entityType === EntityType.Dataset && isColumnLevelLineage && selectedColumn;
119+
const shouldRenderPillsRow = [
120+
showGlossaryTerms && glossaryTerms.length,
121+
showTags && tags.length,
122+
showOwners && owners.length,
123+
groupedMatches.length,
124+
shouldShowPaths,
125+
].some(Boolean);
108126
const shouldRenderEntityLink = previewType === PreviewType.HOVER_CARD && entityTitleSuffix;
109127
const shouldRenderRightSection =
110128
tier !== undefined ||
@@ -119,12 +137,12 @@ const DefaultPreviewCardFooter: React.FC<DefaultPreviewCardFooterProps> = ({
119137
<Container>
120138
{isFullViewCard && (
121139
<Pills
122-
glossaryTerms={glossaryTerms}
123-
tags={tags}
124-
owners={owners}
125-
entityCapabilities={entityCapabilities}
126-
paths={paths}
127-
entityType={entityType}
140+
glossaryTerms={showGlossaryTerms ? glossaryTerms : []}
141+
tags={showTags ? tags : []}
142+
owners={showOwners ? owners : []}
143+
groupedMatches={groupedMatches}
144+
paths={shouldRenderPillsRow ? paths : []}
145+
lineageDirection={lineageDirection}
128146
/>
129147
)}
130148
<RightSection isFullViewCard={isFullViewCard}>

datahub-web-react/src/app/previewV2/Pills.tsx

+21-40
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,15 @@
11
import { LayoutOutlined } from '@ant-design/icons';
2+
import { MatchesGroupedByFieldName } from '@app/searchV2/matches/constants';
23
import React, { useContext } from 'react';
34
import AccountCircleOutlinedIcon from '@mui/icons-material/AccountCircleOutlined';
45
import FindInPageOutlinedIcon from '@mui/icons-material/FindInPageOutlined';
56
import SellOutlinedIcon from '@mui/icons-material/SellOutlined';
67
import styled from 'styled-components';
78
import { BookmarkSimple } from '@phosphor-icons/react';
8-
import { useMatchedFieldsForList } from '../search/context/SearchResultContext';
9-
import {
10-
EntityPath,
11-
EntityType,
12-
GlossaryTermAssociation,
13-
LineageDirection,
14-
Owner,
15-
TagAssociation,
16-
} from '../../types.generated';
17-
import { EntityCapabilityType } from '../entityV2/Entity';
9+
import { EntityPath, GlossaryTermAssociation, LineageDirection, Owner, TagAssociation } from '../../types.generated';
1810
import MatchesContext, { PreviewSection } from '../shared/MatchesContext';
1911
import SearchPill from './SearchPill';
20-
import { entityHasCapability, getHighlightedTag } from './utils';
21-
import { LineageTabContext } from '../entityV2/shared/tabs/Lineage/LineageTabContext';
12+
import { getHighlightedTag } from './utils';
2213

2314
const PillsContainer = styled.div`
2415
gap: 5px;
@@ -32,19 +23,14 @@ interface Props {
3223
glossaryTerms: GlossaryTermAssociation[];
3324
tags: TagAssociation[];
3425
owners: Owner[];
35-
entityCapabilities: Set<EntityCapabilityType>;
26+
groupedMatches: MatchesGroupedByFieldName[];
3627
paths?: EntityPath[];
37-
entityType: EntityType;
28+
lineageDirection: LineageDirection;
3829
}
3930

40-
const Pills = ({ glossaryTerms, tags, owners, entityCapabilities, paths, entityType }: Props) => {
41-
const { lineageDirection, isColumnLevelLineage, selectedColumn } = useContext(LineageTabContext);
31+
const Pills = ({ glossaryTerms, tags, owners, groupedMatches, paths, lineageDirection }: Props) => {
4232
const lineageDirectionText = lineageDirection === LineageDirection.Downstream ? 'downstream' : 'upstream';
4333
const { setExpandedSection, expandedSection } = useContext(MatchesContext);
44-
const groupedMatches = useMatchedFieldsForList('fieldLabels');
45-
const showGlossaryTermsBadge = entityHasCapability(entityCapabilities, EntityCapabilityType.GLOSSARY_TERMS);
46-
const showTagsBadge = entityHasCapability(entityCapabilities, EntityCapabilityType.TAGS);
47-
const showOwnersBadge = entityHasCapability(entityCapabilities, EntityCapabilityType.OWNERS);
4834
const highlightedTag = getHighlightedTag(tags);
4935

5036
const handlePillClick = (section: PreviewSection | undefined, data) => (e) => {
@@ -56,7 +42,7 @@ const Pills = ({ glossaryTerms, tags, owners, entityCapabilities, paths, entityT
5642

5743
return (
5844
<PillsContainer>
59-
{showGlossaryTermsBadge && !!glossaryTerms.length && (
45+
{!!glossaryTerms.length && (
6046
<SearchPill
6147
icon={<BookmarkSimple />}
6248
count={glossaryTerms.length || 0}
@@ -68,7 +54,7 @@ const Pills = ({ glossaryTerms, tags, owners, entityCapabilities, paths, entityT
6854
highlightedText={glossaryTerms.length ? glossaryTerms[0]?.term?.properties?.name : ''}
6955
/>
7056
)}
71-
{showTagsBadge && !!tags.length && (
57+
{!!tags.length && (
7258
<SearchPill
7359
icon={<SellOutlinedIcon />}
7460
count={tags.length}
@@ -80,7 +66,7 @@ const Pills = ({ glossaryTerms, tags, owners, entityCapabilities, paths, entityT
8066
highlightedText={highlightedTag}
8167
/>
8268
)}
83-
{showOwnersBadge && !!owners.length && (
69+
{!!owners.length && (
8470
<SearchPill
8571
icon={<AccountCircleOutlinedIcon />}
8672
count={owners.length}
@@ -92,7 +78,7 @@ const Pills = ({ glossaryTerms, tags, owners, entityCapabilities, paths, entityT
9278
/>
9379
)}
9480

95-
{groupedMatches.length > 0 && (
81+
{!!groupedMatches.length && (
9682
<SearchPill
9783
icon={<FindInPageOutlinedIcon />}
9884
count={groupedMatches?.length || 0}
@@ -103,22 +89,17 @@ const Pills = ({ glossaryTerms, tags, owners, entityCapabilities, paths, entityT
10389
onClick={handlePillClick(PreviewSection.MATCHES, groupedMatches)}
10490
/>
10591
)}
106-
{/* only show the column paths pill on datasets who actually have columns to show */}
107-
{paths &&
108-
paths.length > 0 &&
109-
entityType === EntityType.Dataset &&
110-
isColumnLevelLineage &&
111-
selectedColumn && (
112-
<SearchPill
113-
icon={<LayoutOutlined />}
114-
count={paths.length || 0}
115-
enabled={!!paths.length}
116-
active={expandedSection === PreviewSection.COLUMN_PATHS}
117-
label=""
118-
countLabel={`${lineageDirectionText} column`}
119-
onClick={handlePillClick(PreviewSection.COLUMN_PATHS, paths)}
120-
/>
121-
)}
92+
{!!paths?.length && (
93+
<SearchPill
94+
icon={<LayoutOutlined />}
95+
count={paths.length}
96+
enabled={!!paths.length}
97+
active={expandedSection === PreviewSection.COLUMN_PATHS}
98+
label=""
99+
countLabel={`${lineageDirectionText} column`}
100+
onClick={handlePillClick(PreviewSection.COLUMN_PATHS, paths)}
101+
/>
102+
)}
122103
</PillsContainer>
123104
);
124105
};

0 commit comments

Comments
 (0)