Skip to content
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 17 additions & 18 deletions apps/comments/src/actions/inlineUnreadCommentsAction.spec.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/**
/*!
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

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

import { File, FileAction, Permission } from '@nextcloud/files'
import { File, Permission } from '@nextcloud/files'
import { describe, expect, test, vi } from 'vitest'
import logger from '../logger.js'
import { action } from './inlineUnreadCommentsAction.ts'

const view = {
id: 'files',
name: 'Files',
} as View
} as IView

describe('Inline unread comments action display name tests', () => {
test('Default values', () => {
Expand All @@ -29,36 +29,35 @@ describe('Inline unread comments action display name tests', () => {
root: '/files/admin',
})

expect(action).toBeInstanceOf(FileAction)
expect(action.id).toBe('comments-unread')
expect(action.displayName({
nodes: [file],
view,
folder: {} as Folder,
folder: {} as IFolder,
contents: [],
})).toBe('')
expect(action.title!({
nodes: [file],
view,
folder: {} as Folder,
folder: {} as IFolder,
contents: [],
})).toBe('1 new comment')
expect(action.iconSvgInline({
nodes: [file],
view,
folder: {} as Folder,
folder: {} as IFolder,
contents: [],
})).toMatch(/<svg.+<\/svg>/)
expect(action.enabled!({
nodes: [file],
view,
folder: {} as Folder,
folder: {} as IFolder,
contents: [],
})).toBe(true)
expect(action.inline!({
nodes: [file],
view,
folder: {} as Folder,
folder: {} as IFolder,
contents: [],
})).toBe(true)
expect(action.default).toBeUndefined()
Expand All @@ -81,13 +80,13 @@ describe('Inline unread comments action display name tests', () => {
expect(action.displayName({
nodes: [file],
view,
folder: {} as Folder,
folder: {} as IFolder,
contents: [],
})).toBe('')
expect(action.title!({
nodes: [file],
view,
folder: {} as Folder,
folder: {} as IFolder,
contents: [],
})).toBe('2 new comments')
})
Expand All @@ -108,7 +107,7 @@ describe('Inline unread comments action enabled tests', () => {
expect(action.enabled!({
nodes: [file],
view,
folder: {} as Folder,
folder: {} as IFolder,
contents: [],
})).toBe(false)
})
Expand All @@ -129,7 +128,7 @@ describe('Inline unread comments action enabled tests', () => {
expect(action.enabled!({
nodes: [file],
view,
folder: {} as Folder,
folder: {} as IFolder,
contents: [],
})).toBe(false)
})
Expand All @@ -150,7 +149,7 @@ describe('Inline unread comments action enabled tests', () => {
expect(action.enabled!({
nodes: [file],
view,
folder: {} as Folder,
folder: {} as IFolder,
contents: [],
})).toBe(true)
})
Expand All @@ -171,7 +170,7 @@ describe('Inline unread comments action enabled tests', () => {
expect(action.enabled!({
nodes: [file],
view,
folder: {} as Folder,
folder: {} as IFolder,
contents: [],
})).toBe(true)
})
Expand Down Expand Up @@ -204,7 +203,7 @@ describe('Inline unread comments action execute tests', () => {
const result = await action.exec!({
nodes: [file],
view,
folder: {} as Folder,
folder: {} as IFolder,
contents: [],
})

Expand Down Expand Up @@ -241,7 +240,7 @@ describe('Inline unread comments action execute tests', () => {
const result = await action.exec!({
nodes: [file],
view,
folder: {} as Folder,
folder: {} as IFolder,
contents: [],
})

Expand Down
8 changes: 5 additions & 3 deletions apps/comments/src/actions/inlineUnreadCommentsAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

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

import CommentProcessingSvg from '@mdi/svg/svg/comment-processing.svg?raw'
import { FileAction, getSidebar } from '@nextcloud/files'
import { getSidebar } from '@nextcloud/files'
import { n, t } from '@nextcloud/l10n'
import logger from '../logger.js'

export const action = new FileAction({
export const action: IFileAction = {
id: 'comments-unread',

title({ nodes }) {
Expand Down Expand Up @@ -47,4 +49,4 @@ export const action = new FileAction({
inline: () => true,

order: -140,
})
}
68 changes: 35 additions & 33 deletions apps/files/src/actions/convertAction.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
/**
/*!
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

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

import AutoRenewSvg from '@mdi/svg/svg/autorenew.svg?raw'
import { getCapabilities } from '@nextcloud/capabilities'
import { FileAction, registerFileAction } from '@nextcloud/files'
import { registerFileAction } from '@nextcloud/files'
import { t } from '@nextcloud/l10n'
import { generateUrl } from '@nextcloud/router'
import { convertFile, convertFiles } from './convertUtils.ts'
Expand All @@ -18,47 +21,45 @@ type ConversionsProvider = {
export const ACTION_CONVERT = 'convert'

/**
*
* Registers the convert actions based on the capabilities provided by the server.
*/
export function registerConvertActions() {
// Generate sub actions
const convertProviders = getCapabilities()?.files?.file_conversions as ConversionsProvider[] ?? []
const actions = convertProviders.map(({ to, from, displayName }) => {
return new FileAction({
id: `convert-${from}-${to}`,
displayName: () => t('files', 'Save as {displayName}', { displayName }),
iconSvgInline: () => generateIconSvg(to),
enabled: ({ nodes }) => {
// Check that all nodes have the same mime type
return nodes.every((node) => from === node.mime)
},
const actions = convertProviders.map(({ to, from, displayName }) => ({
id: `convert-${from}-${to}`,
displayName: () => t('files', 'Save as {displayName}', { displayName }),
iconSvgInline: () => generateIconSvg(to),
enabled: ({ nodes }) => {
// Check that all nodes have the same mime type
return nodes.every((node) => from === node.mime)
},

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

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

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

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

// Silently terminate, we'll handle the UI in the background
return Array(nodes.length).fill(null)
},
// Silently terminate, we'll handle the UI in the background
return Array(nodes.length).fill(null)
},

parent: ACTION_CONVERT,
})
})
parent: ACTION_CONVERT,
} satisfies IFileAction))

// Register main action
registerFileAction(new FileAction({
registerFileAction({
id: ACTION_CONVERT,
displayName: () => t('files', 'Save as …'),
iconSvgInline: () => AutoRenewSvg,
Expand All @@ -69,15 +70,16 @@ export function registerConvertActions() {
return null
},
order: 25,
}))
} satisfies IFileAction)

// Register sub actions
actions.forEach(registerFileAction)
}

/**
* Generates an SVG icon for a given mime type by using the server's mime icon endpoint.
*
* @param mime
* @param mime - The mime type to generate the icon for
*/
export function generateIconSvg(mime: string) {
// Generate icon based on mime type
Expand Down
12 changes: 6 additions & 6 deletions apps/files/src/actions/deleteAction.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/**
/*!
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import type { View } from '@nextcloud/files'

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

import axios from '@nextcloud/axios'
import * as capabilities from '@nextcloud/capabilities'
import * as eventBus from '@nextcloud/event-bus'
import { File, FileAction, Folder, Permission } from '@nextcloud/files'
import { File, Folder, Permission } from '@nextcloud/files'
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'
import logger from '../logger.ts'
import { action } from './deleteAction.ts'
Expand All @@ -20,12 +21,12 @@ vi.mock('@nextcloud/capabilities')
const view = {
id: 'files',
name: 'Files',
} as View
} as IView

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

describe('Delete action conditions tests', () => {
beforeEach(() => {
Expand Down Expand Up @@ -90,7 +91,6 @@ describe('Delete action conditions tests', () => {
})

test('Default values', () => {
expect(action).toBeInstanceOf(FileAction)
expect(action.id).toBe('delete')
expect(action.displayName({
nodes: [file],
Expand Down
11 changes: 7 additions & 4 deletions apps/files/src/actions/deleteAction.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
/**
/*!
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

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

import CloseSvg from '@mdi/svg/svg/close.svg?raw'
import NetworkOffSvg from '@mdi/svg/svg/network-off.svg?raw'
import TrashCanSvg from '@mdi/svg/svg/trash-can-outline.svg?raw'
import { FileAction, Permission } from '@nextcloud/files'
import { Permission } from '@nextcloud/files'
import { loadState } from '@nextcloud/initial-state'
import { t } from '@nextcloud/l10n'
import PQueue from 'p-queue'
Expand All @@ -20,7 +23,7 @@ const queue = new PQueue({ concurrency: 5 })

export const ACTION_DELETE = 'delete'

export const action = new FileAction({
export const action: IFileAction = {
id: ACTION_DELETE,
displayName,
iconSvgInline: ({ nodes }) => {
Expand Down Expand Up @@ -117,4 +120,4 @@ export const action = new FileAction({
description: t('files', 'Delete'),
key: 'Delete',
},
})
}
9 changes: 4 additions & 5 deletions apps/files/src/actions/downloadAction.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/**
/*!
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import type { View } from '@nextcloud/files'
import type { IView } from '@nextcloud/files'

import axios from '@nextcloud/axios'
import * as dialogs from '@nextcloud/dialogs'
import * as eventBus from '@nextcloud/event-bus'
import { DefaultType, File, FileAction, Folder, Permission } from '@nextcloud/files'
import { DefaultType, File, Folder, Permission } from '@nextcloud/files'
import { beforeAll, beforeEach, describe, expect, test, vi } from 'vitest'
import { action } from './downloadAction.ts'

Expand All @@ -19,7 +19,7 @@ vi.mock('@nextcloud/event-bus')
const view = {
id: 'files',
name: 'Files',
} as View
} as IView

// Mock webroot variable
beforeAll(() => {
Expand All @@ -28,7 +28,6 @@ beforeAll(() => {

describe('Download action conditions tests', () => {
test('Default values', () => {
expect(action).toBeInstanceOf(FileAction)
expect(action.id).toBe('download')
expect(action.displayName({
nodes: [],
Expand Down
Loading
Loading