From 9117f76e5bc321ba325639b0052209aaae1d191d Mon Sep 17 00:00:00 2001 From: braks <78412429+bcakmakoglu@users.noreply.github.com> Date: Thu, 21 Jul 2022 19:29:52 +0200 Subject: [PATCH 1/3] refactor(gui-v2): move injection keys to context dir # What's changed? * avoids naming collision with `components.d.ts` --- packages/nc-gui-v2/{components => context}/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename packages/nc-gui-v2/{components => context}/index.ts (96%) diff --git a/packages/nc-gui-v2/components/index.ts b/packages/nc-gui-v2/context/index.ts similarity index 96% rename from packages/nc-gui-v2/components/index.ts rename to packages/nc-gui-v2/context/index.ts index b6070aa3c4..f03f1c0429 100644 --- a/packages/nc-gui-v2/components/index.ts +++ b/packages/nc-gui-v2/context/index.ts @@ -1,7 +1,7 @@ import type { ColumnType, TableType, ViewType } from 'nocodb-sdk' import type { InjectionKey, Ref } from 'vue' import type { EventHook } from '@vueuse/core' -import type useViewData from '~/composables/useViewData' +import type { useViewData } from '#imports' export const ColumnInj: InjectionKey = Symbol('column-injection') export const MetaInj: InjectionKey> = Symbol('meta-injection') From 061d89b89e09021f39ec502ed691a30f422f0f8c Mon Sep 17 00:00:00 2001 From: braks <78412429+bcakmakoglu@users.noreply.github.com> Date: Thu, 21 Jul 2022 19:30:21 +0200 Subject: [PATCH 2/3] refactor(gui-v2): accept projectID as argument for `useProject` --- packages/nc-gui-v2/composables/useProject.ts | 33 +++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/packages/nc-gui-v2/composables/useProject.ts b/packages/nc-gui-v2/composables/useProject.ts index 1df977267a..ed3eb1464c 100644 --- a/packages/nc-gui-v2/composables/useProject.ts +++ b/packages/nc-gui-v2/composables/useProject.ts @@ -1,17 +1,19 @@ import { SqlUiFactory } from 'nocodb-sdk' import type { ProjectType, TableType } from 'nocodb-sdk' +import type { MaybeRef } from '@vueuse/core' import { useNuxtApp, useState } from '#app' import { USER_PROJECT_ROLES } from '~/lib/constants' -export default () => { +export default (projectId?: MaybeRef) => { const projectRoles = useState>(USER_PROJECT_ROLES, () => ({})) - const { $api } = useNuxtApp() + const _projectId = $computed(() => unref(projectId)) + const project = useState('project') - const tables = useState('tables') + const tables = useState('tables', () => [] as TableType[]) - const loadProjectRoles = async () => { + async function loadProjectRoles() { projectRoles.value = {} if (project.value.id) { @@ -19,21 +21,30 @@ export default () => { projectRoles.value = user.roles } } - const loadTables = async () => { + async function loadTables() { if (project.value.id) { const tablesResponse = await $api.dbTable.list(project.value.id) if (tablesResponse.list) tables.value = tablesResponse.list } } - const loadProject = async (projectId: string) => { - project.value = await $api.project.read(projectId) + async function loadProject(id: string) { + project.value = await $api.project.read(id) await loadProjectRoles() } - const isMysql = computed(() => ['mysql', 'mysql2'].includes(project.value?.bases?.[0]?.type || '')) - const isPg = computed(() => project.value?.bases?.[0]?.type === 'pg') - const sqlUi = computed(() => SqlUiFactory.create({ client: project.value?.bases?.[0]?.type || '' })) + watchEffect(async () => { + if (_projectId) { + await loadProject(_projectId) + await loadTables() + } + }) + + const projectBaseType = $computed(() => project.value?.bases?.[0]?.type || '') + + const isMysql = computed(() => ['mysql', 'mysql2'].includes(projectBaseType)) + const isPg = computed(() => projectBaseType === 'pg') + const sqlUi = computed(() => SqlUiFactory.create({ client: projectBaseType })) - return { project, tables, loadProject, loadTables, isMysql, isPg, sqlUi } + return { project, tables, loadProjectRoles, loadProject, loadTables, isMysql, isPg, sqlUi } } From f8d95aa9664c147ad134afdfa24511b5057bfc03 Mon Sep 17 00:00:00 2001 From: braks <78412429+bcakmakoglu@users.noreply.github.com> Date: Thu, 21 Jul 2022 19:33:13 +0200 Subject: [PATCH 3/3] refactor(gui-v2): import composables from `#imports` path --- packages/nc-gui-v2/components/cell/Attachment.vue | 5 ++--- packages/nc-gui-v2/components/cell/Checkbox.vue | 2 +- .../nc-gui-v2/components/cell/DateTimePicker.vue | 3 +-- packages/nc-gui-v2/components/cell/Duration.vue | 2 +- packages/nc-gui-v2/components/cell/MultiSelect.vue | 2 +- packages/nc-gui-v2/components/cell/Rating.vue | 2 +- packages/nc-gui-v2/components/cell/SingleSelect.vue | 2 +- packages/nc-gui-v2/components/cell/Url.vue | 2 +- packages/nc-gui-v2/components/dashboard/TreeView.vue | 3 +-- packages/nc-gui-v2/components/dlg/TableCreate.vue | 4 +--- packages/nc-gui-v2/components/dlg/ViewCreate.vue | 2 +- .../nc-gui-v2/components/smartsheet-header/Cell.vue | 2 +- .../components/smartsheet-header/CellIcon.vue | 2 +- .../components/smartsheet-header/VirtualCell.vue | 2 +- .../components/smartsheet-header/VirtualCellIcon.vue | 2 +- .../components/smartsheet-toolbar/ColumnFilter.vue | 2 +- .../smartsheet-toolbar/ColumnFilterMenu.vue | 2 +- .../FieldListAutoCompleteDropdown.vue | 2 +- .../components/smartsheet-toolbar/FieldsMenu.vue | 2 +- .../components/smartsheet-toolbar/SortListMenu.vue | 2 +- packages/nc-gui-v2/components/smartsheet/Cell.vue | 2 +- packages/nc-gui-v2/components/smartsheet/Gallery.vue | 2 +- packages/nc-gui-v2/components/smartsheet/Grid.vue | 2 +- .../nc-gui-v2/components/smartsheet/Pagination.vue | 2 +- packages/nc-gui-v2/components/smartsheet/Sidebar.vue | 2 +- .../nc-gui-v2/components/smartsheet/VirtualCell.vue | 2 +- packages/nc-gui-v2/components/tabs/Smartsheet.vue | 2 +- .../nc-gui-v2/components/virtual-cell/BelongsTo.vue | 2 +- .../nc-gui-v2/components/virtual-cell/Formula.vue | 5 +++-- .../nc-gui-v2/components/virtual-cell/HasMany.vue | 2 +- .../nc-gui-v2/components/virtual-cell/ManyToMany.vue | 2 +- .../components/virtual-cell/components/ItemChip.vue | 2 +- packages/nc-gui-v2/composables/useColumn.ts | 2 +- packages/nc-gui-v2/composables/useMetas.ts | 2 +- packages/nc-gui-v2/composables/useTableCreate.ts | 1 + packages/nc-gui-v2/composables/useViewData.ts | 2 +- packages/nc-gui-v2/pages/nc/[projectId].vue | 12 ++---------- 37 files changed, 41 insertions(+), 52 deletions(-) diff --git a/packages/nc-gui-v2/components/cell/Attachment.vue b/packages/nc-gui-v2/components/cell/Attachment.vue index e78c0d6d55..4f225160e3 100644 --- a/packages/nc-gui-v2/components/cell/Attachment.vue +++ b/packages/nc-gui-v2/components/cell/Attachment.vue @@ -1,9 +1,8 @@