@@ -10,6 +10,7 @@ import ObjectAttributeContent from '#shared/components/ObjectAttributes/ObjectAt
1010import { useOnEmitter } from ' #shared/composables/useOnEmitter.ts'
1111import { useObjectAttributes } from ' #shared/entities/object-attributes/composables/useObjectAttributes.ts'
1212import type { ObjectAttribute } from ' #shared/entities/object-attributes/types/store.ts'
13+ import { flattenObjectAttributeValues } from ' #shared/entities/object-attributes/utils.ts'
1314import type { TicketById } from ' #shared/entities/ticket/types.ts'
1415import { EnumObjectManagerObjects , EnumOrderDirection } from ' #shared/graphql/types.ts'
1516import { i18n } from ' #shared/i18n.ts'
@@ -296,6 +297,27 @@ const groupByAttributeItemName = computed(() => {
296297 return groupByAttribute .value .dataOption ?.belongs_to || groupByAttribute .value .name
297298})
298299
300+ const extractGroupByValue = (
301+ item : TableAdvancedItem ,
302+ name : string ,
303+ isRelation : boolean ,
304+ ): string | number => {
305+ // Relation: Use related object's identifier in case we're dealing with a relation,
306+ // otherwise use item's own value (e.g. state of a ticket).
307+ const value = (isRelation && item [name ] ? (item [name ] as ObjectLike ).id : item [name ]) as
308+ | string
309+ | number
310+
311+ if (value ) return value
312+
313+ // Custom object manager attribute.
314+ const objectAttributeValues = flattenObjectAttributeValues (
315+ (item as ObjectLike ).objectAttributeValues ,
316+ )
317+
318+ return objectAttributeValues [name ] as string | number
319+ }
320+
299321const groupByRowCounts = computed (() => {
300322 if (! groupByAttribute .value || ! groupByAttributeItemName .value ) return
301323
@@ -306,9 +328,7 @@ const groupByRowCounts = computed(() => {
306328 let lastValue: string | number
307329
308330 return localItems .value .reduce ((groupByRowIds : string [][], item ) => {
309- const value = (isRelation && item [name ] ? (item [name ] as ObjectLike ).id : item [name ]) as
310- | string
311- | number
331+ const value = extractGroupByValue (item , name , isRelation )
312332
313333 if ((lastValue && value !== lastValue ) || (groupByRowIds .length > 0 && ! lastValue && value )) {
314334 groupByValueIndex += 1
0 commit comments