-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! fix(files): simplify active store handling
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
- Loading branch information
Showing
5 changed files
with
80 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
import type { FileAction } from '@nextcloud/files' | ||
|
||
import { NodeStatus } from '@nextcloud/files' | ||
import { showError, showSuccess } from '@nextcloud/dialogs' | ||
import { t } from '@nextcloud/l10n' | ||
import Vue from 'vue' | ||
|
||
import { useActiveStore } from '../store/active' | ||
import logger from '../logger' | ||
|
||
/** | ||
* Execute an action on the current active node | ||
* | ||
* @param action The action to execute | ||
*/ | ||
export async function executeAction(action: FileAction) { | ||
const activeStore = useActiveStore() | ||
const currentDir = (window.OCP.Files.Router?.query?.dir || '/') as string | ||
const currentNode = activeStore.activeNode | ||
const currentView = activeStore.activeView | ||
|
||
if (!action.enabled!([currentNode], currentView)) { | ||
logger.debug('Action is not not available for the current context', { action, node: currentNode, view: currentView }) | ||
return | ||
} | ||
|
||
let displayName = action.id | ||
try { | ||
displayName = action.displayName([currentNode], currentView) | ||
} catch (error) { | ||
logger.error('Error while getting action display name', { action, error }) | ||
} | ||
|
||
try { | ||
// Set the loading marker | ||
Vue.set(currentNode, 'status', NodeStatus.LOADING) | ||
|
||
const success = await action.exec(currentNode, currentView, currentDir) | ||
|
||
// If the action returns null, we stay silent | ||
if (success === null || success === undefined) { | ||
return | ||
} | ||
|
||
if (success) { | ||
showSuccess(t('files', '"{displayName}" action executed successfully', { displayName })) | ||
return | ||
} | ||
showError(t('files', '"{displayName}" action failed', { displayName })) | ||
} catch (error) { | ||
logger.error('Error while executing action', { action, error }) | ||
showError(t('files', '"{displayName}" action failed', { displayName })) | ||
} finally { | ||
// Reset the loading marker | ||
Vue.set(currentNode, 'status', undefined) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters