Browse Source

fix: group by belongs to

pull/8389/head
mertmit 7 months ago
parent
commit
d35e03d013
  1. 19
      packages/nc-gui/composables/useViewGroupBy.ts
  2. 1
      packages/nc-gui/lib/types.ts

19
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)

1
packages/nc-gui/lib/types.ts

@ -178,6 +178,7 @@ interface Group {
children?: Group[]
rows?: Row[]
root?: boolean
displayValueProp?: string
}
interface GroupNestedIn {

Loading…
Cancel
Save