56 lines
1.9 KiB
TypeScript
Raw Permalink Normal View History

2024-12-30 23:50:15 +01:00
import React, {useEffect} from 'react'
2024-12-31 13:55:42 +01:00
import type { Edge, Node} from '@xyflow/react'
import {Background, Controls, MiniMap, ReactFlow, useEdgesState, useNodesState} from '@xyflow/react'
2024-12-30 23:50:15 +01:00
import {Flex} from 'antd'
2024-12-31 13:55:42 +01:00
import type {Domain} from '../../utils/api'
2024-12-30 23:50:15 +01:00
import {getLayoutedElements} from '../tracking/watchlist/diagram/getLayoutedElements'
import {domainEntitiesToNode, domainToNode, nsToNode, tldToNode} from '../tracking/watchlist/diagram/watchlistToNodes'
import {domainEntitiesToEdges, domainNSToEdges, tldToEdge} from '../tracking/watchlist/diagram/watchlistToEdges'
export function DomainDiagram({domain}: { domain: Domain }) {
2024-12-30 23:50:15 +01:00
const [nodes, setNodes, onNodesChange] = useNodesState<Node>([])
const [edges, setEdges, onEdgesChange] = useEdgesState<Edge>([])
useEffect(() => {
2024-12-20 17:43:35 +01:00
const nodes = [
domainToNode(domain),
2024-08-18 03:28:53 +02:00
...domainEntitiesToNode(domain, true),
...domain.nameservers.map(nsToNode)
2024-12-20 17:43:35 +01:00
].flat()
const edges = [
2024-08-18 03:28:53 +02:00
domainEntitiesToEdges(domain, true),
...domainNSToEdges(domain)
2024-12-20 17:43:35 +01:00
].flat()
if (domain.tld.tld !== '.') {
nodes.push(tldToNode(domain.tld))
edges.push(tldToEdge(domain))
}
const e = getLayoutedElements(nodes, edges)
setNodes(e.nodes)
setEdges(e.edges)
}, [])
2024-12-30 23:50:15 +01:00
return (
<Flex style={{width: '100%', height: '100vh'}}>
<ReactFlow
fitView
colorMode='system'
nodesConnectable={false}
edgesReconnectable={false}
nodes={nodes}
edges={edges}
onNodesChange={onNodesChange}
onEdgesChange={onEdgesChange}
style={{width: '100%', height: '100%'}}
>
<MiniMap/>
<Controls/>
<Background/>
</ReactFlow>
</Flex>
)
}