From 1f29380b7a88399ee760bcc803f8ef41abc48e3a Mon Sep 17 00:00:00 2001 From: Muhammed Mustafa Date: Thu, 15 Sep 2022 10:44:18 +0530 Subject: [PATCH] feat/Minor cleanup --- packages/nc-gui/components/erd/TableNode.vue | 2 +- packages/nc-gui/components/erd/View.vue | 12 ++++++------ packages/nc-gui/composables/useMetas.ts | 6 ++++-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/packages/nc-gui/components/erd/TableNode.vue b/packages/nc-gui/components/erd/TableNode.vue index 75ac809349..236549125c 100644 --- a/packages/nc-gui/components/erd/TableNode.vue +++ b/packages/nc-gui/components/erd/TableNode.vue @@ -14,7 +14,7 @@ const { data } = toRefs(props) provide(MetaInj, data) const columns = computed(() => { - // Hide hm related created for `mm` relations + // Hide hm ltar created for `mm` relations return data.value.columns.filter((col) => !(col.uidt === UITypes.LinkToAnotherRecord && col.system === 1)) }) diff --git a/packages/nc-gui/components/erd/View.vue b/packages/nc-gui/components/erd/View.vue index b1ac75f7a4..e377dd1fbb 100644 --- a/packages/nc-gui/components/erd/View.vue +++ b/packages/nc-gui/components/erd/View.vue @@ -16,7 +16,7 @@ interface Props { const { tables, config } = defineProps() -const { metasWithId } = useMetas() +const { metasWithIdAsKey } = useMetas() const initialNodes = ref[]>([]) const nodes = ref([]) @@ -29,11 +29,11 @@ const populateInitalNodes = () => { tables.forEach((table) => { if (!table.id) return - dagreGraph.setNode(table.id, { width: 250, height: 50 * metasWithId.value[table.id].columns.length }) + dagreGraph.setNode(table.id, { width: 250, height: 50 * metasWithIdAsKey.value[table.id].columns.length }) initialNodes.value.push({ id: table.id, - data: { ...metasWithId.value[table.id], showPkAndFk: config.showPkAndFk }, + data: { ...metasWithIdAsKey.value[table.id], showPkAndFk: config.showPkAndFk }, type: 'custom', }) }) @@ -43,10 +43,10 @@ const populateInitalNodes = () => { const populateEdges = () => { const ltarColumns = tables.reduce((acc: any[], table) => { - const meta = metasWithId.value[table.id!] - const ltarColumns = meta.columns.filter((column: any) => column.uidt === UITypes.LinkToAnotherRecord && column.system !== 1) + const meta = metasWithIdAsKey.value[table.id!] + const columns = meta.columns.filter((column: any) => column.uidt === UITypes.LinkToAnotherRecord && column.system !== 1) - ltarColumns.forEach((column: any) => { + columns.forEach((column: any) => { if (column.colOptions.type === 'hm') { acc.push(column) } diff --git a/packages/nc-gui/composables/useMetas.ts b/packages/nc-gui/composables/useMetas.ts index 67c5c719fc..aa9708c77b 100644 --- a/packages/nc-gui/composables/useMetas.ts +++ b/packages/nc-gui/composables/useMetas.ts @@ -10,10 +10,12 @@ export function useMetas() { const { tables } = useProject() const metas = useState<{ [idOrTitle: string]: TableType | any }>('metas', () => ({})) - const metasWithId = computed(() => { + + const metasWithIdAsKey = computed(() => { const idEntries = Object.entries(metas.value).filter(([k, v]) => k === v.id) return Object.fromEntries(idEntries) }) + const loadingState = useState>('metas-loading-state', () => ({})) const setMeta = async (model: any) => { @@ -95,5 +97,5 @@ export function useMetas() { } } - return { getMeta, clearAllMeta, metas, metasWithId, removeMeta, setMeta } + return { getMeta, clearAllMeta, metas, metasWithIdAsKey, removeMeta, setMeta } }