Refactor: Drop isActionName and convert getCustomActions to

`filterActions`.
This commit is contained in:
Daniel J. Geiger 2023-01-28 21:27:25 -06:00
parent 87aba3f619
commit 14c6ea938a
8 changed files with 145 additions and 133 deletions

View file

@ -242,6 +242,7 @@ import {
prepareSubtype,
selectSubtype,
subtypeActionPredicate,
isSubtypeAction,
} from "../subtypes";
import {
dataURLToFile,
@ -6229,26 +6230,26 @@ class App extends React.Component<AppProps, AppState> {
};
private getContextMenuItems = (
type: "canvas" | "element" | "custom",
source?: string,
type: "canvas" | "element",
): ContextMenuItems => {
const custom: ContextMenuItems = [];
const subtype: ContextMenuItems = [];
this.actionManager
.getCustomActions({ data: { source: source ?? "" } })
.forEach((action) => custom.push(action));
if (type === "custom") {
return custom;
}
if (custom.length > 0) {
custom.push(CONTEXT_MENU_SEPARATOR);
.filterActions(isSubtypeAction)
.forEach(
(action) =>
this.actionManager.isActionEnabled(action, { data: {} }) &&
subtype.push(action),
);
if (subtype.length > 0) {
subtype.push(CONTEXT_MENU_SEPARATOR);
}
const standard: ContextMenuItems = this._getContextMenuItems(type).filter(
(item) =>
!item ||
item === CONTEXT_MENU_SEPARATOR ||
this.actionManager.isActionEnabled(item, { guardsOnly: true }),
this.actionManager.isActionEnabled(item, { noPredicates: true }),
);
return [...custom, ...standard];
return [...subtype, ...standard];
};
private _getContextMenuItems = (