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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add current folder context for file list actions #1113

Merged
merged 2 commits into from
Nov 13, 2024
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
5 changes: 3 additions & 2 deletions __tests__/fileListAction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { beforeEach, describe, expect, test, vi } from 'vitest'
import type { View } from '../lib/navigation/view.ts'

import { getFileListActions, registerFileListAction, FileListAction } from '../lib/fileListAction.ts'
import { Folder } from '../lib/files/folder.ts'
import logger from '../lib/utils/logger.ts'

const mockAction = (id: string) => new FileListAction({
Expand Down Expand Up @@ -155,7 +156,7 @@ describe('FileListAction creation', () => {
expect(testAction.displayName({} as unknown as View)).toBe('Test')
expect(testAction.iconSvgInline({} as unknown as View)).toBe('<svg></svg>')
expect(testAction.order).toBe(0)
expect(testAction.enabled?.({} as unknown as View, [])).toBe(true)
await expect(testAction.exec({} as unknown as View, [])).resolves.toBe(undefined)
expect(testAction.enabled?.({} as unknown as View, [], { folder: {} as Folder })).toBe(true)
await expect(testAction.exec({} as unknown as View, [], { folder: {} as Folder })).resolves.toBe(undefined)
})
})
13 changes: 11 additions & 2 deletions lib/fileListAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@
*/

import { Node } from './files/node.ts'
import { Folder } from './files/folder.ts'
import { View } from './navigation/view.ts'
import logger from './utils/logger.ts'

interface ActionContext {
folder: Folder,
}

interface FileListActionData {
/** Unique ID */
id: string
Expand All @@ -24,15 +29,19 @@ interface FileListActionData {
* Returns true if this action shoud be shown
*
* @param nodes The nodes in the current directory
* @param context The context
* @param context.folder The current folder
*/
enabled?: (view: View, nodes: Node[]) => boolean
enabled?: (view: View, nodes: Node[], context: ActionContext) => boolean

/**
* Function to execute
*
* @param nodes The nodes in the current directory
* @param context The context
* @param context.folder The current folder
*/
exec: (view: View, nodes: Node[]) => Promise<void>
exec: (view: View, nodes: Node[], context: ActionContext) => Promise<void>
}

export class FileListAction {
Expand Down
Loading