From 26adf14966f52d1cb37baef7920bc3bf02f66f72 Mon Sep 17 00:00:00 2001 From: Denis Bunakalya Date: Fri, 17 Mar 2023 09:11:54 +0300 Subject: [PATCH] Allow to hide actions (#2737) Signed-off-by: Denis Bunakalya --- plugins/view-resources/src/actions.ts | 13 ++++++++++- .../src/components/ActionsPopup.svelte | 23 +++++++++++++++++-- plugins/view/src/index.ts | 3 +++ 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/plugins/view-resources/src/actions.ts b/plugins/view-resources/src/actions.ts index b850963a61..ce871b7087 100644 --- a/plugins/view-resources/src/actions.ts +++ b/plugins/view-resources/src/actions.ts @@ -62,8 +62,19 @@ export async function getActions ( const categories: Record = { top: 1, filter: 50, tools: 100 } - let filteredActions = actions + let filteredActions = [] + for (const action of actions) { + if (action.visibilityTester == null) { + filteredActions.push(action) + } else { + const visibilityTester = await getResource(action.visibilityTester) + + if (await visibilityTester(doc)) { + filteredActions.push(action) + } + } + } if (Array.isArray(doc)) { for (const d of doc) { filteredActions = filterActions(client, d, filteredActions, derived) diff --git a/plugins/view-resources/src/components/ActionsPopup.svelte b/plugins/view-resources/src/components/ActionsPopup.svelte index 05d0c63fea..e3ca39dcb0 100644 --- a/plugins/view-resources/src/components/ActionsPopup.svelte +++ b/plugins/view-resources/src/components/ActionsPopup.svelte @@ -13,7 +13,7 @@ // limitations under the License. -->