From 95b237b9af3223ecbfbc9932e6e96a0de3bc7dd6 Mon Sep 17 00:00:00 2001 From: Andrey Sobolev Date: Thu, 26 Oct 2023 17:22:57 +0700 Subject: [PATCH] UBER-898: Assignee rules and general rules fix (#3894) Signed-off-by: Andrey Sobolev --- packages/presentation/src/rules.ts | 9 ++++-- .../components/issues/AssigneeEditor.svelte | 29 ++++++++++++++----- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/packages/presentation/src/rules.ts b/packages/presentation/src/rules.ts index aec0fcc42f..fd12dda94e 100644 --- a/packages/presentation/src/rules.ts +++ b/packages/presentation/src/rules.ts @@ -41,9 +41,12 @@ export function getDocRules (documents: Doc | Doc[], field: strin // Check individual rules and form a result query for (const r of rules.fieldRules) { if (r.field === field) { - const _docs = docs.map((doc) => - r.mixin !== undefined && h.hasMixin(doc, r.mixin) ? h.as(doc, r.mixin) : doc - ) + const _docs = docs + .map((doc) => (r.mixin !== undefined ? (h.hasMixin(doc, r.mixin) ? h.as(doc, r.mixin) : undefined) : doc)) + .filter((it) => it) as Doc[] + if (_docs.length === 0) { + continue + } if (matchQuery(_docs, r.query, r.mixin ?? rules.ofClass, h).length === _docs.length) { // We have rule match. if (r.disableUnset === true) { diff --git a/plugins/tracker-resources/src/components/issues/AssigneeEditor.svelte b/plugins/tracker-resources/src/components/issues/AssigneeEditor.svelte index d6849e3091..65ad65b8dd 100644 --- a/plugins/tracker-resources/src/components/issues/AssigneeEditor.svelte +++ b/plugins/tracker-resources/src/components/issues/AssigneeEditor.svelte @@ -17,7 +17,7 @@ import { AssigneeBox, AssigneePopup, personAccountByIdStore } from '@hcengineering/contact-resources' import { AssigneeCategory } from '@hcengineering/contact-resources/src/assignee' import { Account, Doc, DocumentQuery, Ref, Space } from '@hcengineering/core' - import { getClient } from '@hcengineering/presentation' + import { RuleApplyResult, getClient, getDocRules } from '@hcengineering/presentation' import { Component, Issue } from '@hcengineering/tracker' import { ButtonKind, ButtonSize, IconSize, TooltipAlignment } from '@hcengineering/ui' import { createEventDispatcher } from 'svelte' @@ -43,11 +43,12 @@ $: _object = (typeof object !== 'string' ? object : undefined) ?? (typeof value !== 'string' ? value : undefined) ?? [] + $: docs = Array.isArray(_object) ? _object : [_object] + $: cdocs = docs.filter((d) => '_class' in d) as Doc[] + const client = getClient() const dispatch = createEventDispatcher() - const docQuery: DocumentQuery = { active: true } - const handleAssigneeChanged = async (newAssignee: Ref | undefined | null) => { if (newAssignee === undefined || (!Array.isArray(_object) && _object?.assignee === newAssignee)) { return @@ -75,8 +76,6 @@ function getCategories (object: Object | Object[]): void { categories = [] - const docs = Array.isArray(object) ? object : [object] - const cdocs = docs.filter((d) => '_class' in d) as Doc[] if (cdocs.length > 0) { categories.push({ label: tracker.string.PreviousAssigned, @@ -130,12 +129,28 @@ ? _object.assignee : _object.reduce((v, it) => (v != null && v === it.assignee ? it.assignee : null), _object[0]?.assignee) ?? undefined) ?? undefined + + let rulesQuery: RuleApplyResult | undefined + let query: DocumentQuery + $: if (cdocs.length > 0) { + rulesQuery = getDocRules(cdocs, 'assignee') + if (rulesQuery !== undefined) { + query = { ...(rulesQuery?.fieldQuery ?? {}), active: true } + } else { + query = { _id: 'none' as Ref, active: true } + rulesQuery = { + disableEdit: true, + disableUnset: true, + fieldQuery: {} + } + } + } {#if _object} {#if isAction} {:else}