diff --git a/packages/nc-gui/components/erd/utils.ts b/packages/nc-gui/components/erd/utils.ts index 384b140b70..68eb76464a 100644 --- a/packages/nc-gui/components/erd/utils.ts +++ b/packages/nc-gui/components/erd/utils.ts @@ -44,6 +44,12 @@ interface Relation { type: 'mm' | 'hm' } +/** + * This util is used to generate the ERD graph elements and layout them + * + * @param tables + * @param props + */ export function useErdElements(tables: MaybeRef, props: MaybeRef) { const elements = ref>([]) @@ -163,8 +169,8 @@ export function useErdElements(tables: MaybeRef, props: MaybeRef[]>((table) => { - if (!table.id) return [] + return erdTables.value.reduce[]>((acc, table) => { + if (!table.id) return acc const columns = metasWithIdAsKey.value[table.id].columns?.filter( @@ -175,23 +181,23 @@ export function useErdElements(tables: MaybeRef, props: MaybeRef !col.pk && col.uidt !== UITypes.ForeignKey) - return [ - { - id: table.id, - data: { - table: metasWithIdAsKey.value[table.id], - pkAndFkColumns, - nonPkColumns, - showPkAndFk: config.showPkAndFk, - showAllColumns: config.showAllColumns, - columnLength: columns.length, - color: '', - }, - type: 'custom', - position: { x: 0, y: 0 }, - } as Node, - ] - }) + acc.push({ + id: table.id, + data: { + table: metasWithIdAsKey.value[table.id], + pkAndFkColumns, + nonPkColumns, + showPkAndFk: config.showPkAndFk, + showAllColumns: config.showAllColumns, + columnLength: columns.length, + color: '', + }, + type: 'custom', + position: { x: 0, y: 0 }, + }) + + return acc + }, []) } function createEdges() {