Browse Source

Merge pull request #2803 from nocodb/refactor/useProject

refactor(gui-v2): move injection keys to context dir
pull/2812/head
Pranav C 2 years ago committed by GitHub
parent
commit
49b7b98630
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      packages/nc-gui-v2/components/cell/Attachment.vue
  2. 2
      packages/nc-gui-v2/components/cell/Checkbox.vue
  3. 3
      packages/nc-gui-v2/components/cell/DateTimePicker.vue
  4. 2
      packages/nc-gui-v2/components/cell/Duration.vue
  5. 2
      packages/nc-gui-v2/components/cell/MultiSelect.vue
  6. 2
      packages/nc-gui-v2/components/cell/Rating.vue
  7. 2
      packages/nc-gui-v2/components/cell/SingleSelect.vue
  8. 2
      packages/nc-gui-v2/components/cell/Url.vue
  9. 3
      packages/nc-gui-v2/components/dashboard/TreeView.vue
  10. 4
      packages/nc-gui-v2/components/dlg/TableCreate.vue
  11. 2
      packages/nc-gui-v2/components/dlg/ViewCreate.vue
  12. 2
      packages/nc-gui-v2/components/smartsheet-header/Cell.vue
  13. 2
      packages/nc-gui-v2/components/smartsheet-header/CellIcon.vue
  14. 2
      packages/nc-gui-v2/components/smartsheet-header/VirtualCell.vue
  15. 2
      packages/nc-gui-v2/components/smartsheet-header/VirtualCellIcon.vue
  16. 2
      packages/nc-gui-v2/components/smartsheet-toolbar/ColumnFilter.vue
  17. 2
      packages/nc-gui-v2/components/smartsheet-toolbar/ColumnFilterMenu.vue
  18. 2
      packages/nc-gui-v2/components/smartsheet-toolbar/FieldListAutoCompleteDropdown.vue
  19. 2
      packages/nc-gui-v2/components/smartsheet-toolbar/FieldsMenu.vue
  20. 2
      packages/nc-gui-v2/components/smartsheet-toolbar/SortListMenu.vue
  21. 2
      packages/nc-gui-v2/components/smartsheet/Cell.vue
  22. 2
      packages/nc-gui-v2/components/smartsheet/Gallery.vue
  23. 2
      packages/nc-gui-v2/components/smartsheet/Grid.vue
  24. 2
      packages/nc-gui-v2/components/smartsheet/Pagination.vue
  25. 2
      packages/nc-gui-v2/components/smartsheet/Sidebar.vue
  26. 2
      packages/nc-gui-v2/components/smartsheet/VirtualCell.vue
  27. 2
      packages/nc-gui-v2/components/tabs/Smartsheet.vue
  28. 2
      packages/nc-gui-v2/components/virtual-cell/BelongsTo.vue
  29. 5
      packages/nc-gui-v2/components/virtual-cell/Formula.vue
  30. 2
      packages/nc-gui-v2/components/virtual-cell/HasMany.vue
  31. 2
      packages/nc-gui-v2/components/virtual-cell/ManyToMany.vue
  32. 2
      packages/nc-gui-v2/components/virtual-cell/components/ItemChip.vue
  33. 2
      packages/nc-gui-v2/composables/useColumn.ts
  34. 2
      packages/nc-gui-v2/composables/useMetas.ts
  35. 33
      packages/nc-gui-v2/composables/useProject.ts
  36. 1
      packages/nc-gui-v2/composables/useTableCreate.ts
  37. 2
      packages/nc-gui-v2/composables/useViewData.ts
  38. 2
      packages/nc-gui-v2/context/index.ts
  39. 10
      packages/nc-gui-v2/pages/nc/[projectId].vue

5
packages/nc-gui-v2/components/cell/Attachment.vue

@ -1,9 +1,8 @@
<script setup lang="ts"> <script setup lang="ts">
import { useToast } from 'vue-toastification' import { useToast } from 'vue-toastification'
import { inject, ref, watchEffect } from '#imports' import { inject, ref, useProject, watchEffect } from '#imports'
import { useNuxtApp } from '#app' import { useNuxtApp } from '#app'
import { ColumnInj, MetaInj } from '~/components' import { ColumnInj, MetaInj } from '~/context'
import useProject from '~/composables/useProject'
import { NOCO } from '~/lib/constants' import { NOCO } from '~/lib/constants'
import { isImage } from '~/utils/fileUtils' import { isImage } from '~/utils/fileUtils'
import MaterialPlusIcon from '~icons/mdi/plus' import MaterialPlusIcon from '~icons/mdi/plus'

2
packages/nc-gui-v2/components/cell/Checkbox.vue

@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import { computed, inject } from '#imports' import { computed, inject } from '#imports'
import { ColumnInj, IsFormInj } from '~/components' import { ColumnInj, IsFormInj } from '~/context'
interface Props { interface Props {
modelValue?: boolean | undefined | number modelValue?: boolean | undefined | number

3
packages/nc-gui-v2/components/cell/DateTimePicker.vue

@ -1,7 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import dayjs from 'dayjs' import dayjs from 'dayjs'
import { computed, ref } from '#imports' import { computed, ref, useProject } from '#imports'
import useProject from '~/composables/useProject'
interface Props { interface Props {
modelValue?: string modelValue?: string

2
packages/nc-gui-v2/components/cell/Duration.vue

@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import { computed, inject, ref } from '#imports' import { computed, inject, ref } from '#imports'
import { ColumnInj } from '~/components' import { ColumnInj } from '~/context'
import { convertDurationToSeconds, convertMS2Duration, durationOptions } from '~/utils/durationHelper' import { convertDurationToSeconds, convertMS2Duration, durationOptions } from '~/utils/durationHelper'
interface Props { interface Props {

2
packages/nc-gui-v2/components/cell/MultiSelect.vue

@ -1,6 +1,6 @@
<script lang="ts" setup> <script lang="ts" setup>
import { computed, inject } from '#imports' import { computed, inject } from '#imports'
import { ColumnInj } from '~/components' import { ColumnInj } from '~/context'
interface Props { interface Props {
modelValue: string modelValue: string

2
packages/nc-gui-v2/components/cell/Rating.vue

@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import { computed, inject } from '#imports' import { computed, inject } from '#imports'
import { ColumnInj, IsFormInj } from '~/components' import { ColumnInj, IsFormInj } from '~/context'
import MdiStarIcon from '~icons/mdi/star' import MdiStarIcon from '~icons/mdi/star'
import MdiStarOutlineIcon from '~icons/mdi/star-outline' import MdiStarOutlineIcon from '~icons/mdi/star-outline'

2
packages/nc-gui-v2/components/cell/SingleSelect.vue

@ -1,6 +1,6 @@
<script lang="ts" setup> <script lang="ts" setup>
import { computed, inject } from '#imports' import { computed, inject } from '#imports'
import { ColumnInj } from '~/components' import { ColumnInj } from '~/context'
interface Props { interface Props {
modelValue: string modelValue: string

2
packages/nc-gui-v2/components/cell/Url.vue

@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import { computed, ref } from '#imports' import { computed, ref } from '#imports'
import { ColumnInj } from '~/components' import { ColumnInj } from '~/context'
import { isValidURL } from '~/utils/urlUtils' import { isValidURL } from '~/utils/urlUtils'
interface Props { interface Props {

3
packages/nc-gui-v2/components/dashboard/TreeView.vue

@ -1,6 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import useProject from '~/composables/useProject' import { useProject, useTabs } from '#imports'
import useTabs from '~/composables/useTabs'
import MdiSettingIcon from '~icons/mdi/cog' import MdiSettingIcon from '~icons/mdi/cog'
const { tables } = useProject() const { tables } = useProject()

4
packages/nc-gui-v2/components/dlg/TableCreate.vue

@ -1,8 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import { onMounted } from '@vue/runtime-core' import { onMounted } from '@vue/runtime-core'
import useTableCreate from '../../composables/useTableCreate' import { useProject, useTableCreate, useTabs } from '#imports'
import useProject from '~/composables/useProject'
import useTabs from '~/composables/useTabs'
import { validateTableName } from '~/utils/validation' import { validateTableName } from '~/utils/validation'
const { modelValue = false } = defineProps<{ modelValue?: boolean }>() const { modelValue = false } = defineProps<{ modelValue?: boolean }>()

2
packages/nc-gui-v2/components/dlg/ViewCreate.vue

@ -3,7 +3,7 @@ import { inject } from '@vue/runtime-core'
import type { TableType } from 'nocodb-sdk' import type { TableType } from 'nocodb-sdk'
import { ViewTypes } from 'nocodb-sdk' import { ViewTypes } from 'nocodb-sdk'
import type { Ref } from '#imports' import type { Ref } from '#imports'
import { ActiveViewInj, MetaInj, ViewListInj } from '~/components' import { ActiveViewInj, MetaInj, ViewListInj } from '~/context'
import useViewCreate from '~/composables/useViewCreate' import useViewCreate from '~/composables/useViewCreate'
const { modelValue, type } = defineProps<{ type: ViewTypes; modelValue: boolean }>() const { modelValue, type } = defineProps<{ type: ViewTypes; modelValue: boolean }>()

2
packages/nc-gui-v2/components/smartsheet-header/Cell.vue

@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import type { ColumnType } from 'nocodb-sdk' import type { ColumnType } from 'nocodb-sdk'
import { ColumnInj } from '../index' import { ColumnInj } from '../../context'
const { column } = defineProps<{ column: ColumnType & { meta: any } }>() const { column } = defineProps<{ column: ColumnType & { meta: any } }>()
provide(ColumnInj, column) provide(ColumnInj, column)

2
packages/nc-gui-v2/components/smartsheet-header/CellIcon.vue

@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import type { ColumnType } from 'nocodb-sdk' import type { ColumnType } from 'nocodb-sdk'
import { ColumnInj } from '~/components' import { ColumnInj } from '~/context'
import useColumn from '~/composables/useColumn' import useColumn from '~/composables/useColumn'
import KeyIcon from '~icons/mdi/key-variant' import KeyIcon from '~icons/mdi/key-variant'
import JSONIcon from '~icons/mdi/code-json' import JSONIcon from '~icons/mdi/code-json'

2
packages/nc-gui-v2/components/smartsheet-header/VirtualCell.vue

@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import type { ColumnType } from 'nocodb-sdk' import type { ColumnType } from 'nocodb-sdk'
import { ColumnInj } from '../index' import { ColumnInj } from '../../context'
import { provide } from '#imports' import { provide } from '#imports'
const { column } = defineProps<{ column: ColumnType & { meta: any } }>() const { column } = defineProps<{ column: ColumnType & { meta: any } }>()

2
packages/nc-gui-v2/components/smartsheet-header/VirtualCellIcon.vue

@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import { LinkToAnotherRecordType, RelationTypes, UITypes } from "nocodb-sdk"; import { LinkToAnotherRecordType, RelationTypes, UITypes } from "nocodb-sdk";
import { ColumnInj } from '~/components' import { ColumnInj } from '~/context'
import GenericIcon from '~icons/mdi/square-rounded' import GenericIcon from '~icons/mdi/square-rounded'
import HMIcon from '~icons/mdi/table-arrow-right' import HMIcon from '~icons/mdi/table-arrow-right'
import BTIcon from '~icons/mdi/table-arrow-left' import BTIcon from '~icons/mdi/table-arrow-left'

2
packages/nc-gui-v2/components/smartsheet-toolbar/ColumnFilter.vue

@ -4,7 +4,7 @@ import FieldListAutoCompleteDropdown from './FieldListAutoCompleteDropdown.vue'
import { useNuxtApp } from '#app' import { useNuxtApp } from '#app'
import { inject } from '#imports' import { inject } from '#imports'
import { comparisonOpList } from '~/utils/filterUtils' import { comparisonOpList } from '~/utils/filterUtils'
import { ActiveViewInj, MetaInj, ReloadViewDataHookInj } from '~/components' import { ActiveViewInj, MetaInj, ReloadViewDataHookInj } from '~/context'
import useViewFilters from '~/composables/useViewFilters' import useViewFilters from '~/composables/useViewFilters'
import MdiDeleteIcon from '~icons/mdi/close-box' import MdiDeleteIcon from '~icons/mdi/close-box'

2
packages/nc-gui-v2/components/smartsheet-toolbar/ColumnFilterMenu.vue

@ -1,7 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
// todo: move to persisted state // todo: move to persisted state
import { useState } from '#app' import { useState } from '#app'
import { IsLockedInj } from '~/components' import { IsLockedInj } from '~/context'
import MdiFilterIcon from '~icons/mdi/filter-outline' import MdiFilterIcon from '~icons/mdi/filter-outline'
import MdiMenuDownIcon from '~icons/mdi/menu-down' import MdiMenuDownIcon from '~icons/mdi/menu-down'

2
packages/nc-gui-v2/components/smartsheet-toolbar/FieldListAutoCompleteDropdown.vue

@ -1,5 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import { MetaInj } from '~/components' import { MetaInj } from '~/context'
interface Props { interface Props {
modelValue?: string modelValue?: string

2
packages/nc-gui-v2/components/smartsheet-toolbar/FieldsMenu.vue

@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import { computed, inject } from 'vue' import { computed, inject } from 'vue'
import { ActiveViewInj, FieldsInj, IsLockedInj, MetaInj, ReloadViewDataHookInj } from '~/components' import { ActiveViewInj, FieldsInj, IsLockedInj, MetaInj, ReloadViewDataHookInj } from '~/context'
import useViewColumns from '~/composables/useViewColumns' import useViewColumns from '~/composables/useViewColumns'
import MdiMenuDownIcon from '~icons/mdi/menu-down' import MdiMenuDownIcon from '~icons/mdi/menu-down'
import MdiEyeIcon from '~icons/mdi/eye-off-outline' import MdiEyeIcon from '~icons/mdi/eye-off-outline'

2
packages/nc-gui-v2/components/smartsheet-toolbar/SortListMenu.vue

@ -1,7 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
import FieldListAutoCompleteDropdown from './FieldListAutoCompleteDropdown.vue' import FieldListAutoCompleteDropdown from './FieldListAutoCompleteDropdown.vue'
import { computed, inject } from '#imports' import { computed, inject } from '#imports'
import { ActiveViewInj, IsLockedInj, MetaInj, ReloadViewDataHookInj } from '~/components' import { ActiveViewInj, IsLockedInj, MetaInj, ReloadViewDataHookInj } from '~/context'
import useViewSorts from '~/composables/useViewSorts' import useViewSorts from '~/composables/useViewSorts'
import MdiMenuDownIcon from '~icons/mdi/menu-down' import MdiMenuDownIcon from '~icons/mdi/menu-down'
import MdiSortIcon from '~icons/mdi/sort' import MdiSortIcon from '~icons/mdi/sort'

2
packages/nc-gui-v2/components/smartsheet/Cell.vue

@ -2,7 +2,7 @@
import type { ColumnType } from 'nocodb-sdk' import type { ColumnType } from 'nocodb-sdk'
import { provide } from 'vue' import { provide } from 'vue'
import { computed } from '#imports' import { computed } from '#imports'
import { ColumnInj } from '~/components' import { ColumnInj } from '~/context'
import useColumn from '~/composables/useColumn' import useColumn from '~/composables/useColumn'
interface Props { interface Props {

2
packages/nc-gui-v2/components/smartsheet/Gallery.vue

@ -1,7 +1,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import { isVirtualCol } from 'nocodb-sdk' import { isVirtualCol } from 'nocodb-sdk'
import { inject, onKeyStroke, onMounted, provide } from '#imports' import { inject, onKeyStroke, onMounted, provide } from '#imports'
import { ActiveViewInj, ChangePageInj, IsFormInj, IsGridInj, MetaInj, PaginationDataInj, ReadonlyInj } from '~/components' import { ActiveViewInj, ChangePageInj, IsFormInj, IsGridInj, MetaInj, PaginationDataInj, ReadonlyInj } from '~/context'
import useViewData from '~/composables/useViewData' import useViewData from '~/composables/useViewData'
const meta = inject(MetaInj) const meta = inject(MetaInj)

2
packages/nc-gui-v2/components/smartsheet/Grid.vue

@ -11,7 +11,7 @@ import {
MetaInj, MetaInj,
PaginationDataInj, PaginationDataInj,
ReloadViewDataHookInj, ReloadViewDataHookInj,
} from '~/components' } from '~/context'
import useViewData from '~/composables/useViewData' import useViewData from '~/composables/useViewData'
const meta = inject(MetaInj) const meta = inject(MetaInj)

2
packages/nc-gui-v2/components/smartsheet/Pagination.vue

@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import { computed, inject } from 'vue' import { computed, inject } from 'vue'
import { ChangePageInj, PaginationDataInj } from '~/components' import { ChangePageInj, PaginationDataInj } from '~/context'
import MdiKeyboardIcon from '~icons/mdi/keyboard-return' import MdiKeyboardIcon from '~icons/mdi/keyboard-return'
const paginatedData = inject(PaginationDataInj) const paginatedData = inject(PaginationDataInj)

2
packages/nc-gui-v2/components/smartsheet/Sidebar.vue

@ -3,7 +3,7 @@ import { ViewTypes } from 'nocodb-sdk'
import type { TableType } from 'nocodb-sdk' import type { TableType } from 'nocodb-sdk'
import type { Ref } from 'vue' import type { Ref } from 'vue'
import { inject, ref } from '#imports' import { inject, ref } from '#imports'
import { ActiveViewInj, MetaInj, ViewListInj } from '~/components' import { ActiveViewInj, MetaInj, ViewListInj } from '~/context'
import useViews from '~/composables/useViews' import useViews from '~/composables/useViews'
import { viewIcons } from '~/utils/viewUtils' import { viewIcons } from '~/utils/viewUtils'
import MdiPlusIcon from '~icons/mdi/plus' import MdiPlusIcon from '~icons/mdi/plus'

2
packages/nc-gui-v2/components/smartsheet/VirtualCell.vue

@ -1,7 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
import type { ColumnType } from 'nocodb-sdk' import type { ColumnType } from 'nocodb-sdk'
import { provide } from '#imports' import { provide } from '#imports'
import { ColumnInj } from '~/components' import { ColumnInj } from '~/context'
import useVirtualCell from '~/composables/useVirtualCell' import useVirtualCell from '~/composables/useVirtualCell'
interface Props { interface Props {

2
packages/nc-gui-v2/components/tabs/Smartsheet.vue

@ -3,7 +3,7 @@ import { useEventBus } from '@vueuse/core'
import type { ColumnType, FormType, GalleryType, GridType, KanbanType } from 'nocodb-sdk' import type { ColumnType, FormType, GalleryType, GridType, KanbanType } from 'nocodb-sdk'
import { ViewTypes } from 'nocodb-sdk' import { ViewTypes } from 'nocodb-sdk'
import { computed, onMounted, provide, watch } from '#imports' import { computed, onMounted, provide, watch } from '#imports'
import { ActiveViewInj, FieldsInj, IsLockedInj, MetaInj, ReloadViewDataHookInj, TabMetaInj } from '~/components' import { ActiveViewInj, FieldsInj, IsLockedInj, MetaInj, ReloadViewDataHookInj, TabMetaInj } from '~/context'
import useMetas from '~/composables/useMetas' import useMetas from '~/composables/useMetas'
const { tabMeta } = defineProps({ const { tabMeta } = defineProps({

2
packages/nc-gui-v2/components/virtual-cell/BelongsTo.vue

@ -1,7 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
import type { ColumnType } from 'nocodb-sdk' import type { ColumnType } from 'nocodb-sdk'
import ItemChip from './components/ItemChip.vue' import ItemChip from './components/ItemChip.vue'
import { ColumnInj } from '~/components' import { ColumnInj } from '~/context'
import useBelongsTo from '~/composables/useBelongsTo' import useBelongsTo from '~/composables/useBelongsTo'
const column = inject(ColumnInj) const column = inject(ColumnInj)

5
packages/nc-gui-v2/components/virtual-cell/Formula.vue

@ -1,8 +1,9 @@
<script lang="ts" setup> <script lang="ts" setup>
import { computed } from '#imports' import { computed, useProject } from '#imports'
import { ColumnInj } from '~/components' import { ColumnInj } from '~/context'
import { handleTZ } from '~/utils/dateTimeUtils' import { handleTZ } from '~/utils/dateTimeUtils'
import { replaceUrlsWithLink } from '~/utils/urlUtils' import { replaceUrlsWithLink } from '~/utils/urlUtils'
const column = inject(ColumnInj) const column = inject(ColumnInj)
const value = inject('value') const value = inject('value')

2
packages/nc-gui-v2/components/virtual-cell/HasMany.vue

@ -1,7 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
import type { ColumnType } from 'nocodb-sdk' import type { ColumnType } from 'nocodb-sdk'
import ItemChip from './components/ItemChip.vue' import ItemChip from './components/ItemChip.vue'
import { ColumnInj } from '~/components' import { ColumnInj } from '~/context'
import useHasMany from '~/composables/useHasMany' import useHasMany from '~/composables/useHasMany'
const column = inject(ColumnInj) const column = inject(ColumnInj)
const value = inject('value') const value = inject('value')

2
packages/nc-gui-v2/components/virtual-cell/ManyToMany.vue

@ -1,7 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
import type { ColumnType } from 'nocodb-sdk' import type { ColumnType } from 'nocodb-sdk'
import ItemChip from './components/ItemChip.vue' import ItemChip from './components/ItemChip.vue'
import { ColumnInj } from '~/components' import { ColumnInj } from '~/context'
import useManyToMany from '~/composables/useManyToMany' import useManyToMany from '~/composables/useManyToMany'
const column = inject(ColumnInj) const column = inject(ColumnInj)
const value = inject('value') const value = inject('value')

2
packages/nc-gui-v2/components/virtual-cell/components/ItemChip.vue

@ -1,5 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import { ReadonlyInj } from '~/components' import { ReadonlyInj } from '~/context'
import MdiCloseThickIcon from '~icons/mdi/close-thick' import MdiCloseThickIcon from '~icons/mdi/close-thick'
interface Props { interface Props {

2
packages/nc-gui-v2/composables/useColumn.ts

@ -1,6 +1,6 @@
import type { ColumnType } from 'nocodb-sdk' import type { ColumnType } from 'nocodb-sdk'
import { SqlUiFactory, UITypes, isVirtualCol } from 'nocodb-sdk' import { SqlUiFactory, UITypes, isVirtualCol } from 'nocodb-sdk'
import useProject from '~/composables/useProject' import { useProject } from '#imports'
export default (column: ColumnType) => { export default (column: ColumnType) => {
const { project } = useProject() const { project } = useProject()

2
packages/nc-gui-v2/composables/useMetas.ts

@ -1,6 +1,6 @@
import type { TableType } from 'nocodb-sdk' import type { TableType } from 'nocodb-sdk'
import { useNuxtApp, useState } from '#app' import { useNuxtApp, useState } from '#app'
import useProject from '~/composables/useProject' import { useProject } from '#imports'
export default () => { export default () => {
const { $api } = useNuxtApp() const { $api } = useNuxtApp()

33
packages/nc-gui-v2/composables/useProject.ts

@ -1,17 +1,19 @@
import { SqlUiFactory } from 'nocodb-sdk' import { SqlUiFactory } from 'nocodb-sdk'
import type { ProjectType, TableType } from 'nocodb-sdk' import type { ProjectType, TableType } from 'nocodb-sdk'
import type { MaybeRef } from '@vueuse/core'
import { useNuxtApp, useState } from '#app' import { useNuxtApp, useState } from '#app'
import { USER_PROJECT_ROLES } from '~/lib/constants' import { USER_PROJECT_ROLES } from '~/lib/constants'
export default () => { export default (projectId?: MaybeRef<string>) => {
const projectRoles = useState<Record<string, boolean>>(USER_PROJECT_ROLES, () => ({})) const projectRoles = useState<Record<string, boolean>>(USER_PROJECT_ROLES, () => ({}))
const { $api } = useNuxtApp() const { $api } = useNuxtApp()
const _projectId = $computed(() => unref(projectId))
const project = useState<ProjectType>('project') const project = useState<ProjectType>('project')
const tables = useState<TableType[]>('tables') const tables = useState<TableType[]>('tables', () => [] as TableType[])
const loadProjectRoles = async () => { async function loadProjectRoles() {
projectRoles.value = {} projectRoles.value = {}
if (project.value.id) { if (project.value.id) {
@ -19,21 +21,30 @@ export default () => {
projectRoles.value = user.roles projectRoles.value = user.roles
} }
} }
const loadTables = async () => { async function loadTables() {
if (project.value.id) { if (project.value.id) {
const tablesResponse = await $api.dbTable.list(project.value.id) const tablesResponse = await $api.dbTable.list(project.value.id)
if (tablesResponse.list) tables.value = tablesResponse.list if (tablesResponse.list) tables.value = tablesResponse.list
} }
} }
const loadProject = async (projectId: string) => { async function loadProject(id: string) {
project.value = await $api.project.read(projectId) project.value = await $api.project.read(id)
await loadProjectRoles() await loadProjectRoles()
} }
const isMysql = computed(() => ['mysql', 'mysql2'].includes(project.value?.bases?.[0]?.type || '')) watchEffect(async () => {
const isPg = computed(() => project.value?.bases?.[0]?.type === 'pg') if (_projectId) {
const sqlUi = computed(() => SqlUiFactory.create({ client: project.value?.bases?.[0]?.type || '' })) 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 }
} }

1
packages/nc-gui-v2/composables/useTableCreate.ts

@ -1,6 +1,7 @@
import type { TableType } from 'nocodb-sdk' import type { TableType } from 'nocodb-sdk'
import { UITypes } from 'nocodb-sdk' import { UITypes } from 'nocodb-sdk'
import { useNuxtApp } from '#app' import { useNuxtApp } from '#app'
import { useProject } from '#imports'
export default (onTableCreate?: (tableMeta: TableType) => void) => { export default (onTableCreate?: (tableMeta: TableType) => void) => {
const table = reactive<{ title: string; table_name: string; columns: string[] }>({ const table = reactive<{ title: string; table_name: string; columns: string[] }>({

2
packages/nc-gui-v2/composables/useViewData.ts

@ -1,7 +1,7 @@
import type { Api, FormType, GalleryType, GridType, PaginatedType, TableType } from 'nocodb-sdk' import type { Api, FormType, GalleryType, GridType, PaginatedType, TableType } from 'nocodb-sdk'
import type { ComputedRef, Ref } from 'vue' import type { ComputedRef, Ref } from 'vue'
import { useNuxtApp } from '#app' import { useNuxtApp } from '#app'
import useProject from '~/composables/useProject' import { useProject } from '#imports'
import { NOCO } from '~/lib/constants' import { NOCO } from '~/lib/constants'
const formatData = (list: Record<string, any>[]) => const formatData = (list: Record<string, any>[]) =>

2
packages/nc-gui-v2/components/index.ts → packages/nc-gui-v2/context/index.ts

@ -1,7 +1,7 @@
import type { ColumnType, TableType, ViewType } from 'nocodb-sdk' import type { ColumnType, TableType, ViewType } from 'nocodb-sdk'
import type { InjectionKey, Ref } from 'vue' import type { InjectionKey, Ref } from 'vue'
import type { EventHook } from '@vueuse/core' import type { EventHook } from '@vueuse/core'
import type useViewData from '~/composables/useViewData' import type { useViewData } from '#imports'
export const ColumnInj: InjectionKey<ColumnType & { meta: any }> = Symbol('column-injection') export const ColumnInj: InjectionKey<ColumnType & { meta: any }> = Symbol('column-injection')
export const MetaInj: InjectionKey<Ref<TableType>> = Symbol('meta-injection') export const MetaInj: InjectionKey<Ref<TableType>> = Symbol('meta-injection')

10
packages/nc-gui-v2/pages/nc/[projectId].vue

@ -1,17 +1,9 @@
<script setup lang="ts"> <script setup lang="ts">
import { watch } from 'vue'
import useProject from '~/composables/useProject'
import useTabs from '~/composables/useTabs'
const route = useRoute() const route = useRoute()
const { loadProject, loadTables } = useProject() const { loadProject, loadTables } = useProject(route.params.projectId as string)
const { clearTabs, addTab } = useTabs() const { clearTabs, addTab } = useTabs()
onMounted(async () => {
await loadProject(route.params.projectId as string)
await loadTables()
addTab({ type: 'auth', title: 'Team & Auth' }) addTab({ type: 'auth', title: 'Team & Auth' })
})
watch( watch(
() => route.params.projectId, () => route.params.projectId,

Loading…
Cancel
Save