Browse Source

feat(gui-v2): add barrel file to composables dir

pull/2877/head
braks 2 years ago
parent
commit
6ab8bb86e5
  1. 18
      packages/nc-gui-v2/composables/index.ts
  2. 4
      packages/nc-gui-v2/composables/useAttachment.ts
  3. 9
      packages/nc-gui-v2/composables/useBelongsTo.ts
  4. 4
      packages/nc-gui-v2/composables/useColors.ts
  5. 2
      packages/nc-gui-v2/composables/useColumn.ts
  6. 7
      packages/nc-gui-v2/composables/useHasMany.ts
  7. 9
      packages/nc-gui-v2/composables/useManyToMany.ts
  8. 4
      packages/nc-gui-v2/composables/useMetas.ts
  9. 4
      packages/nc-gui-v2/composables/useProject.ts
  10. 4
      packages/nc-gui-v2/composables/useTableCreate.ts
  11. 2
      packages/nc-gui-v2/composables/useViewColumns.ts
  12. 6
      packages/nc-gui-v2/composables/useViewData.ts
  13. 2
      packages/nc-gui-v2/composables/useViewFilters.ts
  14. 2
      packages/nc-gui-v2/composables/useViewSorts.ts
  15. 8
      packages/nc-gui-v2/composables/useViews.ts
  16. 4
      packages/nc-gui-v2/composables/useVirtualCell.ts

18
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'

4
packages/nc-gui-v2/composables/useAttachment.ts

@ -1,5 +1,5 @@
// todo: // todo: implement useAttachment
export default () => { export function useAttachment() {
const localFilesState = reactive([]) const localFilesState = reactive([])
const attachments = ref([]) const attachments = ref([])

9
packages/nc-gui-v2/composables/useBelongsTo.ts

@ -1,15 +1,14 @@
import type { ColumnType, TableType } from 'nocodb-sdk' import type { ColumnType, TableType } from 'nocodb-sdk'
import type LinkToAnotherRecordColumn from '../../nocodb/src/lib/models/LinkToAnotherRecordColumn' import useMetas from './useMetas'
import useMetas from '~/composables/useMetas'
export default function (column: ColumnType) { export function useBelongsTo(column: ColumnType) {
const { metas, getMeta } = useMetas() const { metas, getMeta } = useMetas()
const parentMeta = computed<TableType>(() => { const parentMeta = computed<TableType>(() => {
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 () => { 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(() => { const primaryValueProp = computed(() => {

4
packages/nc-gui-v2/composables/useColors.ts

@ -1,9 +1,9 @@
import type { MaybeRef } from '@vueuse/core' import type { MaybeRef } from '@vueuse/core'
import { computed, effectScope, tryOnScopeDispose, unref, watch, watchEffect } from '#build/imports' import { computed, effectScope, tryOnScopeDispose, unref, watch, watchEffect } from '#build/imports'
import { useNuxtApp } from '#app' import { useNuxtApp } from '#app'
import theme from '~/utils/colorsUtils' import { theme } from '~/utils'
export default function useColors(darkMode?: MaybeRef<boolean>) { export function useColors(darkMode?: MaybeRef<boolean>) {
const scope = effectScope() const scope = effectScope()
let mode = $ref(unref(darkMode)) let mode = $ref(unref(darkMode))

2
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 { SqlUiFactory, UITypes, isVirtualCol } from 'nocodb-sdk'
import { useProject } from '#imports' import { useProject } from '#imports'
export default (column: ColumnType) => { export function useColumn(column: ColumnType) {
const { project } = useProject() const { project } = useProject()
const uiDatatype: UITypes = (column && column.uidt) as UITypes const uiDatatype: UITypes = (column && column.uidt) as UITypes

7
packages/nc-gui-v2/composables/useHasMany.ts

@ -1,15 +1,14 @@
import type { ColumnType, TableType } from 'nocodb-sdk' import type { ColumnType, TableType } from 'nocodb-sdk'
import type LinkToAnotherRecordColumn from '../../nocodb/src/lib/models/LinkToAnotherRecordColumn' import { useMetas } from './useMetas'
import useMetas from '~/composables/useMetas'
export default function (column: ColumnType) { export default function (column: ColumnType) {
const { metas, getMeta } = useMetas() const { metas, getMeta } = useMetas()
const childMeta = computed<TableType>(() => { const childMeta = computed<TableType>(() => {
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 () => { 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(() => { const primaryValueProp = computed(() => {

9
packages/nc-gui-v2/composables/useManyToMany.ts

@ -1,15 +1,14 @@
import type { ColumnType, TableType } from 'nocodb-sdk' import type { ColumnType, TableType } from 'nocodb-sdk'
import type LinkToAnotherRecordColumn from '../../nocodb/src/lib/models/LinkToAnotherRecordColumn' import useMetas from './useMetas'
import useMetas from '~/composables/useMetas'
export default function (column: ColumnType) { export function useManyToMany(column: ColumnType) {
const { metas, getMeta } = useMetas() const { metas, getMeta } = useMetas()
const childMeta = computed<TableType>(() => { const childMeta = computed<TableType>(() => {
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 () => { 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(() => { const primaryValueProp = computed(() => {

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

@ -1,8 +1,8 @@
import type { TableInfoType, TableType } from 'nocodb-sdk' import type { TableInfoType, TableType } from 'nocodb-sdk'
import { useProject } from './useProject'
import { useNuxtApp, useState } from '#app' import { useNuxtApp, useState } from '#app'
import { useProject } from '#imports'
export default () => { export function useMetas() {
const { $api } = useNuxtApp() const { $api } = useNuxtApp()
const { tables } = useProject() const { tables } = useProject()

4
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 { OracleUi, ProjectType, TableType } from 'nocodb-sdk'
import type { MaybeRef } from '@vueuse/core' 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'
export default (projectId?: MaybeRef<string>) => { export function useProject(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()

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

@ -1,9 +1,9 @@
import type { TableType } from 'nocodb-sdk' import type { TableType } from 'nocodb-sdk'
import { UITypes } from 'nocodb-sdk' import { UITypes } from 'nocodb-sdk'
import { useProject } from './useProject'
import { useNuxtApp } from '#app' 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[] }>({ const table = reactive<{ title: string; table_name: string; columns: string[] }>({
title: '', title: '',
table_name: '', table_name: '',

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

@ -4,7 +4,7 @@ import { watch } from 'vue'
import type { ComputedRef, Ref } from 'vue' import type { ComputedRef, Ref } from 'vue'
import { useNuxtApp } from '#app' import { useNuxtApp } from '#app'
export default function ( export function useViewColumns(
view: Ref<(GridType | FormType | GalleryType) & { id?: string }> | undefined, view: Ref<(GridType | FormType | GalleryType) & { id?: string }> | undefined,
meta: ComputedRef<TableType>, meta: ComputedRef<TableType>,
isPublic = false, isPublic = false,

6
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 type { ComputedRef, Ref } from 'vue'
import { useNuxtApp } from '#app' import { useNuxtApp } from '#app'
import { useProject } from '#imports' import { useProject } from '#imports'
import { NOCO } from '~/lib/constants' import { NOCO } from '~/lib'
const formatData = (list: Record<string, any>[]) => const formatData = (list: Record<string, any>[]) =>
list.map((row) => ({ list.map((row) => ({
@ -11,13 +11,13 @@ const formatData = (list: Record<string, any>[]) =>
rowMeta: {}, rowMeta: {},
})) }))
export default ( export function useViewData(
meta: Ref<TableType> | ComputedRef<TableType> | undefined, meta: Ref<TableType> | ComputedRef<TableType> | undefined,
viewMeta: viewMeta:
| Ref<(GridType | GalleryType | FormType) & { id: string }> | Ref<(GridType | GalleryType | FormType) & { id: string }>
| ComputedRef<(GridType | GalleryType | FormType) & { id: string }> | ComputedRef<(GridType | GalleryType | FormType) & { id: string }>
| undefined, | undefined,
) => { ) {
const data = ref<Record<string, any>[]>() const data = ref<Record<string, any>[]>()
const formattedData = ref<{ row: Record<string, any>; oldRow: Record<string, any>; rowMeta?: any }[]>() const formattedData = ref<{ row: Record<string, any>; oldRow: Record<string, any>; rowMeta?: any }[]>()
const paginationData = ref<PaginatedType>({ page: 1, pageSize: 25 }) const paginationData = ref<PaginatedType>({ page: 1, pageSize: 25 })

2
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 type { Ref } from 'vue'
import { useNuxtApp } from '#imports' import { useNuxtApp } from '#imports'
export default function ( export function useViewFilters(
view: Ref<(GridType | KanbanType | GalleryType) & { id?: string }> | undefined, view: Ref<(GridType | KanbanType | GalleryType) & { id?: string }> | undefined,
parentId?: string, parentId?: string,
reloadData?: () => void, reloadData?: () => void,

2
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 type { Ref } from 'vue'
import { useNuxtApp } from '#imports' import { useNuxtApp } from '#imports'
export default function ( export function useViewSorts(
view: Ref<(GridType | KanbanType | GalleryType) & { id?: string }> | undefined, view: Ref<(GridType | KanbanType | GalleryType) & { id?: string }> | undefined,
reloadData?: () => void, reloadData?: () => void,
) { ) {

8
packages/nc-gui-v2/composables/useViews.ts

@ -1,9 +1,8 @@
import type { FormType, GalleryType, GridType, KanbanType, TableType } from 'nocodb-sdk' import type { FormType, GalleryType, GridType, KanbanType, TableType } from 'nocodb-sdk'
import type { MaybeRef } from '@vueuse/core' import type { MaybeRef } from '@vueuse/core'
import type { WatchOptions } from '@vue/runtime-core'
import { useNuxtApp } from '#app' import { useNuxtApp } from '#app'
export default function (meta: MaybeRef<TableType | undefined>, watchOptions: WatchOptions = {}) { export function useViews(meta: MaybeRef<TableType | undefined>) {
let views = $ref<(GridType | FormType | KanbanType | GalleryType)[]>([]) let views = $ref<(GridType | FormType | KanbanType | GalleryType)[]>([])
const { $api } = useNuxtApp() const { $api } = useNuxtApp()
@ -18,10 +17,7 @@ export default function (meta: MaybeRef<TableType | undefined>, watchOptions: Wa
} }
} }
watch(() => meta, loadViews, { watch(() => meta, loadViews, { immediate: true })
immediate: true,
...watchOptions,
})
return { views: $$(views), loadViews } return { views: $$(views), loadViews }
} }

4
packages/nc-gui-v2/composables/useVirtualCell.ts

@ -1,8 +1,8 @@
import { computed } from '@vue/reactivity'
import type { ColumnType, LinkToAnotherRecordType } from 'nocodb-sdk' import type { ColumnType, LinkToAnotherRecordType } from 'nocodb-sdk'
import { RelationTypes, UITypes } 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( const isHm = computed(
() => () =>
column.uidt === UITypes.LinkToAnotherRecord && (<LinkToAnotherRecordType>column.colOptions).type === RelationTypes.HAS_MANY, column.uidt === UITypes.LinkToAnotherRecord && (<LinkToAnotherRecordType>column.colOptions).type === RelationTypes.HAS_MANY,

Loading…
Cancel
Save