22 * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
33 * SPDX-License-Identifier: AGPL-3.0-or-later
44 */
5- import type { FileAction } from '@nextcloud/files'
5+ import type { ActionContextSingle , FileAction } from '@nextcloud/files'
66
77import { showError , showSuccess } from '@nextcloud/dialogs'
88import { NodeStatus } from '@nextcloud/files'
99import { t } from '@nextcloud/l10n'
1010import Vue from 'vue'
1111import logger from '../logger.ts'
1212import { useActiveStore } from '../store/active.ts'
13- import { getPinia } from '../store/index.ts'
1413
1514/**
1615 * Execute an action on the current active node
1716 *
1817 * @param action The action to execute
1918 */
2019export async function executeAction ( action : FileAction ) {
21- const activeStore = useActiveStore ( getPinia ( ) )
22- const currentFolder = activeStore . activeFolder !
23- const currentNode = activeStore . activeNode !
24- const currentView = activeStore . activeView !
20+ const activeStore = useActiveStore ( )
21+ const currentFolder = activeStore . activeFolder
22+ const currentNode = activeStore . activeNode
23+ const currentView = activeStore . activeView
2524
26- // @ts -expect-error _children is private
27- const contents = currentFolder ?. _children || [ ]
28-
29- if ( ! currentNode || ! currentView ) {
30- logger . error ( 'No active node or view' , { node : currentNode , view : currentView } )
25+ if ( ! currentFolder || ! currentNode || ! currentView ) {
26+ logger . error ( 'No active folder, node or view' , { folder : currentFolder , node : currentNode , view : currentView } )
3127 return
3228 }
3329
@@ -36,24 +32,23 @@ export async function executeAction(action: FileAction) {
3632 return
3733 }
3834
39- if ( ! action . enabled ! ( {
35+ // @ts -expect-error _children is private
36+ const contents = currentFolder ?. _children || [ ]
37+ const context = {
4038 nodes : [ currentNode ] ,
4139 view : currentView ,
4240 folder : currentFolder ,
4341 contents,
44- } ) ) {
42+ } as ActionContextSingle
43+
44+ if ( ! action . enabled ! ( context ) ) {
4545 logger . debug ( 'Action is not not available for the current context' , { action, node : currentNode , view : currentView } )
4646 return
4747 }
4848
4949 let displayName = action . id
5050 try {
51- displayName = action . displayName ( {
52- nodes : [ currentNode ] ,
53- view : currentView ,
54- folder : currentFolder ,
55- contents,
56- } )
51+ displayName = action . displayName ( context )
5752 } catch ( error ) {
5853 logger . error ( 'Error while getting action display name' , { action, error } )
5954 }
@@ -63,12 +58,7 @@ export async function executeAction(action: FileAction) {
6358 Vue . set ( currentNode , 'status' , NodeStatus . LOADING )
6459 activeStore . activeAction = action
6560
66- const success = await action . exec ( {
67- nodes : [ currentNode ] ,
68- view : currentView ,
69- folder : currentFolder ! ,
70- contents,
71- } )
61+ const success = await action . exec ( context )
7262
7363 // If the action returns null, we stay silent
7464 if ( success === null || success === undefined ) {
0 commit comments