import React from 'react'; import { Group } from '@vx/group'; import { LinkHorizontal } from '@vx/shape'; import styled from 'styled-components'; import { useEntityRegistry } from '../useEntityRegistry'; import { IconStyleType } from '../entity/Entity'; import { NodeData, Direction } from './types'; import { ANTD_GRAY } from '../entity/shared/constants'; import { capitalizeFirstLetter } from '../shared/capitalizeFirstLetter'; function truncate(input, length) { if (!input) return ''; if (input.length > length) { return `${input.substring(0, length)}...`; } return input; } function getLastTokenOfTitle(title: string): string { const lastToken = title?.split('.').slice(-1)[0]; // if the last token does not contain any content, the string should not be tokenized on `.` if (lastToken.replace(/\s/g, '').length === 0) { return title; } return lastToken; } export const width = 212; export const height = 80; const iconWidth = 32; const iconHeight = 32; const iconX = -width / 2 + 22; const iconY = -iconHeight / 2; const centerX = -width / 2; const centerY = -height / 2; const textX = iconX + iconWidth + 8; const PointerGroup = styled(Group)` cursor: pointer; `; export default function LineageEntityNode({ node, isSelected, isHovered, onEntityClick, onEntityCenter, onHover, onExpandClick, direction, isCenterNode, nodesToRenderByUrn, }: { node: { x: number; y: number; data: Omit }; isSelected: boolean; isHovered: boolean; isCenterNode: boolean; onEntityClick: (EntitySelectParams) => void; onEntityCenter: (EntitySelectParams) => void; onHover: (EntitySelectParams) => void; onExpandClick: (LineageExpandParams) => void; direction: Direction; nodesToRenderByUrn: { [key: string]: { x: number; y: number; data: Omit }[] }; }) { const entityRegistry = useEntityRegistry(); const unexploredHiddenChildren = node?.data?.countercurrentChildrenUrns?.filter((urn) => !(urn in nodesToRenderByUrn))?.length || 0; return ( {unexploredHiddenChildren ? ( {[...Array(unexploredHiddenChildren)].map((_, index) => { const link = { source: { x: 0, y: direction === Direction.Upstream ? 70 : -70, }, target: { x: (0.5 / (index + 1)) * 80 * (index % 2 === 0 ? 1 : -1), y: direction === Direction.Upstream ? 150 : -150, }, }; return ( ); })} ) : null} {node.data.unexploredChildren ? ( { onExpandClick({ urn: node.data.urn, type: node.data.type, direction }); }} > ) : null} onEntityCenter({ urn: node.data.urn, type: node.data.type })} onClick={() => { onEntityClick({ urn: node.data.urn, type: node.data.type }); }} onMouseOver={() => { onHover({ urn: node.data.urn, type: node.data.type }); }} onMouseOut={() => { onHover(undefined); }} > {node.data.icon ? ( ) : ( node.data.type && ( ) )} {truncate(capitalizeFirstLetter(node.data.platform), 16)} {' '} |{' '} {capitalizeFirstLetter(node.data.subtype || node.data.type)} {truncate(getLastTokenOfTitle(node.data.name), 16)} {unexploredHiddenChildren && isHovered ? ( {unexploredHiddenChildren} hidden {direction === Direction.Upstream ? 'downstream' : 'upstream'}{' '} {unexploredHiddenChildren > 1 ? 'dependencies' : 'dependency'} ) : null} ); }