|
|
|
@ -13,6 +13,7 @@ import {
|
|
|
|
|
useSmartsheetStoreOrThrow, |
|
|
|
|
useUIPermission, |
|
|
|
|
} from '#imports' |
|
|
|
|
import type { TabItem } from '~/lib' |
|
|
|
|
|
|
|
|
|
export function useViewSorts(view: Ref<ViewType | undefined>, reloadData?: () => void) { |
|
|
|
|
const { sharedView } = useSharedView() |
|
|
|
@ -29,6 +30,8 @@ export function useViewSorts(view: Ref<ViewType | undefined>, reloadData?: () =>
|
|
|
|
|
|
|
|
|
|
const isPublic = inject(IsPublicInj, ref(false)) |
|
|
|
|
|
|
|
|
|
const tabMeta = inject(TabMetaInj, ref({ sortsState: new Map() } as TabItem)) |
|
|
|
|
|
|
|
|
|
const loadSorts = async () => { |
|
|
|
|
if (isPublic.value) { |
|
|
|
|
// todo: sorts missing on `ViewType`
|
|
|
|
@ -38,6 +41,13 @@ export function useViewSorts(view: Ref<ViewType | undefined>, reloadData?: () =>
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
if (!isUIAllowed('sortSync')) { |
|
|
|
|
const sortsBackup = tabMeta.value.sortsState!.get(view.value!.id!) |
|
|
|
|
if (sortsBackup) { |
|
|
|
|
sorts.value = sortsBackup |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (!view?.value) return |
|
|
|
|
sorts.value = (await $api.dbTableSort.list(view.value!.id!)).sorts?.list || [] |
|
|
|
|
} catch (e: any) { |
|
|
|
@ -51,6 +61,7 @@ export function useViewSorts(view: Ref<ViewType | undefined>, reloadData?: () =>
|
|
|
|
|
sorts.value[i] = sort |
|
|
|
|
sorts.value = [...sorts.value] |
|
|
|
|
reloadHook?.trigger() |
|
|
|
|
tabMeta.value.sortsState!.set(view.value!.id!, sorts.value) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -79,6 +90,8 @@ export function useViewSorts(view: Ref<ViewType | undefined>, reloadData?: () =>
|
|
|
|
|
] |
|
|
|
|
|
|
|
|
|
$e('a:sort:add', { length: sorts?.value?.length }) |
|
|
|
|
|
|
|
|
|
tabMeta.value.sortsState!.set(view.value!.id!, sorts.value) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const deleteSort = async (sort: SortType, i: number) => { |
|
|
|
@ -89,6 +102,8 @@ export function useViewSorts(view: Ref<ViewType | undefined>, reloadData?: () =>
|
|
|
|
|
sorts.value.splice(i, 1) |
|
|
|
|
sorts.value = [...sorts.value] |
|
|
|
|
|
|
|
|
|
tabMeta.value.sortsState!.set(view.value!.id!, sorts.value) |
|
|
|
|
|
|
|
|
|
reloadHook?.trigger() |
|
|
|
|
$e('a:sort:delete') |
|
|
|
|
} catch (e: any) { |
|
|
|
|