Fix custom field grouping (#8537)

This commit is contained in:
Denis Bykhov 2025-04-11 20:25:11 +05:00 committed by GitHub
parent 4ec4609364
commit cd2cc7528c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -21,6 +21,7 @@
import { focusStore } from '../selection' import { focusStore } from '../selection'
import { setViewOptions } from '../viewOptions' import { setViewOptions } from '../viewOptions'
import ViewOptionsEditor from './ViewOptions.svelte' import ViewOptionsEditor from './ViewOptions.svelte'
import core, { Class, Doc, Hierarchy, Ref } from '@hcengineering/core'
export let viewlet: Viewlet | undefined export let viewlet: Viewlet | undefined
export let kind: 'primary' | 'secondary' | 'tertiary' | 'negative' = 'secondary' export let kind: 'primary' | 'secondary' | 'tertiary' | 'negative' = 'secondary'
@ -34,6 +35,15 @@
let btn: HTMLButtonElement let btn: HTMLButtonElement
let pressed: boolean = false let pressed: boolean = false
function getGroupingCustomAttributes (h: Hierarchy, _class: Ref<Class<Doc>>): string[] {
const customAttributes = [...h.getOwnAttributes(_class).values()]
.filter(
(attr) => attr.isCustom && !attr.isHidden && [core.class.RefTo, core.class.EnumOf].includes(attr.type._class)
)
.map((a) => a.name)
return customAttributes
}
async function clickHandler (): Promise<void> { async function clickHandler (): Promise<void> {
if (viewlet === undefined) { if (viewlet === undefined) {
return return
@ -46,6 +56,10 @@
config.other = viewOptionsConfig config.other = viewOptionsConfig
} }
const customAttributes = getGroupingCustomAttributes(h, viewlet.attachTo)
config.groupBy = Array.from(new Set([...config.groupBy, ...customAttributes]))
showPopup( showPopup(
ViewOptionsEditor, ViewOptionsEditor,
{ viewlet, config, viewOptions: h.clone(viewOptions) }, { viewlet, config, viewOptions: h.clone(viewOptions) },