Skip to content

Commit

Permalink
Merge pull request #767 from nextcloud-libraries/feat/title
Browse files Browse the repository at this point in the history
  • Loading branch information
skjnldsv committed Sep 20, 2023
2 parents e428bb6 + 43a4f0f commit e02ec0a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
13 changes: 13 additions & 0 deletions __tests__/fileAction.spec.ts
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
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

0 comments on commit e02ec0a

Please sign in to comment.