Browse Source

fix(nc-gui): Fixed ERD view for non opened projects

pull/6565/head
Muhammed Mustafa 1 year ago
parent
commit
39f9c03ed3
  1. 1
      packages/nc-gui/components/dashboard/TreeView/ProjectNode.vue
  2. 34
      packages/nc-gui/components/dlg/ProjectErd.vue
  3. 10
      packages/nc-gui/components/erd/TableNode.vue
  4. 11
      packages/nc-gui/components/erd/View.vue
  5. 16
      packages/nc-gui/composables/useMetas.ts

1
packages/nc-gui/components/dashboard/TreeView/ProjectNode.vue

@ -297,6 +297,7 @@ function openErdView(source: SourceType) {
'modelValue': isOpen, 'modelValue': isOpen,
'sourceId': source!.id, 'sourceId': source!.id,
'onUpdate:modelValue': () => closeDialog(), 'onUpdate:modelValue': () => closeDialog(),
'baseId': base.value.id,
}) })
function closeDialog() { function closeDialog() {

34
packages/nc-gui/components/dlg/ProjectErd.vue

@ -1,5 +1,6 @@
<script lang="ts" setup> <script lang="ts" setup>
const props = defineProps<{ const props = defineProps<{
baseId: string
sourceId: string sourceId: string
modelValue: boolean modelValue: boolean
}>() }>()
@ -9,12 +10,43 @@ const emit = defineEmits(['update:modelValue'])
const isOpen = useVModel(props, 'modelValue', emit) const isOpen = useVModel(props, 'modelValue', emit)
const activeSourceId = computed(() => props.sourceId) const activeSourceId = computed(() => props.sourceId)
const { openedProject: base } = storeToRefs(useBases())
const { baseTables } = storeToRefs(useTablesStore())
const { loadProjectTables } = useTablesStore()
const isLoading = ref(true)
const { getMeta } = useMetas()
const baseId = computed(() => props.baseId || base.value?.id)
onMounted(async () => {
if (baseId.value && baseTables.value.get(baseId.value)) {
return (isLoading.value = false)
}
try {
await loadProjectTables(baseId.value!)
await Promise.all(
baseTables.value.get(baseId.value!)!.map(async (table) => {
await getMeta(table.id!, false, false, baseId.value!)
}),
)
} catch (e) {
console.error(e)
} finally {
isLoading.value = false
}
})
</script> </script>
<template> <template>
<GeneralModal v-model:visible="isOpen" size="large"> <GeneralModal v-model:visible="isOpen" size="large">
<div class="h-[80vh]"> <div class="h-[80vh]">
<LazyDashboardSettingsErd :source-id="activeSourceId" /> <ErdView v-if="!isLoading" :source-id="activeSourceId" :base-id="baseId" />
</div> </div>
</GeneralModal> </GeneralModal>
</template> </template>

10
packages/nc-gui/components/erd/TableNode.vue

@ -41,16 +41,6 @@ watch(
isZooming.value = true isZooming.value = true
}, },
) )
watch(
() => data,
() => {
console.log('data changed', data)
},
{
immediate: true,
},
)
</script> </script>
<template> <template>

11
packages/nc-gui/components/erd/View.vue

@ -17,9 +17,18 @@ const props = defineProps({
type: Boolean, type: Boolean,
default: true, default: true,
}, },
baseId: {
type: String,
default: '',
},
}) })
const { sources, tables: baseTables } = storeToRefs(useBase()) const { baseTables: _baseTables } = storeToRefs(useTablesStore())
const { sources, base } = storeToRefs(useBase())
const baseId = computed(() => props.baseId ?? base.value!.id)
const baseTables = computed(() => _baseTables.value.get(baseId.value) ?? [])
const { metas, getMeta } = useMetas() const { metas, getMeta } = useMetas()

16
packages/nc-gui/composables/useMetas.ts

@ -6,7 +6,8 @@ import { extractSdkResponseErrorMsg, storeToRefs, useBase, useNuxtApp, useState,
export function useMetas() { export function useMetas() {
const { $api } = useNuxtApp() const { $api } = useNuxtApp()
const { tables } = storeToRefs(useBase()) const { tables: _tables } = storeToRefs(useBase())
const { baseTables } = storeToRefs(useTablesStore())
const metas = useState<{ [idOrTitle: string]: TableType | any }>('metas', () => ({})) const metas = useState<{ [idOrTitle: string]: TableType | any }>('metas', () => ({}))
@ -26,8 +27,16 @@ export function useMetas() {
} }
// todo: this needs a proper refactor, arbitrary waiting times are usually not a good idea // todo: this needs a proper refactor, arbitrary waiting times are usually not a good idea
const getMeta = async (tableIdOrTitle: string, force = false, skipIfCacheMiss = false): Promise<TableType | null> => { const getMeta = async (
tableIdOrTitle: string,
force = false,
skipIfCacheMiss = false,
baseId?: string,
): Promise<TableType | null> => {
if (!tableIdOrTitle) return null if (!tableIdOrTitle) return null
const tables = (baseId ? baseTables.value.get(baseId) : _tables.value) ?? []
/** wait until loading is finished if requesting same meta /** wait until loading is finished if requesting same meta
* use while to recheck loading state since it can be changed by other requests * use while to recheck loading state since it can be changed by other requests
* */ * */
@ -72,8 +81,7 @@ export function useMetas() {
return metas.value[tableIdOrTitle] return metas.value[tableIdOrTitle]
} }
const modelId = (tables.value.find((t) => t.id === tableIdOrTitle) || tables.value.find((t) => t.title === tableIdOrTitle)) const modelId = (tables.find((t) => t.id === tableIdOrTitle) || tables.find((t) => t.title === tableIdOrTitle))?.id
?.id
if (!modelId) { if (!modelId) {
console.warn(`Table '${tableIdOrTitle}' is not found in the table list`) console.warn(`Table '${tableIdOrTitle}' is not found in the table list`)

Loading…
Cancel
Save