import React from 'react'; import { Group } from '@vx/group'; import { LinkHorizontal } from '@vx/shape'; import styled from 'styled-components'; import { EntityType } from '../../types.generated'; import { NodeData, Direction } from './types'; function truncate(input, length) { if (!input) return ''; if (input.length > length) { return `${input.substring(0, length)}...`; } return input; } export const width = 212; export const height = 80; const iconWidth = 42; const iconHeight = 42; const iconX = -width / 2 + 8; 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, onHover, onExpandClick, direction, isCenterNode, nodesToRenderByUrn, }: { node: { x: number; y: number; data: Omit }; isSelected: boolean; isHovered: boolean; isCenterNode: boolean; onEntityClick: (EntitySelectParams) => void; onHover: (EntitySelectParams) => void; onExpandClick: (LineageExpandParams) => void; direction: Direction; nodesToRenderByUrn: { [key: string]: { x: number; y: number; data: Omit }[] }; }) { 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: EntityType.Dataset, direction }); }} > ) : null} { onEntityClick({ urn: node.data.urn, type: EntityType.Dataset }); }} onMouseOver={() => { onHover({ urn: node.data.urn, type: EntityType.Dataset }); }} onMouseOut={() => { onHover(undefined); }} > {node.data.icon ? ( ) : null} {truncate(node.data.name?.split('.').slice(-1)[0], 16)} {unexploredHiddenChildren && isHovered ? ( {unexploredHiddenChildren} hidden {direction === Direction.Upstream ? 'downstream' : 'upstream'}{' '} {unexploredHiddenChildren > 1 ? 'dependencies' : 'dependency'} ) : null} ); }