Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UBERF-7817: Fix tag element query #6267

Merged
merged 1 commit into from
Aug 6, 2024
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 @@ -58,30 +58,40 @@
{@const removeMessages = valueMessages.filter(({ action }) => action === 'remove')}
{@const createMessages = valueMessages.filter(({ action }) => action === 'create')}

{@const createMessagesLen = createMessages.length}
{@const removeMessagesLen = removeMessages.length}

{#each createMessages as valueMessage, index}
<DocUpdateMessageObjectValue
message={valueMessage}
objectClass={valueMessage.objectClass}
objectId={valueMessage.objectId}
action={valueMessage.action}
{viewlet}
withIcon={index === 0}
hasSeparator={createMessages.length > 1 && index !== createMessages.length - 1}
hasSeparator={createMessagesLen > 1 && index !== createMessagesLen - 1}
{preview}
/>
{/each}
{#each removeMessages as valueMessage, index}
<DocUpdateMessageObjectValue
message={valueMessage}
objectClass={valueMessage.objectClass}
objectId={valueMessage.objectId}
action={valueMessage.action}
{viewlet}
withIcon={index === 0}
hasSeparator={removeMessages.length > 1 && index !== removeMessages.length - 1}
hasSeparator={removeMessagesLen > 1 && index !== removeMessagesLen - 1}
{preview}
/>
{/each}
{:else}
{@const len = valueMessages.length}
{#each valueMessages as valueMessage, index}
<DocUpdateMessageObjectValue
message={valueMessage}
objectClass={valueMessage.objectClass}
objectId={valueMessage.objectId}
action={valueMessage.action}
{viewlet}
hasSeparator={valueMessages.length > 1 && index !== valueMessages.length - 1}
hasSeparator={len > 1 && index !== len - 1}
{preview}
/>
{/each}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@
// limitations under the License.
-->
<script lang="ts">
import { buildRemovedDoc, checkIsObjectRemoved, DocNavLink, getDocLinkTitle } from '@hcengineering/view-resources'
import { Component, Icon, IconAdd, IconDelete } from '@hcengineering/ui'
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 { Class, Doc, Ref } from '@hcengineering/core'
import { DisplayDocUpdateMessage, DocUpdateMessageViewlet } from '@hcengineering/activity'
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 withIcon: boolean = false
export let hasSeparator: boolean = false
Expand All @@ -32,8 +34,8 @@

let object: Doc | undefined = undefined

$: objectPanel = hierarchy.classHierarchyMixin(message.objectClass, view.mixin.ObjectPanel)
$: objectPresenter = hierarchy.classHierarchyMixin(message.objectClass, view.mixin.ObjectPresenter)
$: objectPanel = hierarchy.classHierarchyMixin(objectClass, view.mixin.ObjectPanel)
$: objectPresenter = hierarchy.classHierarchyMixin(objectClass, view.mixin.ObjectPresenter)

async function getValue (object: Doc): Promise<string | undefined> {
if (viewlet?.valueAttr) {
Expand All @@ -48,21 +50,22 @@

if (isRemoved) {
object = await buildRemovedDoc(client, _id, _class)
objectQuery.unsubscribe()
} else {
objectQuery.query(_class, { _id }, (res) => {
object = res[0]
})
}
}

$: void loadObject(message.objectId, message.objectClass)
$: void loadObject(objectId, objectClass)
</script>

{#if object}
{#if withIcon && message.action === 'create'}
{#if withIcon && action === 'create'}
<Icon icon={IconAdd} size="x-small" />
{/if}
{#if withIcon && message.action === 'remove'}
{#if withIcon && action === 'remove'}
<Icon icon={IconDelete} size="x-small" />
{/if}

Expand All @@ -80,7 +83,7 @@
<DocNavLink
{object}
colorInherit
disabled={message.action === 'remove'}
disabled={action === 'remove'}
component={objectPanel?.component ?? view.component.EditDoc}
shrink={0}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import { Account, AttachedDoc, Class, Collection, Doc, Ref, Space } from '@hcengineering/core'
import { IntlString } from '@hcengineering/platform'
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 { buildRemovedDoc, checkIsObjectRemoved } from '@hcengineering/view-resources'

Expand Down Expand Up @@ -144,17 +144,17 @@
}

async function loadParentObject (
message: DocUpdateMessage,
parentMessage?: ActivityMessage,
message: Pick<DocUpdateMessage, 'attachedTo' | 'attachedToClass' | 'objectId' | 'space'>,
parentMessage?: Pick<ActivityMessage, 'attachedTo' | 'space' | 'attachedToClass'>,
doc?: Doc
): Promise<void> {
if (!parentMessage && message.objectId === message.attachedTo) {
if (parentMessage === undefined && message.objectId === message.attachedTo) {
return
}

const _id = parentMessage ? parentMessage.attachedTo : message.attachedTo
const _class = parentMessage ? parentMessage.attachedToClass : message.attachedToClass
const space = parentMessage ? parentMessage.space : message.space
const _id = parentMessage !== undefined ? parentMessage.attachedTo : message.attachedTo
const _class = parentMessage !== undefined ? parentMessage.attachedToClass : message.attachedToClass
const space = parentMessage !== undefined ? parentMessage.space : message.space

if (doc !== undefined && doc._id === _id) {
parentObject = doc
Expand Down
9 changes: 1 addition & 8 deletions plugins/tags-resources/src/components/Tags.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.
-->
<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 { TagElement, TagReference } from '@hcengineering/tags'
import tags from '../plugin'
Expand Down Expand Up @@ -52,16 +52,9 @@
async function updateWeight (tag: TagReference, weight: TagReference['weight']): Promise<void> {
await client.update(tag, { weight })
}

let elements: IdMap<TagElement> = new Map()
const elementQuery = createQuery()
$: elementQuery.query(tags.class.TagElement, {}, (result) => {
elements = toIdMap(result)
})
</script>

<TagsEditor
bind:elements
{key}
bind:items
targetClass={_class}
Expand Down
19 changes: 16 additions & 3 deletions plugins/tags-resources/src/components/TagsEditor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,17 @@
// limitations under the License.
-->
<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 { KeyedAttribute } from '@hcengineering/presentation'
import { createQuery, KeyedAttribute } from '@hcengineering/presentation'
import { TagElement, TagReference } from '@hcengineering/tags'
import {
Button,
Expand All @@ -37,9 +45,14 @@
export let targetClass: Ref<Class<Doc>>
export let key: KeyedAttribute
export let showTitle = true
export let elements: Map<Ref<TagElement>, TagElement>
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()

let keyLabel: string = ''
Expand Down