From 49a2edf19ed7f6fc5576ff100ae8cec4702be9e6 Mon Sep 17 00:00:00 2001 From: Artyom Savchenko Date: Mon, 20 Apr 2026 13:06:57 +0700 Subject: [PATCH] Fix tracker project actions (#10786) * Fix tracker project actions Signed-off-by: Artem Savchenko * Revert "Fix tracker project actions" This reverts commit 586c6562bd50674d3fb49bdbbbc95ada0311cf11. * Convert docs for all actions Signed-off-by: Artem Savchenko * Clean up Signed-off-by: Artem Savchenko * Clean up Signed-off-by: Artem Savchenko --------- Signed-off-by: Artem Savchenko --- plugins/view-resources/src/actions.ts | 16 ++++++++++++++-- .../src/components/ActionsPopup.svelte | 4 ++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/plugins/view-resources/src/actions.ts b/plugins/view-resources/src/actions.ts index 3c0cbc5d1e..6a7d291573 100644 --- a/plugins/view-resources/src/actions.ts +++ b/plugins/view-resources/src/actions.ts @@ -41,6 +41,18 @@ import view from './plugin' import { type FocusSelection, type SelectionStore } from './selection' import { restrictionStore } from './utils' +/** + * Collapses a single-element array to the element, otherwise returns the original value. + * + * @public + */ +export function normalizeActionContext (doc: T | T[] | undefined): T | T[] | undefined { + if (Array.isArray(doc) && doc.length === 1) { + return doc[0] + } + return doc +} + /** * @public */ @@ -114,7 +126,7 @@ export async function filterAvailableActions ( } else { const visibilityTester = await getResource(action.visibilityTester) - if (await visibilityTester(doc)) { + if (await visibilityTester(normalizeActionContext(doc))) { result.push(action) } } @@ -132,7 +144,7 @@ export async function invokeAction ( ): Promise { const impl = await getResource(action.action) Analytics.handleEvent(action.analyticsEvent ?? action._id) - await impl(Array.isArray(object) && object.length === 1 ? object[0] : object, evt, { + await impl(normalizeActionContext(object), evt, { ...action.actionProps, ...props }) diff --git a/plugins/view-resources/src/components/ActionsPopup.svelte b/plugins/view-resources/src/components/ActionsPopup.svelte index 8719fa8206..0b11ffed81 100644 --- a/plugins/view-resources/src/components/ActionsPopup.svelte +++ b/plugins/view-resources/src/components/ActionsPopup.svelte @@ -51,7 +51,7 @@ } from '@hcengineering/ui' import { Action, ActionCategory, ViewContext } from '@hcengineering/view' import { createEventDispatcher, onMount, tick } from 'svelte' - import { filterActions, getSelection } from '../actions' + import { filterActions, getSelection, normalizeActionContext } from '../actions' import view from '../plugin' import { focusStore, selectionStore } from '../selection' import { openDoc } from '../utils' @@ -99,7 +99,7 @@ } else { const visibilityTester = await getResource(action.visibilityTester) - if (await visibilityTester(docs)) { + if (await visibilityTester(normalizeActionContext(docs))) { resultActions.push(action) } }