Fix view setting bug (#10674)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov
2026-03-24 02:15:33 +05:00
committed by GitHub
parent 31246a11a0
commit deeb8bb545
3 changed files with 62 additions and 35 deletions
@@ -151,11 +151,12 @@
if (hierarchy.isDerived(attribute.type._class, core.class.Collection)) return
const { attrClass, category } = getAttributePresenterClass(hierarchy, attribute.type)
const value = getValue(attribute.name, attribute.type, attrClass)
const proxiedValue = attribute.attributeOf + '.' + attribute.name
for (const res of result) {
const key = typeof res.value === 'string' ? res.value : res.value?.key
if (key === undefined) return
if (key === attribute.name) return
if (key === value) return
const key = getKey(res.value)
if (key === undefined) continue
if (key === attribute.name || key === value || key === proxiedValue) return
if (key === '' && isAttribute(res) && res.label === attribute.label) return
}
const mixin =
category === 'object'
@@ -198,17 +199,28 @@
}
}
function getKey (value: string | BuildModelKey | undefined): string | undefined {
return typeof value === 'string' ? value : value?.key
}
function isAttribute (val: Config): val is AttributeConfig {
return val.type === 'attribute'
}
function isExist (result: Config[], newValue: Config): boolean {
if (!isAttribute(newValue)) return false
const newValueKey = getKey(newValue.value)
if (newValueKey === undefined) return false
for (const res of result) {
if (!isAttribute(res)) continue
if (!isAttribute(newValue)) continue
if (res._class !== newValue._class) continue
if (typeof res.value === 'string') {
if (res.value === newValue.value) return true
if (!isAttribute(res)) {
continue
}
if (getKey(res.value) === newValueKey) {
return true
}
if (newValueKey === '' && res.label === newValue.label) {
return true
}
}
return false
@@ -2,26 +2,29 @@ import { type Data } from '@hcengineering/core'
import { type Viewlet } from '@hcengineering/view'
export function updateViewletConfig (viewlet: Data<Viewlet> | Viewlet, items: any[]): void {
const enabledAttibutes = items.filter((it) => it.type === 'attribute' && it.enabled).map((it) => it.value)
viewlet.config = viewlet.config.filter((configItem) => {
if (configItem === undefined) return false
if (typeof configItem === 'string') {
return enabledAttibutes.includes(configItem)
} else if (configItem !== undefined && typeof configItem === 'object') {
return enabledAttibutes.includes(configItem.key)
}
return false
})
const enabledAttributes = items.filter((it) => it.type === 'attribute' && it.enabled).map((it) => it.value)
const newAttributes = enabledAttibutes.filter((attr) => {
if (
viewlet.config.some((configItem) => {
return typeof configItem === 'string' ? configItem === attr : configItem.key === attr
})
) {
return false
const getKey = (item: any): string | undefined => {
return typeof item === 'string' ? item : item?.key
}
const isMatch = (a: any, b: any): boolean => {
const keyA = getKey(a)
const keyB = getKey(b)
if (keyA !== keyB) return false
if (keyA === '' || keyA === undefined) {
return a === b
}
return true
}
viewlet.config = viewlet.config.filter((configItem) => {
if (configItem === undefined) return false
return enabledAttributes.some((attr) => isMatch(configItem, attr))
})
const newAttributes = enabledAttributes.filter((attr) => {
return !viewlet.config.some((configItem) => isMatch(configItem, attr))
})
viewlet.config = viewlet.config.concat(newAttributes)
@@ -194,11 +194,12 @@
if (hierarchy.isDerived(attribute.type._class, core.class.Collection)) return
const { attrClass, category } = getAttributePresenterClass(hierarchy, attribute.type)
const value = getValue(attribute.name, attribute.type, attrClass)
const proxiedValue = attribute.attributeOf + '.' + attribute.name
for (const res of result) {
const key = typeof res.value === 'string' ? res.value : res.value?.key
if (key === undefined) return
if (key === attribute.name) return
if (key === value) return
const key = getKey(res.value)
if (key === undefined) continue
if (key === attribute.name || key === value || key === proxiedValue) return
if (key === '' && isAttribute(res) && res.label === attribute.label) return
}
const mixin =
category === 'object'
@@ -248,13 +249,24 @@
return val.type === 'attribute'
}
function getKey (value: string | BuildModelKey | undefined): string | undefined {
return typeof value === 'string' ? value : value?.key
}
function isExist (result: Config[], newValue: Config): boolean {
if (!isAttribute(newValue)) return false
const newValueKey = getKey(newValue.value)
if (newValueKey === undefined) return false
for (const res of result) {
if (!isAttribute(res)) continue
if (!isAttribute(newValue)) continue
if (res._class !== newValue._class) continue
if (typeof res.value === 'string') {
if (res.value === newValue.value) return true
if (!isAttribute(res)) {
continue
}
if (getKey(res.value) === newValueKey) {
return true
}
if (newValueKey === '' && res.label === newValue.label) {
return true
}
}
return false