Skip to content

Commit

Permalink
Merge pull request #397 from liam-hq/fix-fit-view
Browse files Browse the repository at this point in the history
🐛 Fixed problem with fitView not working properly while displaying only some tables
  • Loading branch information
junkisai authored Dec 26, 2024
2 parents 17f2f39 + e0c748c commit fc6ba1d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changeset/breezy-olives-decide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@liam-hq/erd-core": patch
"@liam-hq/cli": patch
---

:bug: Fixed problem with fitView not working properly while displaying only some tables
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
import { useUserEditingStore } from '@/stores'
import { useReactFlow } from '@xyflow/react'
import { type Node, useReactFlow } from '@xyflow/react'
import { useEffect } from 'react'
import { NON_RELATED_TABLE_GROUP_NODE_ID } from '../convertDBStructureToNodes'
import { useERDContentContext } from './ERDContentContext'

const newNonRelatedTableGroupNode = (nodes: Node[]): Node | undefined => {
const node = nodes.find((node) => node.id === NON_RELATED_TABLE_GROUP_NODE_ID)

if (!node) {
return
}

const visible = nodes
.filter((node) => node.parentId === NON_RELATED_TABLE_GROUP_NODE_ID)
.some((node) => !node.hidden)

return { ...node, hidden: !visible }
}

export const useSyncHiddenNodesChange = () => {
const {
state: { initializeComplete },
Expand All @@ -15,10 +30,14 @@ export const useSyncHiddenNodesChange = () => {
return
}
const nodes = getNodes()
const updatedNodes = nodes.map((node) => {
const updatedNodes: Node[] = nodes.map((node) => {
const hidden = hiddenNodeIds.has(node.id)
return { ...node, hidden }
})
const nonRelatedTableGroupNode = newNonRelatedTableGroupNode(updatedNodes)
if (nonRelatedTableGroupNode !== undefined) {
updatedNodes.push(nonRelatedTableGroupNode)
}

setNodes(updatedNodes)
}, [initializeComplete, getNodes, setNodes, hiddenNodeIds])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { Edge, Node } from '@xyflow/react'
import { columnHandleId } from './columnHandleId'
import { zIndex } from './constants'

const NON_RELATED_TABLE_GROUP_NODE_ID = 'non-related-table-group'
export const NON_RELATED_TABLE_GROUP_NODE_ID = 'non-related-table-group'

type Params = {
dbStructure: DBStructure
Expand Down

0 comments on commit fc6ba1d

Please sign in to comment.