Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove unused convertElkEdgesToEdges function #263

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading