Skip to content

Commit

Permalink
feat(FileAction): Allow to set destructive flag
Browse files Browse the repository at this point in the history
Makes the action be shown more prominently marked as destructive.
Required for nextcloud/server#46732

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
  • Loading branch information
susnux committed Sep 11, 2024
1 parent ae0a991 commit cc9c8be
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/fileAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export enum DefaultType {
HIDDEN = 'hidden',
}

interface FileActionData {
export interface FileActionData {
/** Unique ID */
id: string
/** Translatable string displayed in the menu */
Expand Down Expand Up @@ -42,6 +42,12 @@ interface FileActionData {
/** This action order in the list */
order?: number,

/**
* Set to true if this action is a destructive action, like "delete".
* This will change the appearance in the action menu more prominent (e.g. red colored)
*/
destructive?: boolean

/**
* This action's parent id in the list.
* If none found, will be displayed as a top-level action.
Expand Down Expand Up @@ -118,6 +124,10 @@ export class FileAction {
return this._action.default
}

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

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

if (action.destructive !== undefined && typeof action.destructive !== 'boolean') {
throw new Error('Invalid destructive flag')
}

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

0 comments on commit cc9c8be

Please sign in to comment.