mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-12 19:30:52 +00:00
Value selector cast to mixin (#2657)
Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
parent
598a00c0d6
commit
a6a7d1e145
@ -1,5 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { Class, Doc, DocumentQuery, FindOptions, Hierarchy, Ref } from '@hcengineering/core'
|
||||
import { Class, Doc, DocumentQuery, FindOptions, Hierarchy, Mixin, Ref } from '@hcengineering/core'
|
||||
import { Asset, IntlString } from '@hcengineering/platform'
|
||||
import { getClient, ObjectPopup, updateAttribute } from '@hcengineering/presentation'
|
||||
import { Label, SelectPopup, resizeObserver } from '@hcengineering/ui'
|
||||
@ -13,6 +13,7 @@
|
||||
export let _class: Ref<Class<Doc>> | undefined
|
||||
export let query: DocumentQuery<Doc> | undefined
|
||||
export let queryOptions: FindOptions<Doc> | undefined
|
||||
export let castRequest: Ref<Mixin<Doc>> | undefined = undefined
|
||||
|
||||
export let attribute: string
|
||||
export let searchField: string
|
||||
@ -31,7 +32,8 @@
|
||||
export let size: 'small' | 'medium' | 'large' = 'small'
|
||||
|
||||
const dispatch = createEventDispatcher()
|
||||
|
||||
const client = getClient()
|
||||
const hierarchy = client.getHierarchy()
|
||||
const changeStatus = async (newStatus: any) => {
|
||||
if (newStatus === '#null') {
|
||||
newStatus = null
|
||||
@ -42,18 +44,20 @@
|
||||
return
|
||||
}
|
||||
const docs = Array.isArray(value) ? value : [value]
|
||||
const c = getClient()
|
||||
|
||||
const changed = (d: Doc) => (d as any)[attribute] !== newStatus
|
||||
await Promise.all(
|
||||
docs.filter(changed).map((it) => {
|
||||
// c.update(it, { [attribute]: newStatus } )
|
||||
const cl = Hierarchy.mixinOrClass(it)
|
||||
const attr = c.getHierarchy().getAttribute(cl, attribute)
|
||||
const attr =
|
||||
castRequest !== undefined
|
||||
? hierarchy.getAttribute(castRequest, attribute)
|
||||
: hierarchy.getAttribute(cl, attribute)
|
||||
if (attr === undefined) {
|
||||
throw new Error('attribute not found')
|
||||
}
|
||||
return updateAttribute(c, it, cl, { key: attribute, attr }, newStatus)
|
||||
return updateAttribute(client, it, cl, { key: attribute, attr }, newStatus)
|
||||
})
|
||||
)
|
||||
|
||||
|
@ -721,6 +721,9 @@ const view = plugin(viewId, {
|
||||
docMatches?: string[]
|
||||
searchField?: string
|
||||
|
||||
// Cast doc to mixin
|
||||
castRequest?: Ref<Mixin<Doc>>
|
||||
|
||||
// Or list of values to select from
|
||||
values?: { icon?: Asset, label: IntlString, id: number | string }[]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user