mirror of
https://github.com/hcengineering/platform.git
synced 2025-02-02 17:02:29 +00:00
UBERF-7817: Fix tag element query (#6267)
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
parent
1c1d0bc538
commit
949f33380c
@ -58,30 +58,40 @@
|
|||||||
{@const removeMessages = valueMessages.filter(({ action }) => action === 'remove')}
|
{@const removeMessages = valueMessages.filter(({ action }) => action === 'remove')}
|
||||||
{@const createMessages = valueMessages.filter(({ action }) => action === 'create')}
|
{@const createMessages = valueMessages.filter(({ action }) => action === 'create')}
|
||||||
|
|
||||||
|
{@const createMessagesLen = createMessages.length}
|
||||||
|
{@const removeMessagesLen = removeMessages.length}
|
||||||
|
|
||||||
{#each createMessages as valueMessage, index}
|
{#each createMessages as valueMessage, index}
|
||||||
<DocUpdateMessageObjectValue
|
<DocUpdateMessageObjectValue
|
||||||
message={valueMessage}
|
objectClass={valueMessage.objectClass}
|
||||||
|
objectId={valueMessage.objectId}
|
||||||
|
action={valueMessage.action}
|
||||||
{viewlet}
|
{viewlet}
|
||||||
withIcon={index === 0}
|
withIcon={index === 0}
|
||||||
hasSeparator={createMessages.length > 1 && index !== createMessages.length - 1}
|
hasSeparator={createMessagesLen > 1 && index !== createMessagesLen - 1}
|
||||||
{preview}
|
{preview}
|
||||||
/>
|
/>
|
||||||
{/each}
|
{/each}
|
||||||
{#each removeMessages as valueMessage, index}
|
{#each removeMessages as valueMessage, index}
|
||||||
<DocUpdateMessageObjectValue
|
<DocUpdateMessageObjectValue
|
||||||
message={valueMessage}
|
objectClass={valueMessage.objectClass}
|
||||||
|
objectId={valueMessage.objectId}
|
||||||
|
action={valueMessage.action}
|
||||||
{viewlet}
|
{viewlet}
|
||||||
withIcon={index === 0}
|
withIcon={index === 0}
|
||||||
hasSeparator={removeMessages.length > 1 && index !== removeMessages.length - 1}
|
hasSeparator={removeMessagesLen > 1 && index !== removeMessagesLen - 1}
|
||||||
{preview}
|
{preview}
|
||||||
/>
|
/>
|
||||||
{/each}
|
{/each}
|
||||||
{:else}
|
{:else}
|
||||||
|
{@const len = valueMessages.length}
|
||||||
{#each valueMessages as valueMessage, index}
|
{#each valueMessages as valueMessage, index}
|
||||||
<DocUpdateMessageObjectValue
|
<DocUpdateMessageObjectValue
|
||||||
message={valueMessage}
|
objectClass={valueMessage.objectClass}
|
||||||
|
objectId={valueMessage.objectId}
|
||||||
|
action={valueMessage.action}
|
||||||
{viewlet}
|
{viewlet}
|
||||||
hasSeparator={valueMessages.length > 1 && index !== valueMessages.length - 1}
|
hasSeparator={len > 1 && index !== len - 1}
|
||||||
{preview}
|
{preview}
|
||||||
/>
|
/>
|
||||||
{/each}
|
{/each}
|
||||||
|
@ -13,14 +13,16 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
-->
|
-->
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { buildRemovedDoc, checkIsObjectRemoved, DocNavLink, getDocLinkTitle } from '@hcengineering/view-resources'
|
|
||||||
import { Component, Icon, IconAdd, IconDelete } from '@hcengineering/ui'
|
|
||||||
import { createQuery, getClient } from '@hcengineering/presentation'
|
|
||||||
import view from '@hcengineering/view'
|
|
||||||
import { Class, Doc, Ref } from '@hcengineering/core'
|
|
||||||
import { DisplayDocUpdateMessage, DocUpdateMessageViewlet } from '@hcengineering/activity'
|
import { DisplayDocUpdateMessage, DocUpdateMessageViewlet } from '@hcengineering/activity'
|
||||||
|
import { Class, Doc, Ref } from '@hcengineering/core'
|
||||||
|
import { createQuery, getClient } from '@hcengineering/presentation'
|
||||||
|
import { Component, Icon, IconAdd, IconDelete } from '@hcengineering/ui'
|
||||||
|
import view from '@hcengineering/view'
|
||||||
|
import { buildRemovedDoc, checkIsObjectRemoved, DocNavLink, getDocLinkTitle } from '@hcengineering/view-resources'
|
||||||
|
|
||||||
export let message: DisplayDocUpdateMessage
|
export let objectClass: DisplayDocUpdateMessage['objectClass']
|
||||||
|
export let objectId: DisplayDocUpdateMessage['objectId']
|
||||||
|
export let action: DisplayDocUpdateMessage['action']
|
||||||
export let viewlet: DocUpdateMessageViewlet | undefined
|
export let viewlet: DocUpdateMessageViewlet | undefined
|
||||||
export let withIcon: boolean = false
|
export let withIcon: boolean = false
|
||||||
export let hasSeparator: boolean = false
|
export let hasSeparator: boolean = false
|
||||||
@ -32,8 +34,8 @@
|
|||||||
|
|
||||||
let object: Doc | undefined = undefined
|
let object: Doc | undefined = undefined
|
||||||
|
|
||||||
$: objectPanel = hierarchy.classHierarchyMixin(message.objectClass, view.mixin.ObjectPanel)
|
$: objectPanel = hierarchy.classHierarchyMixin(objectClass, view.mixin.ObjectPanel)
|
||||||
$: objectPresenter = hierarchy.classHierarchyMixin(message.objectClass, view.mixin.ObjectPresenter)
|
$: objectPresenter = hierarchy.classHierarchyMixin(objectClass, view.mixin.ObjectPresenter)
|
||||||
|
|
||||||
async function getValue (object: Doc): Promise<string | undefined> {
|
async function getValue (object: Doc): Promise<string | undefined> {
|
||||||
if (viewlet?.valueAttr) {
|
if (viewlet?.valueAttr) {
|
||||||
@ -48,6 +50,7 @@
|
|||||||
|
|
||||||
if (isRemoved) {
|
if (isRemoved) {
|
||||||
object = await buildRemovedDoc(client, _id, _class)
|
object = await buildRemovedDoc(client, _id, _class)
|
||||||
|
objectQuery.unsubscribe()
|
||||||
} else {
|
} else {
|
||||||
objectQuery.query(_class, { _id }, (res) => {
|
objectQuery.query(_class, { _id }, (res) => {
|
||||||
object = res[0]
|
object = res[0]
|
||||||
@ -55,14 +58,14 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$: void loadObject(message.objectId, message.objectClass)
|
$: void loadObject(objectId, objectClass)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if object}
|
{#if object}
|
||||||
{#if withIcon && message.action === 'create'}
|
{#if withIcon && action === 'create'}
|
||||||
<Icon icon={IconAdd} size="x-small" />
|
<Icon icon={IconAdd} size="x-small" />
|
||||||
{/if}
|
{/if}
|
||||||
{#if withIcon && message.action === 'remove'}
|
{#if withIcon && action === 'remove'}
|
||||||
<Icon icon={IconDelete} size="x-small" />
|
<Icon icon={IconDelete} size="x-small" />
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
@ -80,7 +83,7 @@
|
|||||||
<DocNavLink
|
<DocNavLink
|
||||||
{object}
|
{object}
|
||||||
colorInherit
|
colorInherit
|
||||||
disabled={message.action === 'remove'}
|
disabled={action === 'remove'}
|
||||||
component={objectPanel?.component ?? view.component.EditDoc}
|
component={objectPanel?.component ?? view.component.EditDoc}
|
||||||
shrink={0}
|
shrink={0}
|
||||||
>
|
>
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
import { Account, AttachedDoc, Class, Collection, Doc, Ref, Space } from '@hcengineering/core'
|
import { Account, AttachedDoc, Class, Collection, Doc, Ref, Space } from '@hcengineering/core'
|
||||||
import { IntlString } from '@hcengineering/platform'
|
import { IntlString } from '@hcengineering/platform'
|
||||||
import { createQuery, getClient } from '@hcengineering/presentation'
|
import { createQuery, getClient } from '@hcengineering/presentation'
|
||||||
import { Component, ShowMore, Action } from '@hcengineering/ui'
|
import { Action, Component, ShowMore } from '@hcengineering/ui'
|
||||||
import { AttributeModel } from '@hcengineering/view'
|
import { AttributeModel } from '@hcengineering/view'
|
||||||
import { buildRemovedDoc, checkIsObjectRemoved } from '@hcengineering/view-resources'
|
import { buildRemovedDoc, checkIsObjectRemoved } from '@hcengineering/view-resources'
|
||||||
|
|
||||||
@ -144,17 +144,17 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function loadParentObject (
|
async function loadParentObject (
|
||||||
message: DocUpdateMessage,
|
message: Pick<DocUpdateMessage, 'attachedTo' | 'attachedToClass' | 'objectId' | 'space'>,
|
||||||
parentMessage?: ActivityMessage,
|
parentMessage?: Pick<ActivityMessage, 'attachedTo' | 'space' | 'attachedToClass'>,
|
||||||
doc?: Doc
|
doc?: Doc
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
if (!parentMessage && message.objectId === message.attachedTo) {
|
if (parentMessage === undefined && message.objectId === message.attachedTo) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const _id = parentMessage ? parentMessage.attachedTo : message.attachedTo
|
const _id = parentMessage !== undefined ? parentMessage.attachedTo : message.attachedTo
|
||||||
const _class = parentMessage ? parentMessage.attachedToClass : message.attachedToClass
|
const _class = parentMessage !== undefined ? parentMessage.attachedToClass : message.attachedToClass
|
||||||
const space = parentMessage ? parentMessage.space : message.space
|
const space = parentMessage !== undefined ? parentMessage.space : message.space
|
||||||
|
|
||||||
if (doc !== undefined && doc._id === _id) {
|
if (doc !== undefined && doc._id === _id) {
|
||||||
parentObject = doc
|
parentObject = doc
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
-->
|
-->
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Class, Doc, IdMap, Ref, toIdMap } from '@hcengineering/core'
|
import { Class, Doc, Ref } from '@hcengineering/core'
|
||||||
import { createQuery, getClient, KeyedAttribute } from '@hcengineering/presentation'
|
import { createQuery, getClient, KeyedAttribute } from '@hcengineering/presentation'
|
||||||
import { TagElement, TagReference } from '@hcengineering/tags'
|
import { TagElement, TagReference } from '@hcengineering/tags'
|
||||||
import tags from '../plugin'
|
import tags from '../plugin'
|
||||||
@ -52,16 +52,9 @@
|
|||||||
async function updateWeight (tag: TagReference, weight: TagReference['weight']): Promise<void> {
|
async function updateWeight (tag: TagReference, weight: TagReference['weight']): Promise<void> {
|
||||||
await client.update(tag, { weight })
|
await client.update(tag, { weight })
|
||||||
}
|
}
|
||||||
|
|
||||||
let elements: IdMap<TagElement> = new Map()
|
|
||||||
const elementQuery = createQuery()
|
|
||||||
$: elementQuery.query(tags.class.TagElement, {}, (result) => {
|
|
||||||
elements = toIdMap(result)
|
|
||||||
})
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<TagsEditor
|
<TagsEditor
|
||||||
bind:elements
|
|
||||||
{key}
|
{key}
|
||||||
bind:items
|
bind:items
|
||||||
targetClass={_class}
|
targetClass={_class}
|
||||||
|
@ -13,9 +13,17 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
-->
|
-->
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { AttachedDoc, Class, Collection, Doc, Ref } from '@hcengineering/core'
|
import {
|
||||||
|
toIdMap,
|
||||||
|
type AttachedDoc,
|
||||||
|
type Class,
|
||||||
|
type Collection,
|
||||||
|
type Doc,
|
||||||
|
type IdMap,
|
||||||
|
type Ref
|
||||||
|
} from '@hcengineering/core'
|
||||||
import { translate } from '@hcengineering/platform'
|
import { translate } from '@hcengineering/platform'
|
||||||
import { KeyedAttribute } from '@hcengineering/presentation'
|
import { createQuery, KeyedAttribute } from '@hcengineering/presentation'
|
||||||
import { TagElement, TagReference } from '@hcengineering/tags'
|
import { TagElement, TagReference } from '@hcengineering/tags'
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
@ -37,9 +45,14 @@
|
|||||||
export let targetClass: Ref<Class<Doc>>
|
export let targetClass: Ref<Class<Doc>>
|
||||||
export let key: KeyedAttribute
|
export let key: KeyedAttribute
|
||||||
export let showTitle = true
|
export let showTitle = true
|
||||||
export let elements: Map<Ref<TagElement>, TagElement>
|
|
||||||
export let schema: '0' | '3' | '9' = key.attr.schema ?? '0'
|
export let schema: '0' | '3' | '9' = key.attr.schema ?? '0'
|
||||||
|
|
||||||
|
let elements: IdMap<TagElement> = new Map()
|
||||||
|
const elementQuery = createQuery()
|
||||||
|
$: elementQuery.query(tags.class.TagElement, { _id: { $in: items.map((it) => it.tag) } }, (result) => {
|
||||||
|
elements = toIdMap(result)
|
||||||
|
})
|
||||||
|
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
|
|
||||||
let keyLabel: string = ''
|
let keyLabel: string = ''
|
||||||
|
Loading…
Reference in New Issue
Block a user