From c83d3ae61043717fe3b36d874a522b24b6c5cc9e Mon Sep 17 00:00:00 2001 From: Vyacheslav Tumanov Date: Tue, 30 Jul 2024 18:11:15 +0500 Subject: [PATCH] Have loading option for menu and show only intersecting statuses there Signed-off-by: Vyacheslav Tumanov --- .../src/components/StatusSelector.svelte | 8 ++ .../view-resources/src/components/Menu.svelte | 76 ++++++++++++------- 2 files changed, 55 insertions(+), 29 deletions(-) diff --git a/plugins/task-resources/src/components/StatusSelector.svelte b/plugins/task-resources/src/components/StatusSelector.svelte index 3b7a61b5c0..2220f53193 100644 --- a/plugins/task-resources/src/components/StatusSelector.svelte +++ b/plugins/task-resources/src/components/StatusSelector.svelte @@ -50,6 +50,14 @@ function updateStatuses (taskTypes: IdMap, store: IdMap, kind: Ref | undefined): void { if (kind === undefined) { statuses = [] + if (Array.isArray(value)) { + const statusIds = value + .map((k) => taskTypes.get(k.kind)) + .filter((p) => p !== undefined) + .map((t) => t?.statuses ?? []) + const intersectingStatuses = statusIds[0].filter((p) => statusIds.every((sArray) => sArray.includes(p))) + statuses = intersectingStatuses.map((s) => store.get(s)).filter((p) => p !== undefined) as Status[] + } } else { const type = taskTypes.get(kind) if (type !== undefined) { diff --git a/plugins/view-resources/src/components/Menu.svelte b/plugins/view-resources/src/components/Menu.svelte index c5afb472a7..0a186a1f2f 100644 --- a/plugins/view-resources/src/components/Menu.svelte +++ b/plugins/view-resources/src/components/Menu.svelte @@ -16,7 +16,7 @@ import { Class, Doc, Ref } from '@hcengineering/core' import { Asset } from '@hcengineering/platform' import { getClient } from '@hcengineering/presentation' - import { Action, Menu } from '@hcengineering/ui' + import { Action, Menu, Loading } from '@hcengineering/ui' import { ActionGroup, ViewContextType } from '@hcengineering/view' import { getActions, invokeAction } from '../actions' @@ -42,39 +42,57 @@ remove: 7 } - void getActions(client, object, baseMenuClass, mode).then((result) => { - const filtered = result.filter((a) => { - if (excludedActions.includes(a._id)) { - return false - } - if (includedActions.length > 0 && !includedActions.includes(a._id)) { - return false - } - if (a.override && a.override.filter((o) => excludedActions.includes(o)).length > 0) { - return false + const findAllObjects = async (object: Doc | Doc[]) => { + const objArray = Array.isArray(object) ? object : [object] + const objClass = objArray.map((obj) => obj._class).filter((it, idx, arr) => arr.indexOf(it) === idx) + if (objClass.length === 1) { + const obj = (await client.findAll(objClass[0], { _id: { $in: objArray.map((it) => it._id) } })) as Array + return obj.length === 1 ? obj[0] : obj + } + return object + } + + void findAllObjects(object).then((res) => { + void getActions(client, res, baseMenuClass, mode).then((result) => { + const filtered = result.filter((a) => { + if (excludedActions.includes(a._id)) { + return false + } + if (includedActions.length > 0 && !includedActions.includes(a._id)) { + return false + } + if (a.override && a.override.filter((o) => excludedActions.includes(o)).length > 0) { + return false + } + return true + }) + const newActions: Action[] = filtered.map((a) => ({ + label: a.label, + icon: a.icon as Asset, + inline: a.inline, + group: a.context.group ?? 'other', + action: async (_: any, evt: Event) => { + invokeAction(object, evt, a) + }, + component: a.actionPopup, + props: { ...a.actionProps, value: object } + })) + resActions = [...newActions, ...actions].sort( + (a, b) => (order as any)[a.group ?? 'other'] - (order as any)[b.group ?? 'other'] + ) + if (resActions.length > 0) { + loaded = true } - return true }) - const newActions: Action[] = filtered.map((a) => ({ - label: a.label, - icon: a.icon as Asset, - inline: a.inline, - group: a.context.group ?? 'other', - action: async (_: any, evt: Event) => { - invokeAction(object, evt, a) - }, - component: a.actionPopup, - props: { ...a.actionProps, value: object } - })) - resActions = [...newActions, ...actions].sort( - (a, b) => (order as any)[a.group ?? 'other'] - (order as any)[b.group ?? 'other'] - ) - if (resActions.length > 0) { - loaded = true - } }) {#if loaded} +{:else} +
+
+ +
+
{/if}