diff --git a/packages/nc-gui/components/erd/TableNode.vue b/packages/nc-gui/components/erd/TableNode.vue index 886252e9df..067719679b 100644 --- a/packages/nc-gui/components/erd/TableNode.vue +++ b/packages/nc-gui/components/erd/TableNode.vue @@ -3,41 +3,30 @@ import type { NodeProps } from '@vue-flow/core' import { Handle, Position } from '@vue-flow/core' import type { ColumnType, LinkToAnotherRecordType, TableType } from 'nocodb-sdk' import { UITypes, isVirtualCol } from 'nocodb-sdk' -import type { Ref } from 'vue' -import { MetaInj, computed, provide, toRefs, useNuxtApp } from '#imports' +import { MetaInj, provide, toRef, useNuxtApp } from '#imports' + +interface NodeData { + table: TableType + pkAndFkColumns: ColumnType[] + nonPkColumns: ColumnType[] + showPkAndFk: boolean + showAllColumns: boolean + color: string +} -interface Props extends NodeProps { - data: TableType & { showPkAndFk: boolean; showAllColumns: boolean; color: string } +interface Props extends NodeProps { + data: NodeData showSkeleton: boolean } -const props = defineProps() +const { data, showSkeleton } = defineProps() -const { data } = toRefs(props) +const table = toRef(data, 'table') -provide(MetaInj, data as Ref) +provide(MetaInj, table) const { $e } = useNuxtApp() -const columns = computed(() => { - // Hide hm ltar created for `mm` relations - return data.value.columns?.filter((col) => !(col.uidt === UITypes.LinkToAnotherRecord && col.system === 1)) -}) - -const pkAndFkColumns = computed(() => { - return columns.value - ?.filter(() => data.value.showPkAndFk && data.value.showAllColumns) - .filter((col) => col.pk || col.uidt === UITypes.ForeignKey) -}) - -const nonPkColumns = computed(() => { - return columns.value - ?.filter( - (col: ColumnType) => data.value.showAllColumns || (!data.value.showAllColumns && col.uidt === UITypes.LinkToAnotherRecord), - ) - .filter((col: ColumnType) => !col.pk && col.uidt !== UITypes.ForeignKey) -}) - const relatedColumnId = (colOptions: LinkToAnotherRecordType | any) => colOptions.type === 'mm' ? colOptions.fk_parent_column_id : colOptions.fk_child_column_id @@ -46,23 +35,23 @@ const relatedColumnId = (colOptions: LinkToAnotherRecordType | any) =>
- +
- +
- {{ data.title }} + {{ table.title }}
@@ -72,30 +61,30 @@ const relatedColumnId = (colOptions: LinkToAnotherRecordType | any) =>
-
+
-
+
-
+
/> v-else-if="isVirtualCol(col)" :column="col" :hide-menu="true" - :class="`nc-erd-table-node-${data.table_name}-column-${col.column_name}`" + :class="`nc-erd-table-node-${table.table_name}-column-${col.column_name}`" />
diff --git a/packages/nc-gui/components/erd/utils.ts b/packages/nc-gui/components/erd/utils.ts index 9214cb5667..781b1bd1c4 100644 --- a/packages/nc-gui/components/erd/utils.ts +++ b/packages/nc-gui/components/erd/utils.ts @@ -27,7 +27,7 @@ interface Relation { } const nodeWidth = 300 -const nodeHeight = 50 +const nodeHeight = 35 export function useErdElements(tables: MaybeRef, props: MaybeRef) { const elements = ref([]) @@ -145,17 +145,27 @@ export function useErdElements(tables: MaybeRef, props: MaybeRef config.showAllColumns || (!config.showAllColumns && col.uidt === UITypes.LinkToAnotherRecord), + (col) => !(col.uidt === UITypes.LinkToAnotherRecord && col.system === 1), ) || [] + const pkAndFkColumns = columns + .filter(() => config.showPkAndFk && config.showAllColumns) + .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) + return [ { id: table.id, data: { - ...metasWithIdAsKey.value[table.id], + table: metasWithIdAsKey.value[table.id], + pkAndFkColumns, + nonPkColumns, showPkAndFk: config.showPkAndFk, showAllColumns: config.showAllColumns, - columnLength: columns.length, + columnLength: pkAndFkColumns.length + nonPkColumns.length, }, type: 'custom', position: { x: 0, y: 0 }, @@ -254,11 +264,9 @@ export function useErdElements(tables: MaybeRef, props: MaybeRef { if (isNode(el)) { - console.log(el.data.columnLength) - dagreGraph.setNode(el.id, { width: skeleton ? nodeWidth * 2.5 : nodeWidth, - height: nodeHeight + (skeleton ? 250 : nodeHeight * el.data.columnLength), + height: 50 + (skeleton ? 250 : nodeHeight * el.data.columnLength), }) } else if (isEdge(el)) { // avoid duplicate edges when using skeleton