From 83fb0717e6c04ee60734beea0c52dddfcd112d5e Mon Sep 17 00:00:00 2001 From: Muhammed Mustafa Date: Sun, 18 Sep 2022 00:52:47 +0530 Subject: [PATCH] feat(nc-gui): Fixed the rendering hack and some cleanup --- packages/nc-gui/components/erd/SimpleView.vue | 128 ++++++++++-------- packages/nc-gui/components/erd/View.vue | 81 +++++------ .../components/smartsheet-toolbar/Erd.vue | 46 ++++++- .../smartsheet-toolbar/ViewActions.vue | 15 +- 4 files changed, 160 insertions(+), 110 deletions(-) diff --git a/packages/nc-gui/components/erd/SimpleView.vue b/packages/nc-gui/components/erd/SimpleView.vue index 749d1de1c4..8d600328ea 100644 --- a/packages/nc-gui/components/erd/SimpleView.vue +++ b/packages/nc-gui/components/erd/SimpleView.vue @@ -1,6 +1,6 @@ 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(
- +
- {{ $t('activity.erd.showPkAndFk') }} + {{ $t('activity.erd.showPkAndFk') }}
- {{ $t('activity.erd.showSqlViews') }} + {{ $t('activity.erd.showSqlViews') }}
- {{ $t('activity.erd.showMMTables') }} + {{ $t('activity.erd.showMMTables') }}
- {{ $t('activity.erd.showJunctionTableNames') }} + {{ $t('activity.erd.showJunctionTableNames') }}
diff --git a/packages/nc-gui/components/smartsheet-toolbar/Erd.vue b/packages/nc-gui/components/smartsheet-toolbar/Erd.vue index 775dea64c5..fb26a67407 100644 --- a/packages/nc-gui/components/smartsheet-toolbar/Erd.vue +++ b/packages/nc-gui/components/smartsheet-toolbar/Erd.vue @@ -1,9 +1,49 @@ + + diff --git a/packages/nc-gui/components/smartsheet-toolbar/ViewActions.vue b/packages/nc-gui/components/smartsheet-toolbar/ViewActions.vue index f00bc6e715..5a8d0e2472 100644 --- a/packages/nc-gui/components/smartsheet-toolbar/ViewActions.vue +++ b/packages/nc-gui/components/smartsheet-toolbar/ViewActions.vue @@ -230,20 +230,7 @@ const { isSqlView } = useSmartsheetStoreOrThrow() - -
- - {{ `${$t('title.erdView')}: ${selectedView?.title}` }} - - - - - -
- -
+