diff options
Diffstat (limited to 'apps/files/src/actions/viewInFolderAction.ts')
-rw-r--r-- | apps/files/src/actions/viewInFolderAction.ts | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/apps/files/src/actions/viewInFolderAction.ts b/apps/files/src/actions/viewInFolderAction.ts new file mode 100644 index 00000000000..b22393c1152 --- /dev/null +++ b/apps/files/src/actions/viewInFolderAction.ts @@ -0,0 +1,68 @@ +/** + * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +import type { Node, View } from '@nextcloud/files' + +import { isPublicShare } from '@nextcloud/sharing/public' +import { FileAction, FileType, Permission } from '@nextcloud/files' +import { t } from '@nextcloud/l10n' + +import FolderMoveSvg from '@mdi/svg/svg/folder-move-outline.svg?raw' + +export const action = new FileAction({ + id: 'view-in-folder', + displayName() { + return t('files', 'View in folder') + }, + iconSvgInline: () => FolderMoveSvg, + + enabled(nodes: Node[], view: View) { + // Not enabled for public shares + if (isPublicShare()) { + return false + } + + // Only works outside of the main files view + if (view.id === 'files') { + return false + } + + // Only works on single node + if (nodes.length !== 1) { + return false + } + + const node = nodes[0] + + if (!node.isDavRessource) { + return false + } + + // Can only view files that are in the user root folder + if (!node.root?.startsWith('/files')) { + return false + } + + if (node.permissions === Permission.NONE) { + return false + } + + return node.type === FileType.File + }, + + async exec(node: Node) { + if (!node || node.type !== FileType.File) { + return false + } + + window.OCP.Files.Router.goToRoute( + null, + { view: 'files', fileid: String(node.fileid) }, + { dir: node.dirname }, + ) + return null + }, + + order: 80, +}) |