mirror of
https://github.com/hcengineering/platform.git
synced 2026-08-17 18:05:42 +02:00
Fix tracker project actions (#10786)
* Fix tracker project actions
Signed-off-by: Artem Savchenko <armisav@gmail.com>
* Revert "Fix tracker project actions"
This reverts commit 586c6562bd.
* Convert docs for all actions
Signed-off-by: Artem Savchenko <armisav@gmail.com>
* Clean up
Signed-off-by: Artem Savchenko <armisav@gmail.com>
* Clean up
Signed-off-by: Artem Savchenko <armisav@gmail.com>
---------
Signed-off-by: Artem Savchenko <armisav@gmail.com>
This commit is contained in:
@@ -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<T extends Doc> (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<void> {
|
||||
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
|
||||
})
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user