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: support nested actions #814

Merged
merged 2 commits into from Oct 25, 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
11 changes: 11 additions & 0 deletions __tests__/fileAction.spec.ts
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
Expand Up @@ -40,6 +40,7 @@
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 @@
* @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 @@
return this._action.order
}

get parent() {
return this._action.parent

Check warning on line 131 in lib/fileAction.ts

View check run for this annotation

Codecov / codecov/patch

lib/fileAction.ts#L131

Added line #L131 was not covered by tests
}

get default() {
return this._action.default
}
Expand Down Expand Up @@ -165,6 +177,10 @@
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
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