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