Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
103 changes: 88 additions & 15 deletions apps/comments/src/actions/inlineUnreadCommentsAction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import type { View } from '@nextcloud/files'
import type { Folder, View } from '@nextcloud/files'

import { File, FileAction, Permission } from '@nextcloud/files'
import { describe, expect, test, vi } from 'vitest'
Expand All @@ -26,15 +26,41 @@ describe('Inline unread comments action display name tests', () => {
attributes: {
'comments-unread': 1,
},
root: '/files/admin',
})

expect(action).toBeInstanceOf(FileAction)
expect(action.id).toBe('comments-unread')
expect(action.displayName([file], view)).toBe('')
expect(action.title!([file], view)).toBe('1 new comment')
expect(action.iconSvgInline([], view)).toMatch(/<svg.+<\/svg>/)
expect(action.enabled!([file], view)).toBe(true)
expect(action.inline!(file, view)).toBe(true)
expect(action.displayName({
nodes: [file],
view,
folder: {} as Folder,
contents: [],
})).toBe('')
expect(action.title!({
nodes: [file],
view,
folder: {} as Folder,
contents: [],
})).toBe('1 new comment')
expect(action.iconSvgInline({
nodes: [file],
view,
folder: {} as Folder,
contents: [],
})).toMatch(/<svg.+<\/svg>/)
expect(action.enabled!({
nodes: [file],
view,
folder: {} as Folder,
contents: [],
})).toBe(true)
expect(action.inline!({
nodes: [file],
view,
folder: {} as Folder,
contents: [],
})).toBe(true)
expect(action.default).toBeUndefined()
expect(action.order).toBe(-140)
})
Expand All @@ -49,10 +75,21 @@ describe('Inline unread comments action display name tests', () => {
attributes: {
'comments-unread': 2,
},
root: '/files/admin',
})

expect(action.displayName([file], view)).toBe('')
expect(action.title!([file], view)).toBe('2 new comments')
expect(action.displayName({
nodes: [file],
view,
folder: {} as Folder,
contents: [],
})).toBe('')
expect(action.title!({
nodes: [file],
view,
folder: {} as Folder,
contents: [],
})).toBe('2 new comments')
})
})

Expand All @@ -64,10 +101,16 @@ describe('Inline unread comments action enabled tests', () => {
owner: 'admin',
mime: 'text/plain',
permissions: Permission.ALL,
attributes: { },
attributes: {},
root: '/files/admin',
})

expect(action.enabled!([file], view)).toBe(false)
expect(action.enabled!({
nodes: [file],
view,
folder: {} as Folder,
contents: [],
})).toBe(false)
})

test('Action is disabled when file does not have unread comments', () => {
Expand All @@ -80,9 +123,15 @@ describe('Inline unread comments action enabled tests', () => {
attributes: {
'comments-unread': 0,
},
root: '/files/admin',
})

expect(action.enabled!([file], view)).toBe(false)
expect(action.enabled!({
nodes: [file],
view,
folder: {} as Folder,
contents: [],
})).toBe(false)
})

test('Action is enabled when file has a single unread comment', () => {
Expand All @@ -95,9 +144,15 @@ describe('Inline unread comments action enabled tests', () => {
attributes: {
'comments-unread': 1,
},
root: '/files/admin',
})

expect(action.enabled!([file], view)).toBe(true)
expect(action.enabled!({
nodes: [file],
view,
folder: {} as Folder,
contents: [],
})).toBe(true)
})

test('Action is enabled when file has a two unread comments', () => {
Expand All @@ -110,9 +165,15 @@ describe('Inline unread comments action enabled tests', () => {
attributes: {
'comments-unread': 2,
},
root: '/files/admin',
})

expect(action.enabled!([file], view)).toBe(true)
expect(action.enabled!({
nodes: [file],
view,
folder: {} as Folder,
contents: [],
})).toBe(true)
})
})

Expand All @@ -139,9 +200,15 @@ describe('Inline unread comments action execute tests', () => {
attributes: {
'comments-unread': 1,
},
root: '/files/admin',
})

const result = await action.exec!(file, view, '/')
const result = await action.exec!({
nodes: [file],
view,
folder: {} as Folder,
contents: [],
})

expect(result).toBe(null)
expect(setActiveTabMock).toBeCalledWith('comments')
Expand Down Expand Up @@ -173,9 +240,15 @@ describe('Inline unread comments action execute tests', () => {
attributes: {
'comments-unread': 1,
},
root: '/files/admin',
})

const result = await action.exec!(file, view, '/')
const result = await action.exec!({
nodes: [file],
view,
folder: {} as Folder,
contents: [],
})

expect(result).toBe(false)
expect(setActiveTabMock).toBeCalledWith('comments')
Expand Down
21 changes: 11 additions & 10 deletions apps/comments/src/actions/inlineUnreadCommentsAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import type { Node } from '@nextcloud/files'

import CommentProcessingSvg from '@mdi/svg/svg/comment-processing.svg?raw'
import { FileAction } from '@nextcloud/files'
import { n, t } from '@nextcloud/l10n'
Expand All @@ -13,9 +10,9 @@ import logger from '../logger.js'
export const action = new FileAction({
id: 'comments-unread',

title(nodes: Node[]) {
const unread = nodes[0].attributes['comments-unread'] as number
if (unread >= 0) {
title({ nodes }) {
const unread = nodes[0]?.attributes['comments-unread'] as number | undefined
if (typeof unread === 'number' && unread >= 0) {
return n('comments', '1 new comment', '{unread} new comments', unread, { unread })
}
return t('comments', 'Comment')
Expand All @@ -26,15 +23,19 @@ export const action = new FileAction({

iconSvgInline: () => CommentProcessingSvg,

enabled(nodes: Node[]) {
const unread = nodes[0].attributes['comments-unread'] as number | undefined
enabled({ nodes }) {
const unread = nodes[0]?.attributes?.['comments-unread'] as number | undefined
return typeof unread === 'number' && unread > 0
},

async exec(node: Node) {
async exec({ nodes }) {
if (nodes.length !== 1 || !nodes[0]) {
return false
}

try {
window.OCA.Files.Sidebar.setActiveTab('comments')
await window.OCA.Files.Sidebar.open(node.path)
await window.OCA.Files.Sidebar.open(nodes[0].path)
return null
} catch (error) {
logger.error('Error while opening sidebar', { error })
Expand Down
19 changes: 10 additions & 9 deletions apps/files/src/actions/convertAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import type { Node, View } from '@nextcloud/files'

import AutoRenewSvg from '@mdi/svg/svg/autorenew.svg?raw'
import { getCapabilities } from '@nextcloud/capabilities'
import { FileAction, registerFileAction } from '@nextcloud/files'
Expand All @@ -31,20 +28,24 @@ export function registerConvertActions() {
id: `convert-${from}-${to}`,
displayName: () => t('files', 'Save as {displayName}', { displayName }),
iconSvgInline: () => generateIconSvg(to),
enabled: (nodes: Node[]) => {
enabled: ({ nodes }) => {
// Check that all nodes have the same mime type
return nodes.every((node) => from === node.mime)
},

async exec(node: Node) {
async exec({ nodes }) {
if (!nodes[0]) {
return false
}

// If we're here, we know that the node has a fileid
convertFile(node.fileid as number, to)
convertFile(nodes[0].fileid as number, to)

// Silently terminate, we'll handle the UI in the background
return null
},

async execBatch(nodes: Node[]) {
async execBatch({ nodes }) {
const fileIds = nodes.map((node) => node.fileid).filter(Boolean) as number[]
convertFiles(fileIds, to)

Expand All @@ -61,8 +62,8 @@ export function registerConvertActions() {
id: ACTION_CONVERT,
displayName: () => t('files', 'Save as …'),
iconSvgInline: () => AutoRenewSvg,
enabled: (nodes: Node[], view: View) => {
return actions.some((action) => action.enabled!(nodes, view))
enabled: (context) => {
return actions.some((action) => action.enabled!(context))
},
async exec() {
return null
Expand Down
Loading
Loading