Browse Source

chore(nc-gui): replace flatMap with arr reduce

pull/4071/head
braks 2 years ago
parent
commit
10aa15c4a3
  1. 18
      packages/nc-gui/components/erd/utils.ts

18
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<TableType[]>, props: MaybeRef<ERDConfig>) {
const elements = ref<Elements<NodeData | EdgeData>>([])
@ -163,8 +169,8 @@ export function useErdElements(tables: MaybeRef<TableType[]>, props: MaybeRef<ER
}
function createNodes() {
return erdTables.value.flatMap<Node<NodeData>[]>((table) => {
if (!table.id) return []
return erdTables.value.reduce<Node<NodeData>[]>((acc, table) => {
if (!table.id) return acc
const columns =
metasWithIdAsKey.value[table.id].columns?.filter(
@ -175,8 +181,7 @@ export function useErdElements(tables: MaybeRef<TableType[]>, props: MaybeRef<ER
const nonPkColumns = columns.filter((col) => !col.pk && col.uidt !== UITypes.ForeignKey)
return [
{
acc.push({
id: table.id,
data: {
table: metasWithIdAsKey.value[table.id],
@ -189,9 +194,10 @@ export function useErdElements(tables: MaybeRef<TableType[]>, props: MaybeRef<ER
},
type: 'custom',
position: { x: 0, y: 0 },
} as Node<NodeData>,
]
})
return acc
}, [])
}
function createEdges() {

Loading…
Cancel
Save