Skip to content

Commit

Permalink
Refactor visibility handling in ERDRenderer components
Browse files Browse the repository at this point in the history
  • Loading branch information
sasamuku committed Dec 16, 2024
1 parent d086741 commit ed41c2e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useHiddenNodesStore } from '@/stores/hiddenNodes'
import type { Column, Relationships, Table } from '@liam-hq/db-structure'
import { DiamondFillIcon, DiamondIcon, KeyRound } from '@liam-hq/ui'
import { Handle, Position } from '@xyflow/react'
Expand Down Expand Up @@ -25,14 +26,19 @@ export const TableColumn: FC<TableColumnProps> = ({
}) => {
const handleId = `${table.name}-${column.name}`

const isSource = Object.values(relationships).some(
const hiddenNodes = useHiddenNodesStore()

const isVisibleSourceCardinality = Object.values(relationships).some(
(relationship) =>
relationship.primaryTableName === table.name &&
relationship.primaryColumnName === column.name,
relationship.primaryColumnName === column.name &&
!hiddenNodes.includes(relationship.foreignTableName),
)
const targetCardinality = Object.values(relationships).find(
({ foreignTableName, foreignColumnName }) =>
foreignTableName === table.name && foreignColumnName === column.name,
({ foreignTableName, foreignColumnName, primaryTableName }) =>
foreignTableName === table.name &&
foreignColumnName === column.name &&
!hiddenNodes.includes(primaryTableName),
)?.cardinality

return (
Expand Down Expand Up @@ -70,7 +76,7 @@ export const TableColumn: FC<TableColumnProps> = ({
<span className={styles.columnType}>{column.type}</span>
</span>

{isSource && (
{isVisibleSourceCardinality && (
<>
<Handle
id={handleId}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { addHiddenNode, removeHiddenNode } from '@/stores/hiddenNodes'
import { Eye, EyeClosed, SidebarMenuAction } from '@liam-hq/ui'
import { useReactFlow } from '@xyflow/react'
import { type FC, type MouseEvent, useCallback } from 'react'
Expand All @@ -14,9 +15,10 @@ export const VisibilityButton: FC<Props> = ({ tableName, hidden }) => {
const handleClick = useCallback(
(event: MouseEvent) => {
event.stopPropagation()
!hidden ? addHiddenNode(tableName) : removeHiddenNode(tableName)
updateNode(tableName, (node) => ({ ...node, hidden: !node.hidden }))
},
[updateNode, tableName],
[updateNode, tableName, hidden],
)

return (
Expand Down

0 comments on commit ed41c2e

Please sign in to comment.