Skip to content

Commit 52e3762

Browse files
authored
Merge pull request #56743 from nextcloud/chore/files-4-0-0
2 parents 282341a + 2c4b5c6 commit 52e3762

File tree

436 files changed

+3484
-1873
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

436 files changed

+3484
-1873
lines changed

apps/comments/src/actions/inlineUnreadCommentsAction.spec.ts

Lines changed: 88 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
55

6-
import type { View } from '@nextcloud/files'
6+
import type { Folder, View } from '@nextcloud/files'
77

88
import { File, FileAction, Permission } from '@nextcloud/files'
99
import { describe, expect, test, vi } from 'vitest'
@@ -26,15 +26,41 @@ describe('Inline unread comments action display name tests', () => {
2626
attributes: {
2727
'comments-unread': 1,
2828
},
29+
root: '/files/admin',
2930
})
3031

3132
expect(action).toBeInstanceOf(FileAction)
3233
expect(action.id).toBe('comments-unread')
33-
expect(action.displayName([file], view)).toBe('')
34-
expect(action.title!([file], view)).toBe('1 new comment')
35-
expect(action.iconSvgInline([], view)).toMatch(/<svg.+<\/svg>/)
36-
expect(action.enabled!([file], view)).toBe(true)
37-
expect(action.inline!(file, view)).toBe(true)
34+
expect(action.displayName({
35+
nodes: [file],
36+
view,
37+
folder: {} as Folder,
38+
contents: [],
39+
})).toBe('')
40+
expect(action.title!({
41+
nodes: [file],
42+
view,
43+
folder: {} as Folder,
44+
contents: [],
45+
})).toBe('1 new comment')
46+
expect(action.iconSvgInline({
47+
nodes: [file],
48+
view,
49+
folder: {} as Folder,
50+
contents: [],
51+
})).toMatch(/<svg.+<\/svg>/)
52+
expect(action.enabled!({
53+
nodes: [file],
54+
view,
55+
folder: {} as Folder,
56+
contents: [],
57+
})).toBe(true)
58+
expect(action.inline!({
59+
nodes: [file],
60+
view,
61+
folder: {} as Folder,
62+
contents: [],
63+
})).toBe(true)
3864
expect(action.default).toBeUndefined()
3965
expect(action.order).toBe(-140)
4066
})
@@ -49,10 +75,21 @@ describe('Inline unread comments action display name tests', () => {
4975
attributes: {
5076
'comments-unread': 2,
5177
},
78+
root: '/files/admin',
5279
})
5380

54-
expect(action.displayName([file], view)).toBe('')
55-
expect(action.title!([file], view)).toBe('2 new comments')
81+
expect(action.displayName({
82+
nodes: [file],
83+
view,
84+
folder: {} as Folder,
85+
contents: [],
86+
})).toBe('')
87+
expect(action.title!({
88+
nodes: [file],
89+
view,
90+
folder: {} as Folder,
91+
contents: [],
92+
})).toBe('2 new comments')
5693
})
5794
})
5895

@@ -64,10 +101,16 @@ describe('Inline unread comments action enabled tests', () => {
64101
owner: 'admin',
65102
mime: 'text/plain',
66103
permissions: Permission.ALL,
67-
attributes: { },
104+
attributes: {},
105+
root: '/files/admin',
68106
})
69107

70-
expect(action.enabled!([file], view)).toBe(false)
108+
expect(action.enabled!({
109+
nodes: [file],
110+
view,
111+
folder: {} as Folder,
112+
contents: [],
113+
})).toBe(false)
71114
})
72115

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

85-
expect(action.enabled!([file], view)).toBe(false)
129+
expect(action.enabled!({
130+
nodes: [file],
131+
view,
132+
folder: {} as Folder,
133+
contents: [],
134+
})).toBe(false)
86135
})
87136

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

100-
expect(action.enabled!([file], view)).toBe(true)
150+
expect(action.enabled!({
151+
nodes: [file],
152+
view,
153+
folder: {} as Folder,
154+
contents: [],
155+
})).toBe(true)
101156
})
102157

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

115-
expect(action.enabled!([file], view)).toBe(true)
171+
expect(action.enabled!({
172+
nodes: [file],
173+
view,
174+
folder: {} as Folder,
175+
contents: [],
176+
})).toBe(true)
116177
})
117178
})
118179

@@ -139,9 +200,15 @@ describe('Inline unread comments action execute tests', () => {
139200
attributes: {
140201
'comments-unread': 1,
141202
},
203+
root: '/files/admin',
142204
})
143205

144-
const result = await action.exec!(file, view, '/')
206+
const result = await action.exec!({
207+
nodes: [file],
208+
view,
209+
folder: {} as Folder,
210+
contents: [],
211+
})
145212

146213
expect(result).toBe(null)
147214
expect(setActiveTabMock).toBeCalledWith('comments')
@@ -173,9 +240,15 @@ describe('Inline unread comments action execute tests', () => {
173240
attributes: {
174241
'comments-unread': 1,
175242
},
243+
root: '/files/admin',
176244
})
177245

178-
const result = await action.exec!(file, view, '/')
246+
const result = await action.exec!({
247+
nodes: [file],
248+
view,
249+
folder: {} as Folder,
250+
contents: [],
251+
})
179252

180253
expect(result).toBe(false)
181254
expect(setActiveTabMock).toBeCalledWith('comments')

apps/comments/src/actions/inlineUnreadCommentsAction.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
5-
6-
import type { Node } from '@nextcloud/files'
7-
85
import CommentProcessingSvg from '@mdi/svg/svg/comment-processing.svg?raw'
96
import { FileAction } from '@nextcloud/files'
107
import { n, t } from '@nextcloud/l10n'
@@ -13,9 +10,9 @@ import logger from '../logger.js'
1310
export const action = new FileAction({
1411
id: 'comments-unread',
1512

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

2724
iconSvgInline: () => CommentProcessingSvg,
2825

29-
enabled(nodes: Node[]) {
30-
const unread = nodes[0].attributes['comments-unread'] as number | undefined
26+
enabled({ nodes }) {
27+
const unread = nodes[0]?.attributes?.['comments-unread'] as number | undefined
3128
return typeof unread === 'number' && unread > 0
3229
},
3330

34-
async exec(node: Node) {
31+
async exec({ nodes }) {
32+
if (nodes.length !== 1 || !nodes[0]) {
33+
return false
34+
}
35+
3536
try {
3637
window.OCA.Files.Sidebar.setActiveTab('comments')
37-
await window.OCA.Files.Sidebar.open(node.path)
38+
await window.OCA.Files.Sidebar.open(nodes[0].path)
3839
return null
3940
} catch (error) {
4041
logger.error('Error while opening sidebar', { error })

apps/files/src/actions/convertAction.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
5-
6-
import type { Node, View } from '@nextcloud/files'
7-
85
import AutoRenewSvg from '@mdi/svg/svg/autorenew.svg?raw'
96
import { getCapabilities } from '@nextcloud/capabilities'
107
import { FileAction, registerFileAction } from '@nextcloud/files'
@@ -31,20 +28,24 @@ export function registerConvertActions() {
3128
id: `convert-${from}-${to}`,
3229
displayName: () => t('files', 'Save as {displayName}', { displayName }),
3330
iconSvgInline: () => generateIconSvg(to),
34-
enabled: (nodes: Node[]) => {
31+
enabled: ({ nodes }) => {
3532
// Check that all nodes have the same mime type
3633
return nodes.every((node) => from === node.mime)
3734
},
3835

39-
async exec(node: Node) {
36+
async exec({ nodes }) {
37+
if (!nodes[0]) {
38+
return false
39+
}
40+
4041
// If we're here, we know that the node has a fileid
41-
convertFile(node.fileid as number, to)
42+
convertFile(nodes[0].fileid as number, to)
4243

4344
// Silently terminate, we'll handle the UI in the background
4445
return null
4546
},
4647

47-
async execBatch(nodes: Node[]) {
48+
async execBatch({ nodes }) {
4849
const fileIds = nodes.map((node) => node.fileid).filter(Boolean) as number[]
4950
convertFiles(fileIds, to)
5051

@@ -61,8 +62,8 @@ export function registerConvertActions() {
6162
id: ACTION_CONVERT,
6263
displayName: () => t('files', 'Save as …'),
6364
iconSvgInline: () => AutoRenewSvg,
64-
enabled: (nodes: Node[], view: View) => {
65-
return actions.some((action) => action.enabled!(nodes, view))
65+
enabled: (context) => {
66+
return actions.some((action) => action.enabled!(context))
6667
},
6768
async exec() {
6869
return null

0 commit comments

Comments
 (0)