diff --git a/packages/nc-gui/components/erd/utils.ts b/packages/nc-gui/components/erd/utils.ts index ad4c0d13d1..d876673a0a 100644 --- a/packages/nc-gui/components/erd/utils.ts +++ b/packages/nc-gui/components/erd/utils.ts @@ -48,7 +48,7 @@ const nodeWidth = 300 const nodeHeight = 50 export function useErdElements(tables: MaybeRef, props: MaybeRef) { - const elements = ref([]) + const elements = ref>([]) const { theme } = useTheme() @@ -170,13 +170,9 @@ export function useErdElements(tables: MaybeRef, props: MaybeRef config.showAllColumns || (!config.showAllColumns && col.uidt === UITypes.LinkToAnotherRecord), ) || [] - const pkAndFkColumns = columns - .filter(() => config.showPkAndFk && config.showAllColumns) - .filter((col) => col.pk || col.uidt === UITypes.ForeignKey) + const pkAndFkColumns = columns.filter(() => config.showPkAndFk).filter((col) => col.pk || col.uidt === UITypes.ForeignKey) - const nonPkColumns = columns - .filter((col) => config.showAllColumns || (!config.showAllColumns && col.uidt === UITypes.LinkToAnotherRecord)) - .filter((col: ColumnType) => !col.pk && col.uidt !== UITypes.ForeignKey) + const nonPkColumns = columns.filter((col) => !col.pk && col.uidt !== UITypes.ForeignKey) return [ { @@ -187,7 +183,8 @@ export function useErdElements(tables: MaybeRef, props: MaybeRef, props: MaybeRef, props: MaybeRef, props: MaybeRef() - - elements.value.forEach((el) => { - if (isEdge(el)) { - connectedNodes.add(el.source) - connectedNodes.add(el.target) - } - }) - - const nonConnectedNodes = erdTables.value.filter((table) => !connectedNodes.has(table.id!)) - - if (nonConnectedNodes.length === 0) return - - if (nonConnectedNodes.length === 1) { - const firstTable = erdTables.value.find((table) => table.type === 'table' && table.id !== nonConnectedNodes[0].id) - if (!firstTable) return - - dagreGraph.setEdge(nonConnectedNodes[0].id!, firstTable.id!) - return - } - - const firstNode = nonConnectedNodes[0] - nonConnectedNodes.forEach((node, index) => { - if (index === 0) return - - const source = firstNode.id! - const target = node.id! - - dagreGraph.setEdge(source, target) - }) - } - const layout = (skeleton = false) => { elements.value = [...createNodes(), ...createEdges()] as Elements elements.value.forEach((el) => { if (isNode(el)) { + const node = el as Node + const colLength = node.data!.columnLength + + const width = skeleton ? nodeWidth * 3 : nodeWidth + const height = nodeHeight + (skeleton ? 250 : colLength > 0 ? nodeHeight * colLength : nodeHeight) dagreGraph.setNode(el.id, { - width: skeleton ? nodeWidth * 2.5 : nodeWidth, - height: nodeHeight + (skeleton ? 250 : nodeHeight * el.data.columnLength), + width, + height, }) } else if (isEdge(el)) { - // avoid duplicate edges when using skeleton - if ((skeleton && !dagreGraph.edge(el.source, el.target)) || !skeleton) { - dagreGraph.setEdge(el.source, el.target) - } + dagreGraph.setEdge(el.source, el.target) } }) @@ -321,7 +286,7 @@ export function useErdElements(tables: MaybeRef, props: MaybeRef nodes.id === el.source) if (node) { - const color = node.data.color + const color = node.data!.color el.data.color = color ;(el.markerEnd as EdgeMarker).color = skeleton ? `#${tinycolor(color).toHex()}` : undefined }