11import { orange } from '@ant-design/colors' ;
22import { WarningFilled } from '@ant-design/icons' ;
3+ import { Tooltip } from '@components' ;
34import React from 'react' ;
45import { useParams } from 'react-router' ;
56import styled from 'styled-components' ;
67
78import { generateQueryVariables } from '@app/entityV2/shared/embed/UpstreamHealth/utils' ;
89import { decodeUrn } from '@app/entityV2/shared/utils' ;
910import { useGetDefaultLineageStartTimeMillis } from '@app/lineage/utils/useGetLineageTimeParams' ;
11+ import { getEntityTypeFromEntityUrn } from '@app/lineageV3/utils/lineageUtils' ;
1012import { HAS_ACTIVE_INCIDENTS_FILTER_NAME , HAS_FAILING_ASSERTIONS_FILTER_NAME } from '@app/search/utils/constants' ;
13+ import { useUrlQueryParam } from '@app/shared/useUrlQueryParam' ;
1114import { useAppConfig } from '@app/useAppConfig' ;
15+ import { useEntityRegistry } from '@app/useEntityRegistry' ;
1216
1317import { useSearchAcrossLineageQuery } from '@graphql/search.generated' ;
1418
1519// Do not update unless you update the reference to this ID in our Chrome extension code
1620const 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
2330interface 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
2835export 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 ;
0 commit comments