Skip to content

Commit 27f8e0f

Browse files
authored
feat(web): Add tooltip and size parameter to EmbeddedHealthIcon (#14604)
1 parent 06747d6 commit 27f8e0f

File tree

2 files changed

+61
-3
lines changed

2 files changed

+61
-3
lines changed

datahub-web-react/src/app/entityV2/shared/embed/EmbeddedHealthIcon.tsx

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,30 @@
11
import { orange } from '@ant-design/colors';
22
import { WarningFilled } from '@ant-design/icons';
3+
import { Tooltip } from '@components';
34
import React from 'react';
45
import { useParams } from 'react-router';
56
import styled from 'styled-components';
67

78
import { generateQueryVariables } from '@app/entityV2/shared/embed/UpstreamHealth/utils';
89
import { decodeUrn } from '@app/entityV2/shared/utils';
910
import { useGetDefaultLineageStartTimeMillis } from '@app/lineage/utils/useGetLineageTimeParams';
11+
import { getEntityTypeFromEntityUrn } from '@app/lineageV3/utils/lineageUtils';
1012
import { HAS_ACTIVE_INCIDENTS_FILTER_NAME, HAS_FAILING_ASSERTIONS_FILTER_NAME } from '@app/search/utils/constants';
13+
import { useUrlQueryParam } from '@app/shared/useUrlQueryParam';
1114
import { useAppConfig } from '@app/useAppConfig';
15+
import { useEntityRegistry } from '@app/useEntityRegistry';
1216

1317
import { useSearchAcrossLineageQuery } from '@graphql/search.generated';
1418

1519
// Do not update unless you update the reference to this ID in our Chrome extension code
1620
const ICON_ID = 'embedded-datahub-health-icon';
1721

18-
const StyledWarning = styled(WarningFilled)`
22+
// Default size for the warning icon in pixels
23+
const DEFAULT_ICON_SIZE = 16;
24+
25+
const StyledWarning = styled(WarningFilled)<{ size: number }>`
1926
color: ${orange[5]};
20-
font-size: 16px;
27+
font-size: ${({ size }) => size}px;
2128
`;
2229

2330
interface RouteParams {
@@ -26,8 +33,16 @@ interface RouteParams {
2633

2734
// Used by our Chrome Extension to show a warning health icon if there are unhealthy upstreams
2835
export default function EmbeddedHealthIcon() {
36+
const entityRegistry = useEntityRegistry();
2937
const { urn: encodedUrn } = useParams<RouteParams>();
38+
const { value: showTooltipParam } = useUrlQueryParam('show-tooltip', 'false');
39+
const { value: sizeParam } = useUrlQueryParam('size', DEFAULT_ICON_SIZE.toString());
40+
const showTooltip = showTooltipParam === 'true';
41+
const iconSize = parseInt(sizeParam || DEFAULT_ICON_SIZE.toString(), 10);
3042
const urn = decodeUrn(encodedUrn);
43+
const entityType = getEntityTypeFromEntityUrn(urn, entityRegistry);
44+
const [, , entityTypeFallback] = urn.split(':');
45+
3146
const appConfig = useAppConfig();
3247
const lineageEnabled: boolean = appConfig?.config?.chromeExtensionConfig?.lineageEnabled || false;
3348
const startTimeMillis = useGetDefaultLineageStartTimeMillis();
@@ -59,7 +74,25 @@ export default function EmbeddedHealthIcon() {
5974
);
6075

6176
if (incidentsData?.searchAcrossLineage?.total || assertionsData?.searchAcrossLineage?.total) {
62-
return <StyledWarning id={ICON_ID} />;
77+
const warningIcon = <StyledWarning id={ICON_ID} size={iconSize} />;
78+
79+
if (showTooltip) {
80+
const title =
81+
"Some upstream entities are unhealthy, which may impact this entity. Expand the DataHub browser extension's side panel for more details.";
82+
return (
83+
<Tooltip title={title}>
84+
<a
85+
href={`${window.location.origin}${entityType ? entityRegistry.getEntityUrl(entityType, urn) : `/${entityTypeFallback}/${encodeURIComponent(urn)}`}`}
86+
target="_blank"
87+
rel="noreferrer noopener"
88+
>
89+
{warningIcon}
90+
</a>
91+
</Tooltip>
92+
);
93+
}
94+
95+
return warningIcon;
6396
}
6497

6598
return null;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { useEffect, useMemo } from 'react';
2+
import { useHistory, useLocation } from 'react-router';
3+
4+
import updateQueryParams from '@app/shared/updateQueryParams';
5+
6+
export const useUrlQueryParam = (paramKey: string, defaultValue?: string) => {
7+
const location = useLocation();
8+
const history = useHistory();
9+
10+
const searchParams = useMemo(() => new URLSearchParams(location.search), [location.search]);
11+
12+
const value = searchParams.get(paramKey) || defaultValue;
13+
14+
useEffect(() => {
15+
if (!searchParams.get(paramKey) && defaultValue) {
16+
updateQueryParams({ [paramKey]: defaultValue }, location, history);
17+
}
18+
}, [paramKey, defaultValue, location, history, searchParams]);
19+
20+
const setValue = (paramValue: string) => {
21+
updateQueryParams({ [paramKey]: paramValue }, location, history);
22+
};
23+
24+
return { value, setValue };
25+
};

0 commit comments

Comments
 (0)