From 6ab8bb86e5ed74793327ff3911562f9f6ac8bd00 Mon Sep 17 00:00:00 2001 From: braks <78412429+bcakmakoglu@users.noreply.github.com> Date: Fri, 29 Jul 2022 11:24:24 +0200 Subject: [PATCH] feat(gui-v2): add barrel file to composables dir --- packages/nc-gui-v2/composables/index.ts | 18 ++++++++++++++++++ .../nc-gui-v2/composables/useAttachment.ts | 4 ++-- packages/nc-gui-v2/composables/useBelongsTo.ts | 9 ++++----- packages/nc-gui-v2/composables/useColors.ts | 4 ++-- packages/nc-gui-v2/composables/useColumn.ts | 2 +- packages/nc-gui-v2/composables/useHasMany.ts | 7 +++---- .../nc-gui-v2/composables/useManyToMany.ts | 9 ++++----- packages/nc-gui-v2/composables/useMetas.ts | 4 ++-- packages/nc-gui-v2/composables/useProject.ts | 4 ++-- .../nc-gui-v2/composables/useTableCreate.ts | 4 ++-- .../nc-gui-v2/composables/useViewColumns.ts | 2 +- packages/nc-gui-v2/composables/useViewData.ts | 6 +++--- .../nc-gui-v2/composables/useViewFilters.ts | 2 +- packages/nc-gui-v2/composables/useViewSorts.ts | 2 +- packages/nc-gui-v2/composables/useViews.ts | 8 ++------ .../nc-gui-v2/composables/useVirtualCell.ts | 4 ++-- 16 files changed, 50 insertions(+), 39 deletions(-) create mode 100644 packages/nc-gui-v2/composables/index.ts diff --git a/packages/nc-gui-v2/composables/index.ts b/packages/nc-gui-v2/composables/index.ts new file mode 100644 index 0000000000..b359f3b2fa --- /dev/null +++ b/packages/nc-gui-v2/composables/index.ts @@ -0,0 +1,18 @@ +export * from './useApi' +export * from './useGlobal' +export * from './useUIPermission' +export * from './useAttachment' +export * from './useBelongsTo' +export * from './useColors' +export * from './useColumn' +export * from './useManyToMany' +export * from './useMetas' +export * from './useProject' +export * from './useTableCreate' +export * from './useTabs' +export * from './useViewColumns' +export * from './useViewData' +export * from './useViewFilters' +export * from './useViews' +export * from './useViewSorts' +export * from './useVirtualCell' diff --git a/packages/nc-gui-v2/composables/useAttachment.ts b/packages/nc-gui-v2/composables/useAttachment.ts index 24b604d425..3aee3b2798 100644 --- a/packages/nc-gui-v2/composables/useAttachment.ts +++ b/packages/nc-gui-v2/composables/useAttachment.ts @@ -1,5 +1,5 @@ -// todo: -export default () => { +// todo: implement useAttachment +export function useAttachment() { const localFilesState = reactive([]) const attachments = ref([]) diff --git a/packages/nc-gui-v2/composables/useBelongsTo.ts b/packages/nc-gui-v2/composables/useBelongsTo.ts index 40e7d7ed1b..86adf7f731 100644 --- a/packages/nc-gui-v2/composables/useBelongsTo.ts +++ b/packages/nc-gui-v2/composables/useBelongsTo.ts @@ -1,15 +1,14 @@ import type { ColumnType, TableType } from 'nocodb-sdk' -import type LinkToAnotherRecordColumn from '../../nocodb/src/lib/models/LinkToAnotherRecordColumn' -import useMetas from '~/composables/useMetas' +import useMetas from './useMetas' -export default function (column: ColumnType) { +export function useBelongsTo(column: ColumnType) { const { metas, getMeta } = useMetas() const parentMeta = computed(() => { - return metas.value?.[(column.colOptions as LinkToAnotherRecordColumn)?.fk_related_model_id as string] + return metas.value?.[(column.colOptions as any)?.fk_related_model_id as string] }) const loadParentMeta = async () => { - await getMeta((column.colOptions as LinkToAnotherRecordColumn)?.fk_related_model_id as string) + await getMeta((column.colOptions as any)?.fk_related_model_id as string) } const primaryValueProp = computed(() => { diff --git a/packages/nc-gui-v2/composables/useColors.ts b/packages/nc-gui-v2/composables/useColors.ts index 7448ad7c1c..d2fd78b9ed 100644 --- a/packages/nc-gui-v2/composables/useColors.ts +++ b/packages/nc-gui-v2/composables/useColors.ts @@ -1,9 +1,9 @@ import type { MaybeRef } from '@vueuse/core' import { computed, effectScope, tryOnScopeDispose, unref, watch, watchEffect } from '#build/imports' import { useNuxtApp } from '#app' -import theme from '~/utils/colorsUtils' +import { theme } from '~/utils' -export default function useColors(darkMode?: MaybeRef) { +export function useColors(darkMode?: MaybeRef) { const scope = effectScope() let mode = $ref(unref(darkMode)) diff --git a/packages/nc-gui-v2/composables/useColumn.ts b/packages/nc-gui-v2/composables/useColumn.ts index 9eb65f1195..e46397fd87 100644 --- a/packages/nc-gui-v2/composables/useColumn.ts +++ b/packages/nc-gui-v2/composables/useColumn.ts @@ -2,7 +2,7 @@ import type { ColumnType } from 'nocodb-sdk' import { SqlUiFactory, UITypes, isVirtualCol } from 'nocodb-sdk' import { useProject } from '#imports' -export default (column: ColumnType) => { +export function useColumn(column: ColumnType) { const { project } = useProject() const uiDatatype: UITypes = (column && column.uidt) as UITypes diff --git a/packages/nc-gui-v2/composables/useHasMany.ts b/packages/nc-gui-v2/composables/useHasMany.ts index 2a2fafa9c5..dda56d1f55 100644 --- a/packages/nc-gui-v2/composables/useHasMany.ts +++ b/packages/nc-gui-v2/composables/useHasMany.ts @@ -1,15 +1,14 @@ import type { ColumnType, TableType } from 'nocodb-sdk' -import type LinkToAnotherRecordColumn from '../../nocodb/src/lib/models/LinkToAnotherRecordColumn' -import useMetas from '~/composables/useMetas' +import { useMetas } from './useMetas' export default function (column: ColumnType) { const { metas, getMeta } = useMetas() const childMeta = computed(() => { - return metas.value?.[(column.colOptions as LinkToAnotherRecordColumn)?.fk_related_model_id as string] + return metas.value?.[(column.colOptions as any)?.fk_related_model_id as string] }) const loadChildMeta = async () => { - await getMeta((column.colOptions as LinkToAnotherRecordColumn)?.fk_related_model_id as string) + await getMeta((column.colOptions as any)?.fk_related_model_id as string) } const primaryValueProp = computed(() => { diff --git a/packages/nc-gui-v2/composables/useManyToMany.ts b/packages/nc-gui-v2/composables/useManyToMany.ts index 2a2fafa9c5..3d9f1b5020 100644 --- a/packages/nc-gui-v2/composables/useManyToMany.ts +++ b/packages/nc-gui-v2/composables/useManyToMany.ts @@ -1,15 +1,14 @@ import type { ColumnType, TableType } from 'nocodb-sdk' -import type LinkToAnotherRecordColumn from '../../nocodb/src/lib/models/LinkToAnotherRecordColumn' -import useMetas from '~/composables/useMetas' +import useMetas from './useMetas' -export default function (column: ColumnType) { +export function useManyToMany(column: ColumnType) { const { metas, getMeta } = useMetas() const childMeta = computed(() => { - return metas.value?.[(column.colOptions as LinkToAnotherRecordColumn)?.fk_related_model_id as string] + return metas.value?.[(column.colOptions as any)?.fk_related_model_id as string] }) const loadChildMeta = async () => { - await getMeta((column.colOptions as LinkToAnotherRecordColumn)?.fk_related_model_id as string) + await getMeta((column.colOptions as any)?.fk_related_model_id as string) } const primaryValueProp = computed(() => { diff --git a/packages/nc-gui-v2/composables/useMetas.ts b/packages/nc-gui-v2/composables/useMetas.ts index 40232b1c49..b5f0a4548d 100644 --- a/packages/nc-gui-v2/composables/useMetas.ts +++ b/packages/nc-gui-v2/composables/useMetas.ts @@ -1,8 +1,8 @@ import type { TableInfoType, TableType } from 'nocodb-sdk' +import { useProject } from './useProject' import { useNuxtApp, useState } from '#app' -import { useProject } from '#imports' -export default () => { +export function useMetas() { const { $api } = useNuxtApp() const { tables } = useProject() diff --git a/packages/nc-gui-v2/composables/useProject.ts b/packages/nc-gui-v2/composables/useProject.ts index cad569363f..7d4fc760db 100644 --- a/packages/nc-gui-v2/composables/useProject.ts +++ b/packages/nc-gui-v2/composables/useProject.ts @@ -2,9 +2,9 @@ import { SqlUiFactory } from 'nocodb-sdk' import type { OracleUi, ProjectType, TableType } from 'nocodb-sdk' import type { MaybeRef } from '@vueuse/core' import { useNuxtApp, useState } from '#app' -import { USER_PROJECT_ROLES } from '~/lib/constants' +import { USER_PROJECT_ROLES } from '~/lib' -export default (projectId?: MaybeRef) => { +export function useProject(projectId?: MaybeRef) { const projectRoles = useState>(USER_PROJECT_ROLES, () => ({})) const { $api } = useNuxtApp() diff --git a/packages/nc-gui-v2/composables/useTableCreate.ts b/packages/nc-gui-v2/composables/useTableCreate.ts index f6f39dd493..581ea88463 100644 --- a/packages/nc-gui-v2/composables/useTableCreate.ts +++ b/packages/nc-gui-v2/composables/useTableCreate.ts @@ -1,9 +1,9 @@ import type { TableType } from 'nocodb-sdk' import { UITypes } from 'nocodb-sdk' +import { useProject } from './useProject' import { useNuxtApp } from '#app' -import { useProject } from '#imports' -export default (onTableCreate?: (tableMeta: TableType) => void) => { +export function useTableCreate(onTableCreate?: (tableMeta: TableType) => void) { const table = reactive<{ title: string; table_name: string; columns: string[] }>({ title: '', table_name: '', diff --git a/packages/nc-gui-v2/composables/useViewColumns.ts b/packages/nc-gui-v2/composables/useViewColumns.ts index b1057c5f56..2694cfc49f 100644 --- a/packages/nc-gui-v2/composables/useViewColumns.ts +++ b/packages/nc-gui-v2/composables/useViewColumns.ts @@ -4,7 +4,7 @@ import { watch } from 'vue' import type { ComputedRef, Ref } from 'vue' import { useNuxtApp } from '#app' -export default function ( +export function useViewColumns( view: Ref<(GridType | FormType | GalleryType) & { id?: string }> | undefined, meta: ComputedRef, isPublic = false, diff --git a/packages/nc-gui-v2/composables/useViewData.ts b/packages/nc-gui-v2/composables/useViewData.ts index afa02b242c..8446f8d6d8 100644 --- a/packages/nc-gui-v2/composables/useViewData.ts +++ b/packages/nc-gui-v2/composables/useViewData.ts @@ -2,7 +2,7 @@ import type { Api, FormType, GalleryType, GridType, PaginatedType, TableType } f import type { ComputedRef, Ref } from 'vue' import { useNuxtApp } from '#app' import { useProject } from '#imports' -import { NOCO } from '~/lib/constants' +import { NOCO } from '~/lib' const formatData = (list: Record[]) => list.map((row) => ({ @@ -11,13 +11,13 @@ const formatData = (list: Record[]) => rowMeta: {}, })) -export default ( +export function useViewData( meta: Ref | ComputedRef | undefined, viewMeta: | Ref<(GridType | GalleryType | FormType) & { id: string }> | ComputedRef<(GridType | GalleryType | FormType) & { id: string }> | undefined, -) => { +) { const data = ref[]>() const formattedData = ref<{ row: Record; oldRow: Record; rowMeta?: any }[]>() const paginationData = ref({ page: 1, pageSize: 25 }) diff --git a/packages/nc-gui-v2/composables/useViewFilters.ts b/packages/nc-gui-v2/composables/useViewFilters.ts index c794de80ed..64a82d24bc 100644 --- a/packages/nc-gui-v2/composables/useViewFilters.ts +++ b/packages/nc-gui-v2/composables/useViewFilters.ts @@ -2,7 +2,7 @@ import type { FilterType, GalleryType, GridType, KanbanType } from 'nocodb-sdk' import type { Ref } from 'vue' import { useNuxtApp } from '#imports' -export default function ( +export function useViewFilters( view: Ref<(GridType | KanbanType | GalleryType) & { id?: string }> | undefined, parentId?: string, reloadData?: () => void, diff --git a/packages/nc-gui-v2/composables/useViewSorts.ts b/packages/nc-gui-v2/composables/useViewSorts.ts index c0fe98f326..7d1bcf00f7 100644 --- a/packages/nc-gui-v2/composables/useViewSorts.ts +++ b/packages/nc-gui-v2/composables/useViewSorts.ts @@ -2,7 +2,7 @@ import type { GalleryType, GridType, KanbanType, SortType } from 'nocodb-sdk' import type { Ref } from 'vue' import { useNuxtApp } from '#imports' -export default function ( +export function useViewSorts( view: Ref<(GridType | KanbanType | GalleryType) & { id?: string }> | undefined, reloadData?: () => void, ) { diff --git a/packages/nc-gui-v2/composables/useViews.ts b/packages/nc-gui-v2/composables/useViews.ts index a042709e92..b7c9277609 100644 --- a/packages/nc-gui-v2/composables/useViews.ts +++ b/packages/nc-gui-v2/composables/useViews.ts @@ -1,9 +1,8 @@ import type { FormType, GalleryType, GridType, KanbanType, TableType } from 'nocodb-sdk' import type { MaybeRef } from '@vueuse/core' -import type { WatchOptions } from '@vue/runtime-core' import { useNuxtApp } from '#app' -export default function (meta: MaybeRef, watchOptions: WatchOptions = {}) { +export function useViews(meta: MaybeRef) { let views = $ref<(GridType | FormType | KanbanType | GalleryType)[]>([]) const { $api } = useNuxtApp() @@ -18,10 +17,7 @@ export default function (meta: MaybeRef, watchOptions: Wa } } - watch(() => meta, loadViews, { - immediate: true, - ...watchOptions, - }) + watch(() => meta, loadViews, { immediate: true }) return { views: $$(views), loadViews } } diff --git a/packages/nc-gui-v2/composables/useVirtualCell.ts b/packages/nc-gui-v2/composables/useVirtualCell.ts index e4cf181153..06bb61d318 100644 --- a/packages/nc-gui-v2/composables/useVirtualCell.ts +++ b/packages/nc-gui-v2/composables/useVirtualCell.ts @@ -1,8 +1,8 @@ -import { computed } from '@vue/reactivity' import type { ColumnType, LinkToAnotherRecordType } from 'nocodb-sdk' import { RelationTypes, UITypes } from 'nocodb-sdk' +import { computed } from '#imports' -export default function useVirtualCell(column: ColumnType) { +export function useVirtualCell(column: ColumnType) { const isHm = computed( () => column.uidt === UITypes.LinkToAnotherRecord && (column.colOptions).type === RelationTypes.HAS_MANY,