-
-
-
{{ $t('objects.table') }}
-
-
-
-
{{ $t('objects.sqlVIew') }}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
{{ $t('objects.table') }}
+
+
+
+
{{ $t('objects.sqlVIew') }}
+
-
-
+
+
diff --git a/packages/nc-gui/components/erd/View.vue b/packages/nc-gui/components/erd/View.vue
index b4f52e1ee4..a522b08b95 100644
--- a/packages/nc-gui/components/erd/View.vue
+++ b/packages/nc-gui/components/erd/View.vue
@@ -7,7 +7,7 @@ const { table } = defineProps<{ table?: TableType }>()
const { includeM2M } = useGlobal()
const { tables: projectTables } = useProject()
-
+const tables = ref
([])
const { metas, getMeta } = useMetas()
let isLoading = $ref(true)
@@ -23,39 +23,34 @@ const config = ref({
showJunctionTableNames: false,
})
-const tables = computed(() => {
+const loadMetaOfTablesNotInMetas = async (localTables: TableType[]) => {
+ await Promise.all(
+ localTables
+ .filter((table) => !metas.value[table.id!])
+ .map(async (table) => {
+ await getMeta(table.id!)
+ }),
+ )
+}
+
+const populateTables = async () => {
+ let localTables: TableType[] = []
if (table) {
// if table is provided only get the table and its related tables
- return projectTables.value.filter(
+ localTables = projectTables.value.filter(
(t) =>
t.id === table.id ||
table.columns?.find(
(column) => column.uidt === UITypes.LinkToAnotherRecord && column?.colOptions?.fk_related_model_id === t.id,
),
)
+ } else {
+ localTables = projectTables.value
}
- return projectTables.value
-})
-
-const loadMetaOfTablesNotInMetas = async () => {
- await Promise.all(
- tables.value
- .filter((table) => !metas.value[table.id!])
- .map(async (table) => {
- await getMeta(table.id!)
- }),
- )
-}
-
-onMounted(async () => {
- await loadMetaOfTablesNotInMetas()
+ await loadMetaOfTablesNotInMetas(localTables)
- isLoading = false
-})
-
-const tablesFilteredWithConfig = computed(() =>
- tables.value
+ tables.value = localTables
.filter(
(t) =>
config.value.showMMTables ||
@@ -63,26 +58,34 @@ const tablesFilteredWithConfig = computed(() =>
// Show mm table if its the selected table
t.id === table?.id,
)
- .filter((t) => (!config.value.showViews && t.type !== 'view') || config.value.showViews),
-)
+ .filter((t) => (!config.value.showViews && t.type !== 'view') || config.value.showViews)
+
+ isLoading = false
+}
watch(
- () => config.value.showAllColumns,
- () => {
- config.value.showPkAndFk = config.value.showAllColumns
+ [config, metas],
+ async () => {
+ await populateTables()
+ },
+ {
+ deep: true,
},
)
-watch(metas, () => {
- erdKey.value = erdKey.value + 1
-})
+watch(
+ [projectTables],
+ async () => {
+ await populateTables()
+ },
+ { immediate: true },
+)
watch(
- config,
+ () => config.value.showAllColumns,
() => {
- erdKey.value = erdKey.value + 1
+ config.value.showPkAndFk = config.value.showAllColumns
},
- { deep: true },
)
@@ -101,7 +104,7 @@ watch(