Skip to content

Commit 55ae6a1

Browse files
committed
fix(actions): reduce context of displayName, title, iconSvgInline, inline and renderInline
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
1 parent 621e4a8 commit 55ae6a1

3 files changed

Lines changed: 18 additions & 18 deletions

File tree

__tests__/actions/fileAction.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -249,17 +249,17 @@ describe('FileActions creation', () => {
249249
const node = {} as Node
250250

251251
expect(action.id).toBe('test')
252-
expect(action.displayName({ view, folder, nodes: [], content: [] })).toBe('Test')
253-
expect(action.title?.({ view, folder, nodes: [], content: [] })).toBe('Test title')
254-
expect(action.iconSvgInline({ view, folder, nodes: [], content: [] })).toBe('<svg></svg>')
252+
expect(action.displayName({ view, nodes: [] })).toBe('Test')
253+
expect(action.title?.({ view, nodes: [] })).toBe('Test title')
254+
expect(action.iconSvgInline({ view, nodes: [] })).toBe('<svg></svg>')
255255
await expect(action.exec({ view, folder, nodes: [node], content: [] })).resolves.toBe(true)
256256
await expect(action.execBatch?.({ view, folder, nodes: [], content: [] })).resolves.toStrictEqual([true])
257257
expect(action.enabled?.({ view, folder, nodes: [], content: [] })).toBe(true)
258258
expect(action.order).toBe(100)
259259
expect(action.parent).toBe('123')
260260
expect(action.destructive).toBe(true)
261261
expect(action.default).toBe(DefaultType.DEFAULT)
262-
expect(action.inline?.({ view, folder, nodes: [], content: [] })).toBe(true)
263-
expect((await action.renderInline?.({ view, folder, nodes: [], content: [] }))?.outerHTML).toBe('<span>test</span>')
262+
expect(action.inline?.({ view, nodes: [] })).toBe(true)
263+
expect((await action.renderInline?.({ view, nodes: [] }))?.outerHTML).toBe('<span>test</span>')
264264
})
265265
})

lib/actions/fileAction.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
5-
import type { ActionContext, ActionContextSingle } from '../types.ts'
5+
import type { ActionContext, ActionContextBase, ActionContextSingle } from '../types.ts'
66

77
import logger from '../utils/logger.ts'
88

@@ -46,11 +46,11 @@ export interface FileActionData {
4646
/** Unique ID */
4747
id: string
4848
/** Translatable string displayed in the menu */
49-
displayName: (context: ActionContext) => string
49+
displayName: (context: ActionContextBase) => string
5050
/** Translatable title for of the action */
51-
title?: (context: ActionContext) => string
51+
title?: (context: ActionContextBase) => string
5252
/** Svg as inline string. <svg><path fill="..." /></svg> */
53-
iconSvgInline: (context: ActionContext) => string
53+
iconSvgInline: (context: ActionContextBase) => string
5454
/** Condition wether this action is shown or not */
5555
enabled?: (context: ActionContext) => boolean
5656

@@ -102,12 +102,12 @@ export interface FileActionData {
102102
/**
103103
* If true, the renderInline function will be called
104104
*/
105-
inline?: (context: ActionContext) => boolean,
105+
inline?: (context: ActionContextBase) => boolean,
106106
/**
107107
* If defined, the returned html element will be
108108
* appended before the actions menu.
109109
*/
110-
renderInline?: (context: ActionContext) => Promise<HTMLElement | null>,
110+
renderInline?: (context: ActionContextBase) => Promise<HTMLElement | null>,
111111
}
112112

113113
export class FileAction {

lib/types.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@
66
import { Folder, Node } from './node/index.ts'
77
import { View } from './navigation/index.ts'
88

9-
export type ActionContextSingle = {
10-
nodes: [Node],
9+
export type ActionContextBase = {
10+
nodes: Node[],
1111
view: View,
12-
folder: Folder,
13-
content: Node[],
1412
}
1513

1614
export type ActionContext = {
17-
nodes: Node[],
18-
view: View,
1915
folder: Folder,
2016
content: Node[],
21-
}
17+
} & ActionContextBase
18+
19+
export type ActionContextSingle = {
20+
nodes: [Node],
21+
} & ActionContext
2222

2323
export type ViewActionContext = {
2424
view: View,

0 commit comments

Comments
 (0)