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: Minor refactoring of ERDContent #287

Merged
merged 3 commits into from
Dec 17, 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
6 changes: 6 additions & 0 deletions frontend/.changeset/unlucky-cycles-reflect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@liam-hq/erd-core": patch
"@liam-hq/cli": patch
---

Minor refactoring of ERDContent
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ type Props = {
| undefined
}

const highlightEdge = (edge: Edge): Edge => ({
...edge,
animated: true,
data: { ...edge.data, isHighlighted: true },
})

const unhighlightEdge = (edge: Edge): Edge => ({
...edge,
animated: false,
data: { ...edge.data, isHighlighted: false },
})

export const isRelatedToTable = (
relationships: Relationships,
tableName: string,
Expand Down Expand Up @@ -80,13 +92,7 @@ export const ERDContentInner: FC<Props> = ({
)

const updatedEdges = edges.map((e) =>
relatedEdges.includes(e)
? { ...e, animated: true, data: { ...e.data, isHighlighted: true } }
: {
...e,
animated: false,
data: { ...e.data, isHighlighted: false },
},
relatedEdges.includes(e) ? highlightEdge(e) : unhighlightEdge(e),
)

const updatedNodes = nodes.map((node) => {
Expand Down Expand Up @@ -136,11 +142,7 @@ export const ERDContentInner: FC<Props> = ({
const handlePaneClick = useCallback(() => {
setActiveNodeId(null)

const updatedEdges = edges.map((e) => ({
...e,
animated: false,
data: { ...e.data, isHighlighted: false },
}))
const updatedEdges = edges.map(unhighlightEdge)

const updatedNodes = nodes.map((node) => ({
...node,
Expand All @@ -163,9 +165,7 @@ export const ERDContentInner: FC<Props> = ({
)

const updatedEdges = edges.map((e) =>
relatedEdges.includes(e)
? { ...e, animated: true, data: { ...e.data, isHighlighted: true } }
: e,
relatedEdges.includes(e) ? highlightEdge(e) : e,
)

const updatedNodes = nodes.map((node) => {
Expand Down Expand Up @@ -212,17 +212,7 @@ export const ERDContentInner: FC<Props> = ({
(e) => e.source === activeNodeId || e.target === activeNodeId,
)
const updatedEdges = edges.map((e) =>
relatedEdges.includes(e)
? {
...e,
animated: true,
data: { ...e.data, isHighlighted: true },
}
: {
...e,
animated: false,
data: { ...e.data, isHighlighted: false },
},
relatedEdges.includes(e) ? highlightEdge(e) : unhighlightEdge(e),
)
setEdges(updatedEdges)

Expand Down Expand Up @@ -277,13 +267,7 @@ export const ERDContentInner: FC<Props> = ({
setNodes(updatedNodes)
} else {
const updatedEdges = edges.map((e) =>
e.source === id || e.target === id
? {
...e,
animated: false,
data: { ...e.data, isHighlighted: false },
}
: e,
e.source === id || e.target === id ? unhighlightEdge(e) : e,
)
setEdges(updatedEdges)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const TableNode: FC<Props> = ({ data }) => {
const { relationships } = useDBStructureStore()
const {
active: { tableName },
showMode,
} = useUserEditingStore()

const isActive = tableName === data.table.name
Expand All @@ -29,8 +30,6 @@ export const TableNode: FC<Props> = ({ data }) => {
data.isRelated ||
isRelatedToTable(relationships, data.table.name, tableName)

const { showMode } = useUserEditingStore()

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