|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
import { UITypes } from 'nocodb-sdk' |
|
|
|
|
import type { ColumnType, LinkToAnotherRecordType, LookupType, SelectOptionsType, ViewType } from 'nocodb-sdk' |
|
|
|
|
import type { ColumnType, LinkToAnotherRecordType, LookupType, SelectOptionsType, TableType, ViewType } from 'nocodb-sdk' |
|
|
|
|
import type { Ref } from 'vue' |
|
|
|
|
import { message } from 'ant-design-vue' |
|
|
|
|
import { extractSdkResponseErrorMsg } from '../utils' |
|
|
|
@ -17,7 +17,13 @@ import type { Group, GroupNestedIn, Row } from '#imports'
|
|
|
|
|
|
|
|
|
|
const excludedGroupingUidt = [UITypes.Attachment, UITypes.QrCode, UITypes.Barcode] |
|
|
|
|
|
|
|
|
|
export const useViewGroupBy = (view: Ref<ViewType | undefined>, where?: ComputedRef<string | undefined>) => { |
|
|
|
|
const [useProvideViewGroupBy, useViewGroupBy] = useInjectionState( |
|
|
|
|
( |
|
|
|
|
view: Ref<ViewType | undefined>, |
|
|
|
|
meta: Ref<TableType | undefined> | ComputedRef<TableType | undefined>, |
|
|
|
|
where?: ComputedRef<string | undefined>, |
|
|
|
|
isPublic = false, |
|
|
|
|
) => { |
|
|
|
|
const groupByLimit: number = 3 |
|
|
|
|
|
|
|
|
|
const { api } = useApi() |
|
|
|
@ -28,8 +34,6 @@ export const useViewGroupBy = (view: Ref<ViewType | undefined>, where?: Computed
|
|
|
|
|
|
|
|
|
|
const { sharedView, fetchSharedViewData } = useSharedView() |
|
|
|
|
|
|
|
|
|
const meta = inject(MetaInj) |
|
|
|
|
|
|
|
|
|
const { gridViewCols } = useViewColumnsOrThrow() |
|
|
|
|
|
|
|
|
|
const { getMeta } = useMetas() |
|
|
|
@ -60,8 +64,6 @@ export const useViewGroupBy = (view: Ref<ViewType | undefined>, where?: Computed
|
|
|
|
|
|
|
|
|
|
const { sorts, nestedFilters } = useSmartsheetStoreOrThrow() |
|
|
|
|
|
|
|
|
|
const isPublic = inject(IsPublicInj, ref(false)) |
|
|
|
|
|
|
|
|
|
const reloadViewDataHook = inject(ReloadViewDataHookInj, createEventHook()) |
|
|
|
|
|
|
|
|
|
const groupByGroupLimit = computed(() => { |
|
|
|
@ -232,11 +234,11 @@ export const useViewGroupBy = (view: Ref<ViewType | undefined>, where?: Computed
|
|
|
|
|
const nestedWhere = calculateNestedWhere(group.nestedIn, where?.value) |
|
|
|
|
if (!groupby || !groupby.column.title) return |
|
|
|
|
|
|
|
|
|
if (isPublic.value && !sharedView.value?.uuid) { |
|
|
|
|
if (isPublic && !sharedView.value?.uuid) { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const response = !isPublic.value |
|
|
|
|
const response = !isPublic |
|
|
|
|
? await api.dbViewRow.groupBy('noco', base.value.id, view.value.fk_model_id, view.value.id, { |
|
|
|
|
offset: ((group.paginationData.page ?? 0) - 1) * (group.paginationData.pageSize ?? groupByGroupLimit.value), |
|
|
|
|
limit: group.paginationData.pageSize ?? groupByGroupLimit.value, |
|
|
|
@ -361,7 +363,7 @@ export const useViewGroupBy = (view: Ref<ViewType | undefined>, where?: Computed
|
|
|
|
|
where: `${nestedWhere}`, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const response = !isPublic.value |
|
|
|
|
const response = !isPublic |
|
|
|
|
? await api.dbViewRow.list('noco', base.value.id, view.value.fk_model_id, view.value.id, { |
|
|
|
|
...query, |
|
|
|
|
...params, |
|
|
|
@ -419,12 +421,10 @@ export const useViewGroupBy = (view: Ref<ViewType | undefined>, where?: Computed
|
|
|
|
|
if (groupBy.value.length > 0) { |
|
|
|
|
rootGroup.value.paginationData = { page: 1, pageSize: groupByGroupLimit.value } |
|
|
|
|
rootGroup.value.column = {} as any |
|
|
|
|
await loadGroups() |
|
|
|
|
refreshNested() |
|
|
|
|
nextTick(() => reloadViewDataHook?.trigger()) |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
{ immediate: true }, |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
const findGroupByNestedIn = (nestedIn: GroupNestedIn[], group?: Group, nestLevel = 0): Group => { |
|
|
|
@ -541,12 +541,11 @@ export const useViewGroupBy = (view: Ref<ViewType | undefined>, where?: Computed
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
onMounted(async () => { |
|
|
|
|
await loadAllowedLookups() |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
watch(meta, async () => { |
|
|
|
|
watch([() => view?.value?.id, () => meta.value?.columns], async ([newViewId]) => { |
|
|
|
|
// reload only if view belongs to current table
|
|
|
|
|
if (newViewId && view.value?.fk_model_id === meta.value?.id) { |
|
|
|
|
await loadAllowedLookups() |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
return { |
|
|
|
@ -561,4 +560,14 @@ export const useViewGroupBy = (view: Ref<ViewType | undefined>, where?: Computed
|
|
|
|
|
groupWrapperChangePage, |
|
|
|
|
redistributeRows, |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
'useViewGroupBy', |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
export { useProvideViewGroupBy } |
|
|
|
|
|
|
|
|
|
export function useViewGroupByOrThrow() { |
|
|
|
|
const viewColumns = useViewGroupBy() |
|
|
|
|
if (viewColumns == null) throw new Error('Please call `useProvideViewGroupBy` on the appropriate parent component') |
|
|
|
|
return viewColumns |
|
|
|
|
} |
|
|
|
|