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
feat: add action title
Signed-off-by: John Molakvoæ (skjnldsv) <[email protected]>
  • Loading branch information
skjnldsv committed Sep 20, 2023
commit 43a4f0fbca77b5f2c0a0717293bb75975e34aafc
13 changes: 13 additions & 0 deletions __tests__/fileAction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,17 @@ describe('Invalid FileAction creation', () => {
} as any as FileAction)
}).toThrowError('Invalid displayName function')
})
test('Invalid title', () => {
expect(() => {
new FileAction({
id: 'test',
displayName: () => 'Test',
title: 'Test',
iconSvgInline: () => '<svg></svg>',
exec: async () => true,
} as any as FileAction)
}).toThrowError('Invalid title function')
})
test('Invalid iconSvgInline', () => {
expect(() => {
new FileAction({
Expand Down Expand Up @@ -203,6 +214,7 @@ describe('FileActions creation', () => {
const action = new FileAction({
id: 'test',
displayName: () => 'Test',
title: () => 'Test title',
iconSvgInline: () => '<svg></svg>',
exec: async () => true,
execBatch: async () => [true],
Expand All @@ -219,6 +231,7 @@ describe('FileActions creation', () => {

expect(action.id).toBe('test')
expect(action.displayName([], {} as any)).toBe('Test')
expect(action.title?.([], {} as any)).toBe('Test title')
expect(action.iconSvgInline([], {} as any)).toBe('<svg></svg>')
await expect(action.exec({} as any, {} as any, '/')).resolves.toBe(true)
await expect(action.execBatch?.([], {} as any, '/')).resolves.toStrictEqual([true])
Expand Down
10 changes: 10 additions & 0 deletions lib/fileAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ interface FileActionData {
id: string
/** Translatable string displayed in the menu */
displayName: (files: Node[], view: View) => string
/** Translatable title for of the action */
title?: (files: Node[], view: View) => string
/** Svg as inline string. <svg><path fill="..." /></svg> */
iconSvgInline: (files: Node[], view: View) => string
/** Condition wether this action is shown or not */
Expand Down Expand Up @@ -93,6 +95,10 @@ export class FileAction {
return this._action.displayName
}

get title() {
return this._action.title
}

get iconSvgInline() {
return this._action.iconSvgInline
}
Expand Down Expand Up @@ -134,6 +140,10 @@ export class FileAction {
throw new Error('Invalid displayName function')
}

if ('title' in action && typeof action.title !== 'function') {
throw new Error('Invalid title function')
}

if (!action.iconSvgInline || typeof action.iconSvgInline !== 'function') {
throw new Error('Invalid iconSvgInline function')
}
Expand Down