diff --git a/plugins/card-resources/src/components/settings/view/ViewSetting.svelte b/plugins/card-resources/src/components/settings/view/ViewSetting.svelte index 58e72ab0df..c0cb8bbe2b 100644 --- a/plugins/card-resources/src/components/settings/view/ViewSetting.svelte +++ b/plugins/card-resources/src/components/settings/view/ViewSetting.svelte @@ -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 diff --git a/plugins/card-resources/src/components/settings/view/utils.ts b/plugins/card-resources/src/components/settings/view/utils.ts index e4499026e8..ea5f8b3e10 100644 --- a/plugins/card-resources/src/components/settings/view/utils.ts +++ b/plugins/card-resources/src/components/settings/view/utils.ts @@ -2,26 +2,29 @@ import { type Data } from '@hcengineering/core' import { type Viewlet } from '@hcengineering/view' export function updateViewletConfig (viewlet: Data | 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) diff --git a/plugins/view-resources/src/components/ViewletSetting.svelte b/plugins/view-resources/src/components/ViewletSetting.svelte index 1a835298eb..a8f9404739 100644 --- a/plugins/view-resources/src/components/ViewletSetting.svelte +++ b/plugins/view-resources/src/components/ViewletSetting.svelte @@ -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