Skip to content

Commit

Permalink
Merge pull request #263 from liam-hq/refactor-remove-set-edges
Browse files Browse the repository at this point in the history
refactor: remove unused convertElkEdgesToEdges function
  • Loading branch information
junkisai authored Dec 16, 2024
2 parents d890612 + c6bc898 commit f3a6b65
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 43 deletions.
5 changes: 5 additions & 0 deletions frontend/.changeset/popular-actors-smoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@liam-hq/erd-core": patch
---

refactor: remove unused convertElkEdgesToEdges function

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -24,7 +23,7 @@ type Params = {
edges: Edge[]
}

export async function getElkLayout({ nodes, edges }: Params): Promise<Params> {
export async function getElkLayout({ nodes, edges }: Params): Promise<Node[]> {
const graph: ElkNode = {
id: 'root',
layoutOptions,
Expand All @@ -38,14 +37,8 @@ export async function getElkLayout({ nodes, edges }: Params): Promise<Params> {

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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ export const convertDBStructureToNodes = ({
? null
: `${rel.foreignTableName}-${rel.foreignColumnName}`,
data: { relationship: rel },
style: {
opacity: 0,
},
}))

return { nodes, edges }
Expand Down

0 comments on commit f3a6b65

Please sign in to comment.