Skip to content

Commit

Permalink
Merge pull request #42967 from nextcloud/fix/files/42956
Browse files Browse the repository at this point in the history
  • Loading branch information
skjnldsv committed Jan 22, 2024
2 parents 4c1452f + 3f33f78 commit 1a5d5a2
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
21 changes: 20 additions & 1 deletion apps/files/src/actions/viewInFolderAction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ import { expect } from '@jest/globals'
import { File, Folder, Node, Permission, View, FileAction } from '@nextcloud/files'

const view = {
id: 'trashbin',
name: 'Trashbin',
} as View

const viewFiles = {
id: 'files',
name: 'Files',
} as View
Expand All @@ -36,11 +41,12 @@ describe('View in folder action conditions tests', () => {
expect(action.iconSvgInline([], view)).toBe('<svg>SvgMock</svg>')
expect(action.default).toBeUndefined()
expect(action.order).toBe(80)
expect(action.enabled).toBeDefined()
})
})

describe('View in folder action enabled tests', () => {
test('Enabled for files', () => {
test('Enabled for trashbin', () => {
const file = new File({
id: 1,
source: 'https://cloud.domain.com/remote.php/dav/files/admin/foobar.txt',
Expand All @@ -53,6 +59,19 @@ describe('View in folder action enabled tests', () => {
expect(action.enabled!([file], view)).toBe(true)
})

test('Disabled for files', () => {
const file = new File({
id: 1,
source: 'https://cloud.domain.com/remote.php/dav/files/admin/foobar.txt',
owner: 'admin',
mime: 'text/plain',
permissions: Permission.ALL,
})

expect(action.enabled).toBeDefined()
expect(action.enabled!([file], viewFiles)).toBe(false)
})

test('Disabled without permissions', () => {
const file = new File({
id: 1,
Expand Down
9 changes: 7 additions & 2 deletions apps/files/src/actions/viewInFolderAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ export const action = new FileAction({
},
iconSvgInline: () => FolderMoveSvg,

enabled(nodes: Node[]) {
enabled(nodes: Node[], view: View) {
// 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
Expand All @@ -49,7 +54,7 @@ export const action = new FileAction({
return node.type === FileType.File
},

async exec(node: Node, view: View, dir: string) {
async exec(node: Node) {
if (!node || node.type !== FileType.File) {
return false
}
Expand Down
4 changes: 2 additions & 2 deletions dist/files-init.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/files-init.js.map

Large diffs are not rendered by default.

0 comments on commit 1a5d5a2

Please sign in to comment.