Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down
35 changes: 19 additions & 16 deletions plugins/card-resources/src/components/settings/view/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
const enabledAttributes = items.filter((it) => it.type === 'attribute' && it.enabled).map((it) => it.value)

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
if (typeof configItem === 'string') {
return enabledAttibutes.includes(configItem)
} else if (configItem !== undefined && typeof configItem === 'object') {
return enabledAttibutes.includes(configItem.key)
}
return false
return enabledAttributes.some((attr) => isMatch(configItem, attr))
})

const newAttributes = enabledAttibutes.filter((attr) => {
if (
viewlet.config.some((configItem) => {
return typeof configItem === 'string' ? configItem === attr : configItem.key === attr
})
) {
return false
}
return true
const newAttributes = enabledAttributes.filter((attr) => {
return !viewlet.config.some((configItem) => isMatch(configItem, attr))
})

viewlet.config = viewlet.config.concat(newAttributes)
Expand Down
30 changes: 21 additions & 9 deletions plugins/view-resources/src/components/ViewletSetting.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down
Loading