import { Badge, Box, Flex, SkeletonText, VStack } from '@chakra-ui/react'; import { useMemo } from 'react'; import ReactFlow, { Background, ReactFlowProvider, Handle, Position, isNode, isEdge, } from 'reactflow'; import { useConfig } from '~/context'; import { useASNDetail, useColorToken, useColorValue } from '~/hooks'; import { Controls } from './controls'; import { useElements } from './use-elements'; import type { NodeProps as ReactFlowNodeProps } from 'reactflow'; interface ChartProps { data: StructuredResponse; } interface NodeProps extends Omit { data: D; } export interface NodeData { asn: string; name: string; hasChildren: boolean; hasParents?: boolean; } export const Chart = (props: ChartProps): JSX.Element => { const { data } = props; const { primaryAsn, orgName } = useConfig(); const dots = useColorToken('colors', 'blackAlpha.500', 'whiteAlpha.400'); const elements = useElements({ asn: primaryAsn, name: orgName }, data); const nodes = useMemo(() => elements.filter(isNode), [elements]); const edges = useMemo(() => elements.filter(isEdge), [elements]); return ( setTimeout(() => inst.fitView(), 0)} proOptions={{ hideAttribution: true }} > ); }; const ASNode = (props: NodeProps): JSX.Element => { const { data } = props; const { asn, name, hasChildren, hasParents } = data; const color = useColorValue('black', 'white'); const bg = useColorValue('white', 'whiteAlpha.200'); const { data: asnData, isError, isLoading } = useASNDetail(String(asn)); return ( <> {hasChildren && } {isLoading ? ( ) : !isError && asnData?.data?.asn.organization?.orgName ? ( asnData.data.asn.organization.orgName ) : ( name )} {asn} {hasParents && } ); };