Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(fileActions): improve typing and add silent actions #625

Merged
merged 1 commit into from Apr 19, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions __tests__/fileAction.spec.ts
Expand Up @@ -201,8 +201,8 @@ describe('FileActions creation', () => {
expect(action.id).toBe('test')
expect(action.displayName([], {})).toBe('Test')
expect(action.iconSvgInline([], {})).toBe('<svg></svg>')
await expect(action.exec({} as any, {})).resolves.toBe(true)
await expect(action.execBatch?.([], {})).resolves.toStrictEqual([true])
await expect(action.exec({} as any, {}, '/')).resolves.toBe(true)
await expect(action.execBatch?.([], {}, '/')).resolves.toStrictEqual([true])
expect(action.enabled?.({} as any, {})).toBe(true)
expect(action.order).toBe(100)
expect(action.default).toBe(true)
Expand Down
10 changes: 6 additions & 4 deletions lib/fileAction.ts
Expand Up @@ -34,16 +34,18 @@ interface FileActionData {
enabled?: (files: Node[], view) => boolean
/**
* Function executed on single file action
* @returns true if the action was executed, false otherwise
* @returns true if the action was executed successfully,
* false otherwise and null if the action is silent/undefined.
* @throws Error if the action failed
*/
exec: (file: Node, view) => Promise<boolean>,
exec: (file: Node, view, dir: string) => Promise<boolean|null>,
/**
* Function executed on multiple files action
* @returns true if the action was executed, false otherwise
* @returns true if the action was executed successfully,
* false otherwise and null if the action is silent/undefined.
* @throws Error if the action failed
*/
execBatch?: (files: Node[], view) => Promise<boolean[]>
execBatch?: (files: Node[], view, dir: string) => Promise<(boolean|null)[]>
/** This action order in the list */
order?: number,
/** Make this action the default */
Expand Down