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