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
11 changes: 11 additions & 0 deletions __tests__/fileAction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,17 @@ describe('Invalid FileAction creation', () => {
} as any as FileAction)
}).toThrowError('Invalid order')
})
test('Invalid parent', () => {
expect(() => {
new FileAction({
id: 'test',
displayName: () => 'Test',
iconSvgInline: () => '<svg></svg>',
exec: async () => true,
parent: true,
} as any as FileAction)
}).toThrowError('Invalid parent')
})
test('Invalid default', () => {
expect(() => {
new FileAction({
Expand Down
16 changes: 16 additions & 0 deletions lib/fileAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ interface FileActionData {
iconSvgInline: (files: Node[], view: View) => string
/** Condition wether this action is shown or not */
enabled?: (files: Node[], view: View) => boolean

/**
* Function executed on single file action
* @return true if the action was executed successfully,
Expand All @@ -54,9 +55,16 @@ interface FileActionData {
* @throws Error if the action failed
*/
execBatch?: (files: Node[], view: View, dir: string) => Promise<(boolean|null)[]>

/** This action order in the list */
order?: number,

/**
* This action's parent id in the list.
* If none found, will be displayed as a top-level action.
*/
parent?: string,

/**
* Make this action the default.
* If multiple actions are default, the first one
Expand Down Expand Up @@ -119,6 +127,10 @@ export class FileAction {
return this._action.order
}

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

get default() {
return this._action.default
}
Expand Down Expand Up @@ -165,6 +177,10 @@ export class FileAction {
throw new Error('Invalid order')
}

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

if (action.default && !Object.values(DefaultType).includes(action.default)) {
throw new Error('Invalid default')
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"build": "vite --mode production build",
"build:doc": "typedoc --out dist/doc lib && touch dist/doc/.nojekyll",
"dev": "vite --mode development build",
"dev:watch": "vite --mode development build --watch",
"watch": "vite --mode development build --watch",
"lint": "eslint .",
"lint:fix": "eslint --fix .",
"test": "vitest run",
Expand Down