From 10aa15c4a3eaff0c9a662df6e2a9015fe446f582 Mon Sep 17 00:00:00 2001 From: braks <78412429+bcakmakoglu@users.noreply.github.com> Date: Tue, 18 Oct 2022 08:59:11 +0200 Subject: [PATCH] chore(nc-gui): replace flatMap with arr reduce --- packages/nc-gui/components/erd/utils.ts | 44 ++++++++++++++----------- 1 file changed, 25 insertions(+), 19 deletions(-) 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() {