mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-21 07:46:24 +00:00
Allow to hide actions (#2737)
Signed-off-by: Denis Bunakalya <denis.bunakalya@xored.com>
This commit is contained in:
parent
aee24facdf
commit
26adf14966
@ -62,8 +62,19 @@ export async function getActions (
|
|||||||
|
|
||||||
const categories: Record<string, number> = { top: 1, filter: 50, tools: 100 }
|
const categories: Record<string, number> = { 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)) {
|
if (Array.isArray(doc)) {
|
||||||
for (const d of doc) {
|
for (const d of doc) {
|
||||||
filteredActions = filterActions(client, d, filteredActions, derived)
|
filteredActions = filterActions(client, d, filteredActions, derived)
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
-->
|
-->
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { WithLookup } from '@hcengineering/core'
|
import { WithLookup, Doc } from '@hcengineering/core'
|
||||||
import { getResource, translate } from '@hcengineering/platform'
|
import { getResource, translate } from '@hcengineering/platform'
|
||||||
import { createQuery, getClient } from '@hcengineering/presentation'
|
import { createQuery, getClient } from '@hcengineering/presentation'
|
||||||
import ui, { Button, closePopup, Component, Icon, IconArrowLeft, Label } from '@hcengineering/ui'
|
import ui, { Button, closePopup, Component, Icon, IconArrowLeft, Label } from '@hcengineering/ui'
|
||||||
@ -52,13 +52,32 @@
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
let visibleActions: WithLookup<Action>[] = []
|
||||||
let supportedActions: WithLookup<Action>[] = []
|
let supportedActions: WithLookup<Action>[] = []
|
||||||
let filteredActions: WithLookup<Action>[] = []
|
let filteredActions: WithLookup<Action>[] = []
|
||||||
|
|
||||||
|
async function filterVisibleActions (actions: WithLookup<Action>[], docs: Doc[]) {
|
||||||
|
const resultActions: WithLookup<Action>[] = []
|
||||||
|
|
||||||
|
for (const action of actions) {
|
||||||
|
if (!action.visibilityTester) {
|
||||||
|
resultActions.push(action)
|
||||||
|
} else {
|
||||||
|
const visibilityTester = await getResource(action.visibilityTester)
|
||||||
|
|
||||||
|
if (await visibilityTester(docs)) {
|
||||||
|
resultActions.push(action)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
visibleActions = resultActions
|
||||||
|
}
|
||||||
|
$: filterVisibleActions(actions, getSelection($focusStore, $selectionStore))
|
||||||
|
|
||||||
const client = getClient()
|
const client = getClient()
|
||||||
|
|
||||||
$: {
|
$: {
|
||||||
let fActions: WithLookup<Action>[] = actions
|
let fActions: WithLookup<Action>[] = visibleActions
|
||||||
|
|
||||||
const docs = getSelection($focusStore, $selectionStore)
|
const docs = getSelection($focusStore, $selectionStore)
|
||||||
for (const d of docs) {
|
for (const d of docs) {
|
||||||
|
@ -329,6 +329,9 @@ export interface Action<T extends Doc = Doc, P = Record<string, any>> extends Do
|
|||||||
// Action is applicable only for objects matching criteria
|
// Action is applicable only for objects matching criteria
|
||||||
query?: DocumentQuery<T>
|
query?: DocumentQuery<T>
|
||||||
|
|
||||||
|
// Action is shown only if the check is passed
|
||||||
|
visibilityTester?: Resource<(doc?: Doc | Doc[]) => Promise<boolean>>
|
||||||
|
|
||||||
// If defined, types should be matched to proposed list
|
// If defined, types should be matched to proposed list
|
||||||
inputProps?: Record<string, Ref<Class<Doc>>>
|
inputProps?: Record<string, Ref<Class<Doc>>>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user