From d35e03d01376fee70590ed9c7e837dda9b4713c3 Mon Sep 17 00:00:00 2001 From: mertmit Date: Fri, 3 May 2024 18:54:37 +0000 Subject: [PATCH] fix: group by belongs to --- packages/nc-gui/composables/useViewGroupBy.ts | 19 +++++++++++++++++-- packages/nc-gui/lib/types.ts | 1 + 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/packages/nc-gui/composables/useViewGroupBy.ts b/packages/nc-gui/composables/useViewGroupBy.ts index dafe5c8683..de77407440 100644 --- a/packages/nc-gui/composables/useViewGroupBy.ts +++ b/packages/nc-gui/composables/useViewGroupBy.ts @@ -121,7 +121,7 @@ const [useProvideViewGroupBy, useViewGroupBy] = useInjectionState( rowMeta: {}, })) - const valueToTitle = (value: string, col: ColumnType) => { + const valueToTitle = (value: string, col: ColumnType, displayValueProp?: string) => { if (col.uidt === UITypes.Checkbox) { return value ? GROUP_BY_VARS.TRUE : GROUP_BY_VARS.FALSE } @@ -132,6 +132,10 @@ const [useProvideViewGroupBy, useViewGroupBy] = useInjectionState( } } + if (col.uidt === UITypes.LinkToAnotherRecord && displayValueProp && value && typeof value === 'object') { + return value[displayValueProp] ?? GROUP_BY_VARS.NULL + } + // convert to JSON string if non-string value if (value && typeof value === 'object') { value = JSON.stringify(value) @@ -238,6 +242,14 @@ const [useProvideViewGroupBy, useViewGroupBy] = useInjectionState( return } + if (groupby.column.uidt === UITypes.LinkToAnotherRecord) { + const relatedTableMeta = await getMeta( + (groupby.column.colOptions as LinkToAnotherRecordType).fk_related_model_id as string, + ) + if (!relatedTableMeta) return + group.displayValueProp = (relatedTableMeta.columns?.find((c) => c.pv) || relatedTableMeta.columns?.[0])?.title || '' + } + 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), @@ -464,7 +476,10 @@ const [useProvideViewGroupBy, useViewGroupBy] = useInjectionState( if (group.nested) { const child = group.children?.find((g) => { if (!groupBy.value[nestLevel].column.title) return undefined - return g.key === valueToTitle(row.row[groupBy.value[nestLevel].column.title!], groupBy.value[nestLevel].column) + return ( + g.key === + valueToTitle(row.row[groupBy.value[nestLevel].column.title!], groupBy.value[nestLevel].column, group.displayValueProp) + ) }) if (child) { return findGroupForRow(row, child, nestLevel + 1) diff --git a/packages/nc-gui/lib/types.ts b/packages/nc-gui/lib/types.ts index a4361cd150..c32fdab28b 100644 --- a/packages/nc-gui/lib/types.ts +++ b/packages/nc-gui/lib/types.ts @@ -178,6 +178,7 @@ interface Group { children?: Group[] rows?: Row[] root?: boolean + displayValueProp?: string } interface GroupNestedIn {