diff --git a/packages/nc-gui-v2/composables/useSharedView.ts b/packages/nc-gui-v2/composables/useSharedView.ts index 4e05bb23cd..7175d0b152 100644 --- a/packages/nc-gui-v2/composables/useSharedView.ts +++ b/packages/nc-gui-v2/composables/useSharedView.ts @@ -1,9 +1,10 @@ -import type { ColumnType, FilterType, PaginatedType, TableType, ViewType } from 'nocodb-sdk' +import type { ColumnType, FilterType, PaginatedType, SortType, TableType, ViewType } from 'nocodb-sdk' import { useNuxtApp } from '#app' const filters = ref<(FilterType & { status?: 'update' | 'delete' | 'create'; parentId?: string })[]>([]) const paginationData = ref({ page: 1, pageSize: 25 }) const sharedView = ref() +const sorts = ref([]) export function useSharedView() { const meta = ref(() => sharedView.value?.model) @@ -32,10 +33,11 @@ export function useSharedView() { const { data } = await $api.public.dataList(sharedView?.value?.uuid, { offset: (page - 1) * pageSize, filterArrJson: JSON.stringify(filters.value), + sortArrJson: JSON.stringify(sorts.value), } as any) return data } - return { sharedView, loadSharedView, meta, columns, filters, fetchSharedViewData, paginationData } + return { sharedView, loadSharedView, meta, columns, filters, fetchSharedViewData, paginationData, sorts } } diff --git a/packages/nc-gui-v2/composables/useViewSorts.ts b/packages/nc-gui-v2/composables/useViewSorts.ts index 31e4a998e4..b7d712a255 100644 --- a/packages/nc-gui-v2/composables/useViewSorts.ts +++ b/packages/nc-gui-v2/composables/useViewSorts.ts @@ -1,18 +1,41 @@ import type { GalleryType, GridType, KanbanType, SortType } from 'nocodb-sdk' import type { Ref } from 'vue' import { useNuxtApp } from '#imports' +import { IsPublicInj, ReloadViewDataHookInj } from '~/context' export function useViewSorts( view: Ref<(GridType | KanbanType | GalleryType) & { id?: string }> | undefined, reloadData?: () => void, ) { - const sorts = ref([]) + const _sorts = ref([]) + const { sorts: sharedViewSorts, sharedView } = useSharedView() + + const reloadHook = inject(ReloadViewDataHookInj) + const isPublic = inject(IsPublicInj, ref(false)) + + const sorts = computed({ + get: () => (isPublic.value ? sharedViewSorts.value : _sorts.value), + set: (value) => { + if (isPublic.value) { + sharedViewSorts.value = value + } else { + _sorts.value = value + } + reloadHook?.trigger() + }, + }) const { $api } = useNuxtApp() const { isUIAllowed } = useUIPermission() const loadSorts = async () => { + if (isPublic.value) { + console.log('load sorts public', sharedView.value?.sorts) + const sharedSorts = sharedView.value?.sorts || [] + sorts.value = [...sharedSorts] + return + } if (!view?.value) return sorts.value = ((await $api.dbTableSort.list(view?.value?.id as string)) as any)?.sorts?.list } @@ -20,6 +43,12 @@ export function useViewSorts( const saveOrUpdate = async (sort: SortType, i: number) => { // TODO: // if (!this.shared && this._isUIAllowed('sortSync')) { + if (isPublic.value) { + sorts.value[i] = sort + sorts.value = [...sorts.value] + return + } + if (isUIAllowed('sortSync')) { if (sort.id) { await $api.dbTableSort.update(sort.id, sort) @@ -30,14 +59,23 @@ export function useViewSorts( reloadData?.() } const addSort = () => { - sorts.value.push({ - direction: 'asc', - }) + sorts.value = [ + ...sorts.value, + { + direction: 'asc', + }, + ] } const deleteSort = async (sort: SortType, i: number) => { // TOOD: // if (!this.shared && sort.id && this._isUIAllowed('sortSync')) { + if (isPublic.value) { + sorts.value.splice(i, 1) + sorts.value = [...sorts.value] + return + } + if (isUIAllowed('sortSync') && sort.id) { await $api.dbTableSort.delete(sort.id) } else {