diff --git a/frontend/.changeset/popular-actors-smoke.md b/frontend/.changeset/popular-actors-smoke.md new file mode 100644 index 00000000..60930fc5 --- /dev/null +++ b/frontend/.changeset/popular-actors-smoke.md @@ -0,0 +1,5 @@ +--- +"@liam-hq/erd-core": patch +--- + +refactor: remove unused convertElkEdgesToEdges function diff --git a/frontend/packages/erd-core/src/components/ERDRenderer/ERDContent/useAutoLayout/convertElkEdgesToEdges.ts b/frontend/packages/erd-core/src/components/ERDRenderer/ERDContent/useAutoLayout/convertElkEdgesToEdges.ts deleted file mode 100644 index dc037fd1..00000000 --- a/frontend/packages/erd-core/src/components/ERDRenderer/ERDContent/useAutoLayout/convertElkEdgesToEdges.ts +++ /dev/null @@ -1,26 +0,0 @@ -import type { Edge } from '@xyflow/react' -import type { ElkExtendedEdge } from 'elkjs' - -export function convertElkEdgesToEdges( - elkEdges: ElkExtendedEdge[], - originEdges: Edge[], -): Edge[] { - const results: Edge[] = [] - - for (const { id, sources, targets } of elkEdges) { - const originEdge = originEdges.find((edge) => edge.id === id) - if (!originEdge) continue - - results.push({ - ...originEdge, - source: sources[0] ?? '', - target: targets[0] ?? '', - zIndex: 1, - style: { - opacity: 1, - }, - }) - } - - return results -} diff --git a/frontend/packages/erd-core/src/components/ERDRenderer/ERDContent/useAutoLayout/getElkLayout.ts b/frontend/packages/erd-core/src/components/ERDRenderer/ERDContent/useAutoLayout/getElkLayout.ts index 4ffeef1e..32ef9cc3 100644 --- a/frontend/packages/erd-core/src/components/ERDRenderer/ERDContent/useAutoLayout/getElkLayout.ts +++ b/frontend/packages/erd-core/src/components/ERDRenderer/ERDContent/useAutoLayout/getElkLayout.ts @@ -1,7 +1,6 @@ import type { Edge, Node } from '@xyflow/react' import type { ElkNode, LayoutOptions } from 'elkjs' import ELK from 'elkjs/lib/elk.bundled.js' -import { convertElkEdgesToEdges } from './convertElkEdgesToEdges' import { convertElkNodesToNodes } from './convertElkNodesToNodes' import { convertNodesToElkNodes } from './convertNodesToElkNodes' @@ -24,7 +23,7 @@ type Params = { edges: Edge[] } -export async function getElkLayout({ nodes, edges }: Params): Promise { +export async function getElkLayout({ nodes, edges }: Params): Promise { const graph: ElkNode = { id: 'root', layoutOptions, @@ -38,14 +37,8 @@ export async function getElkLayout({ nodes, edges }: Params): Promise { const layout = await elk.layout(graph) if (!layout.children) { - return { - nodes, - edges, - } + return nodes } - return { - nodes: convertElkNodesToNodes(layout.children, nodes), - edges: convertElkEdgesToEdges(layout.edges ?? [], edges), - } + return convertElkNodesToNodes(layout.children, nodes) } diff --git a/frontend/packages/erd-core/src/components/ERDRenderer/ERDContent/useAutoLayout/useAutoLayout.ts b/frontend/packages/erd-core/src/components/ERDRenderer/ERDContent/useAutoLayout/useAutoLayout.ts index 65b13315..de5d6541 100644 --- a/frontend/packages/erd-core/src/components/ERDRenderer/ERDContent/useAutoLayout/useAutoLayout.ts +++ b/frontend/packages/erd-core/src/components/ERDRenderer/ERDContent/useAutoLayout/useAutoLayout.ts @@ -4,21 +4,20 @@ import { getElkLayout } from './getElkLayout' export const useAutoLayout = () => { const nodesInitialized = useNodesInitialized() - const { getNodes, setNodes, getEdges, setEdges, fitView } = useReactFlow() + const { getNodes, setNodes, getEdges, fitView } = useReactFlow() const handleLayout = useCallback(async () => { const nodes = getNodes() const edges = getEdges() - const { nodes: newNodes, edges: newEdges } = await getElkLayout({ + const newNodes = await getElkLayout({ nodes, edges, }) setNodes(newNodes) - setEdges(newEdges) setTimeout(() => fitView(), 0) - }, [getNodes, setNodes, getEdges, setEdges, fitView]) + }, [getNodes, setNodes, getEdges, fitView]) useEffect(() => { if (nodesInitialized) { diff --git a/frontend/packages/erd-core/src/components/ERDRenderer/convertDBStructureToNodes.ts b/frontend/packages/erd-core/src/components/ERDRenderer/convertDBStructureToNodes.ts index 6647f8a6..1f7f56a6 100644 --- a/frontend/packages/erd-core/src/components/ERDRenderer/convertDBStructureToNodes.ts +++ b/frontend/packages/erd-core/src/components/ERDRenderer/convertDBStructureToNodes.ts @@ -46,9 +46,6 @@ export const convertDBStructureToNodes = ({ ? null : `${rel.foreignTableName}-${rel.foreignColumnName}`, data: { relationship: rel }, - style: { - opacity: 0, - }, })) return { nodes, edges }