refactor(systemtags): adjust for files library interfaces

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
This commit is contained in:
Ferdinand Thiessen 2026-02-05 15:12:53 +01:00
parent 009aad6eb7
commit 752ff74170
No known key found for this signature in database
GPG key ID: 7E849AE05218500F
6 changed files with 44 additions and 46 deletions

View file

@ -1,33 +1,32 @@
/**
/*!
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import type { View } from '@nextcloud/files'
import type { IFolder, IView } from '@nextcloud/files'
import { File, FileAction, Folder, Permission } from '@nextcloud/files'
import { File, Folder, Permission } from '@nextcloud/files'
import { describe, expect, test } from 'vitest'
import { action } from './bulkSystemTagsAction.ts'
const view = {
id: 'files',
name: 'Files',
} as View
} as IView
describe('Manage tags action conditions tests', () => {
test('Default values', () => {
expect(action).toBeInstanceOf(FileAction)
expect(action.id).toBe('systemtags:bulk')
expect(action.displayName({
nodes: [],
view,
folder: {} as Folder,
folder: {} as IFolder,
contents: [],
})).toBe('Manage tags')
expect(action.iconSvgInline({
nodes: [],
view,
folder: {} as Folder,
folder: {} as IFolder,
contents: [],
})).toMatch(/<svg.+<\/svg>/)
expect(action.default).toBeUndefined()
@ -60,19 +59,19 @@ describe('Manage tags action enabled tests', () => {
expect(action.enabled!({
nodes: [file1, file2],
view,
folder: {} as Folder,
folder: {} as IFolder,
contents: [],
})).toBe(false)
expect(action.enabled!({
nodes: [file1],
view,
folder: {} as Folder,
folder: {} as IFolder,
contents: [],
})).toBe(false)
expect(action.enabled!({
nodes: [file2],
view,
folder: {} as Folder,
folder: {} as IFolder,
contents: [],
})).toBe(true)
})
@ -91,7 +90,7 @@ describe('Manage tags action enabled tests', () => {
expect(action.enabled!({
nodes: [file],
view,
folder: {} as Folder,
folder: {} as IFolder,
contents: [],
})).toBe(false)
})

View file

@ -3,10 +3,10 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import type { ActionContext, ActionContextSingle } from '@nextcloud/files'
import type { ActionContext, ActionContextSingle, IFileAction } from '@nextcloud/files'
import TagMultipleSvg from '@mdi/svg/svg/tag-multiple-outline.svg?raw'
import { FileAction, Permission } from '@nextcloud/files'
import { Permission } from '@nextcloud/files'
import { t } from '@nextcloud/l10n'
import { isPublicShare } from '@nextcloud/sharing/public'
import { spawnDialog } from '@nextcloud/vue/functions/dialog'
@ -29,7 +29,7 @@ async function execBatch({ nodes }: ActionContext | ActionContextSingle): Promis
.fill(response)
}
export const action = new FileAction({
export const action: IFileAction = {
id: 'systemtags:bulk',
displayName: () => t('systemtags', 'Manage tags'),
iconSvgInline: () => TagMultipleSvg,
@ -64,4 +64,4 @@ export const action = new FileAction({
description: t('systemtags', 'Manage tags'),
key: 't',
},
})
}

View file

@ -3,10 +3,10 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import type { Folder, View } from '@nextcloud/files'
import type { IFolder, IView } from '@nextcloud/files'
import { emit, subscribe } from '@nextcloud/event-bus'
import { File, FileAction, Permission } from '@nextcloud/files'
import { File, Permission } from '@nextcloud/files'
import { beforeEach, describe, expect, test, vi } from 'vitest'
import * as serviceTagApi from '../services/api.ts'
import { setNodeSystemTags } from '../utils.ts'
@ -15,7 +15,7 @@ import { action } from './inlineSystemTagsAction.ts'
const view = {
id: 'files',
name: 'Files',
} as View
} as IView
describe('Inline system tags action conditions tests', () => {
test('Default values', () => {
@ -28,18 +28,17 @@ describe('Inline system tags action conditions tests', () => {
root: '/files/admin',
})
expect(action).toBeInstanceOf(FileAction)
expect(action.id).toBe('system-tags')
expect(action.displayName({
nodes: [file],
view,
folder: {} as Folder,
folder: {} as IFolder,
contents: [],
})).toBe('')
expect(action.iconSvgInline({
nodes: [file],
view,
folder: {} as Folder,
folder: {} as IFolder,
contents: [],
})).toBe('')
expect(action.default).toBeUndefined()
@ -49,7 +48,7 @@ describe('Inline system tags action conditions tests', () => {
expect(action.enabled!({
nodes: [file],
view,
folder: {} as Folder,
folder: {} as IFolder,
contents: [],
})).toBe(true)
})
@ -72,7 +71,7 @@ describe('Inline system tags action conditions tests', () => {
expect(action.enabled!({
nodes: [file],
view,
folder: {} as Folder,
folder: {} as IFolder,
contents: [],
})).toBe(true)
})
@ -98,7 +97,7 @@ describe('Inline system tags action render tests', () => {
const result = await action.renderInline!({
nodes: [file],
view,
folder: {} as Folder,
folder: {} as IFolder,
contents: [],
})
expect(result).toBeInstanceOf(HTMLElement)
@ -123,7 +122,7 @@ describe('Inline system tags action render tests', () => {
const result = await action.renderInline!({
nodes: [file],
view,
folder: {} as Folder,
folder: {} as IFolder,
contents: [],
})
expect(result).toBeInstanceOf(HTMLElement)
@ -148,7 +147,7 @@ describe('Inline system tags action render tests', () => {
const result = await action.renderInline!({
nodes: [file],
view,
folder: {} as Folder,
folder: {} as IFolder,
contents: [],
})
expect(result).toBeInstanceOf(HTMLElement)
@ -178,7 +177,7 @@ describe('Inline system tags action render tests', () => {
const result = await action.renderInline!({
nodes: [file],
view,
folder: {} as Folder,
folder: {} as IFolder,
contents: [],
})
expect(result).toBeInstanceOf(HTMLElement)
@ -208,7 +207,7 @@ describe('Inline system tags action render tests', () => {
const result = await action.renderInline!({
nodes: [file],
view,
folder: {} as Folder,
folder: {} as IFolder,
contents: [],
}) as HTMLElement
document.body.appendChild(result)
@ -270,7 +269,7 @@ describe('Inline system tags action colors', () => {
const result = await action.renderInline!({
nodes: [file],
view,
folder: {} as Folder,
folder: {} as IFolder,
contents: [],
})
expect(result).toBeInstanceOf(HTMLElement)
@ -297,7 +296,7 @@ describe('Inline system tags action colors', () => {
const result = await action.renderInline!({
nodes: [file],
view,
folder: {} as Folder,
folder: {} as IFolder,
contents: [],
})
expect(result).toBeInstanceOf(HTMLElement)
@ -324,7 +323,7 @@ describe('Inline system tags action colors', () => {
const result = await action.renderInline!({
nodes: [file],
view,
folder: {} as Folder,
folder: {} as IFolder,
contents: [],
}) as HTMLElement
document.body.appendChild(result)

View file

@ -3,11 +3,10 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import type { INode } from '@nextcloud/files'
import type { IFileAction, INode } from '@nextcloud/files'
import type { TagWithId } from '../types.ts'
import { subscribe } from '@nextcloud/event-bus'
import { FileAction } from '@nextcloud/files'
import { t } from '@nextcloud/l10n'
import logger from '../logger.ts'
import { fetchTags } from '../services/api.ts'
@ -19,7 +18,7 @@ import '../css/fileEntryInlineSystemTags.scss'
// Init tag cache
const cache: TagWithId[] = []
export const action = new FileAction({
export const action: IFileAction = {
id: 'system-tags',
displayName: () => '',
iconSvgInline: () => '',
@ -44,7 +43,7 @@ export const action = new FileAction({
},
order: 0,
})
}
// Subscribe to the events
subscribe('systemtags:node:updated', updateSystemTagsHtml)
@ -167,11 +166,11 @@ async function renderInline(node: INode): Promise<HTMLElement> {
}
}
systemTagsElement.append(renderTag(tags[0]))
systemTagsElement.append(renderTag(tags[0]!))
if (tags.length === 2) {
// Special case only two tags:
// the overflow fake tag would take the same space as this, so render it
systemTagsElement.append(renderTag(tags[1]))
systemTagsElement.append(renderTag(tags[1]!))
} else if (tags.length > 1) {
// More tags than the one we're showing
// So we add a overflow element indicating there are more tags

View file

@ -3,21 +3,21 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import type { View } from '@nextcloud/files'
import type { IView } from '@nextcloud/files'
import { DefaultType, File, FileAction, Folder, Permission } from '@nextcloud/files'
import { DefaultType, File, Folder, Permission } from '@nextcloud/files'
import { describe, expect, test, vi } from 'vitest'
import { action } from './openInFilesAction.ts'
const view = {
id: 'files',
name: 'Files',
} as View
} as IView
const systemTagsView = {
id: 'tags',
name: 'tags',
} as View
} as IView
const validNode = new Folder({
id: 1,
@ -43,7 +43,6 @@ const validTag = new Folder({
describe('Open in files action conditions tests', () => {
test('Default values', () => {
expect(action).toBeInstanceOf(FileAction)
expect(action.id).toBe('systemtags:open-in-files')
expect(action.displayName({
nodes: [],

View file

@ -1,13 +1,15 @@
/**
/*!
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { DefaultType, FileAction, FileType } from '@nextcloud/files'
import type { IFileAction } from '@nextcloud/files'
import { DefaultType, FileType } from '@nextcloud/files'
import { t } from '@nextcloud/l10n'
import { systemTagsViewId } from '../files_views/systemtagsView.ts'
export const action = new FileAction({
export const action: IFileAction = {
id: 'systemtags:open-in-files',
displayName: () => t('systemtags', 'Open in Files'),
iconSvgInline: () => '',
@ -47,4 +49,4 @@ export const action = new FileAction({
// Before openFolderAction
order: -1000,
default: DefaultType.HIDDEN,
})
}