Skip to content

Commit

Permalink
Merge pull request #299 from liam-hq/refactor-table-node-2
Browse files Browse the repository at this point in the history
refactor: The behavior of TableNode when clicked is unified to be handled by ERDContent
  • Loading branch information
MH4GF authored Dec 18, 2024
2 parents 176d201 + 88cf707 commit 5628eb0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
6 changes: 6 additions & 0 deletions frontend/.changeset/pink-otters-happen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@liam-hq/erd-core": patch
"@liam-hq/cli": patch
---

refactor: The behavior of TableNode when clicked is unified to be handled by ERDContent
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useDBStructureStore } from '@/stores'
import { updateActiveTableName, useDBStructureStore } from '@/stores'
import type { Relationships } from '@liam-hq/db-structure'
import {
Background,
Expand Down Expand Up @@ -89,6 +89,7 @@ export const ERDContentInner: FC<Props> = ({
const handleNodeClick = useCallback(
(nodeId: string) => {
setActiveNodeId(nodeId)
updateActiveTableName(nodeId)

const relatedEdges = edges.filter(
(e) => e.source === nodeId || e.target === nodeId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import {
updateActiveTableName,
useDBStructureStore,
useUserEditingStore,
} from '@/stores'
import { useDBStructureStore, useUserEditingStore } from '@/stores'
import type { Node, NodeProps } from '@xyflow/react'
import clsx from 'clsx'
import { type FC, useCallback } from 'react'
import type { FC } from 'react'
import { isRelatedToTable } from '../ERDContent'
import { TableColumnList } from './TableColumnList'
import { TableHeader } from './TableHeader'
Expand All @@ -30,23 +26,17 @@ export const TableNode: FC<Props> = ({ data }) => {
data.isRelated ||
isRelatedToTable(relationships, data.table.name, tableName)

const handleClick = useCallback(() => {
updateActiveTableName(data.table.name)
}, [data])

return (
<button
type="button"
<div
className={clsx(
styles.wrapper,
isTableRelated && styles.wrapperHover,
isActive && styles.wrapperActive,
)}
onClick={handleClick}
data-erd="table-node"
>
<TableHeader data={data} />
{showMode === 'ALL_FIELDS' && <TableColumnList data={data} />}
</button>
</div>
)
}

0 comments on commit 5628eb0

Please sign in to comment.