diff --git a/frontend/packages/erd-core/src/components/ERDRenderer/ERDContent/TableNode/TableColumnList/TableColumnList.tsx b/frontend/packages/erd-core/src/components/ERDRenderer/ERDContent/TableNode/TableColumnList/TableColumnList.tsx index 3c7c6b68..a2fa9640 100644 --- a/frontend/packages/erd-core/src/components/ERDRenderer/ERDContent/TableNode/TableColumnList/TableColumnList.tsx +++ b/frontend/packages/erd-core/src/components/ERDRenderer/ERDContent/TableNode/TableColumnList/TableColumnList.tsx @@ -1,4 +1,4 @@ -import type { Relationships } from '@liam-hq/db-structure' +import type { Column } from '@liam-hq/db-structure' import type { FC } from 'react' import { columnHandleId } from '../../../columnHandleId' import type { Data } from '../type' @@ -7,34 +7,30 @@ import { TableColumn } from './TableColumn' type TableColumnListProps = { data: Data filter?: 'KEY_ONLY' - relationships: Relationships } -export const TableColumnList: FC = ({ - data, - filter, - relationships, -}) => { - const foreignKeyColumns = Object.values(data.table.columns).filter((column) => - Object.values(relationships).some( - (rel) => - rel.foreignTableName === data.table.name && - rel.foreignColumnName === column.name, - ), - ) - - const primaryColumns = Object.values(data.table.columns).filter((column) => { - return column.primary - }) - - const columns = - filter === 'KEY_ONLY' - ? primaryColumns.concat(foreignKeyColumns) - : Object.values(data.table.columns) +const shouldDisplayColumn = ( + column: Column, + filter: 'KEY_ONLY' | undefined, + targetColumnCardinalities: Data['targetColumnCardinalities'], +): boolean => { + if (filter === 'KEY_ONLY') { + return ( + column.primary || targetColumnCardinalities?.[column.name] !== undefined + ) + } + return true +} +export const TableColumnList: FC = ({ data, filter }) => { return (