refactor: actions menu
This commit is contained in:
@@ -53,20 +53,22 @@ class ActionsMenuCtrl extends PureViewCtrl implements ActionsMenuScope {
|
|||||||
};
|
};
|
||||||
|
|
||||||
async loadExtensions() {
|
async loadExtensions() {
|
||||||
const extensions = this.application.actionsManager!.getExtensions().sort((a, b) => {
|
const actionExtensions = this.application.actionsManager!.getExtensions().sort((a, b) => {
|
||||||
return a.name.toLowerCase() < b.name.toLowerCase() ? -1 : 1;
|
return a.name.toLowerCase() < b.name.toLowerCase() ? -1 : 1;
|
||||||
});
|
});
|
||||||
for (const extension of extensions) {
|
let extensionsForItem = [];
|
||||||
await this.application.actionsManager!.loadExtensionInContextOfItem(
|
for (const extension of actionExtensions) {
|
||||||
|
const extensionInContext = await this.application.actionsManager!.loadExtensionInContextOfItem(
|
||||||
extension,
|
extension,
|
||||||
this.props.item
|
this.props.item
|
||||||
);
|
);
|
||||||
|
extensionsForItem.push(extensionInContext);
|
||||||
}
|
}
|
||||||
if (extensions.length == 0) {
|
if (actionExtensions.length == 0) {
|
||||||
this.loadingExtensions = false;
|
this.loadingExtensions = false;
|
||||||
}
|
}
|
||||||
await this.setState({
|
await this.setState({
|
||||||
extensions: extensions
|
extensions: extensionsForItem
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,11 +95,7 @@ class ActionsMenuCtrl extends PureViewCtrl implements ActionsMenuScope {
|
|||||||
}
|
}
|
||||||
await this.updateAction(action, extension, { running: false });
|
await this.updateAction(action, extension, { running: false });
|
||||||
this.handleActionResponse(action, response);
|
this.handleActionResponse(action, response);
|
||||||
const updatedExtension = await this.application.actionsManager!.loadExtensionInContextOfItem(
|
await this.reloadExtension(extension);
|
||||||
extension,
|
|
||||||
this.props.item
|
|
||||||
);
|
|
||||||
await this.updateExtension(updatedExtension!);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handleActionResponse(action: Action, result: ActionResponse) {
|
handleActionResponse(action: Action, result: ActionResponse) {
|
||||||
@@ -112,7 +110,7 @@ class ActionsMenuCtrl extends PureViewCtrl implements ActionsMenuScope {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
subRowsForAction(parentAction: Action, extension: SNActionsExtension): ActionSubRow[] | undefined {
|
private subRowsForAction(parentAction: Action, extension: SNActionsExtension): ActionSubRow[] | undefined {
|
||||||
if (!parentAction.subactions) {
|
if (!parentAction.subactions) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
@@ -128,7 +126,7 @@ class ActionsMenuCtrl extends PureViewCtrl implements ActionsMenuScope {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateAction(
|
private async updateAction(
|
||||||
action: Action,
|
action: Action,
|
||||||
extension: SNActionsExtension,
|
extension: SNActionsExtension,
|
||||||
params: UpdateActionParams
|
params: UpdateActionParams
|
||||||
@@ -150,19 +148,38 @@ class ActionsMenuCtrl extends PureViewCtrl implements ActionsMenuScope {
|
|||||||
await this.updateExtension(updatedExtension);
|
await this.updateExtension(updatedExtension);
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateExtension(extension: SNActionsExtension, params?: UpdateExtensionParams) {
|
private async updateExtension(
|
||||||
|
extension: SNActionsExtension,
|
||||||
|
params?: UpdateExtensionParams
|
||||||
|
) {
|
||||||
const updatedExtension = await this.application.changeItem(extension.uuid, (mutator) => {
|
const updatedExtension = await this.application.changeItem(extension.uuid, (mutator) => {
|
||||||
const extensionMutator = mutator as ActionsExtensionMutator;
|
const extensionMutator = mutator as ActionsExtensionMutator;
|
||||||
extensionMutator.hidden = params && params.hidden;
|
extensionMutator.hidden = params && params.hidden;
|
||||||
}) as SNActionsExtension;
|
}) as SNActionsExtension;
|
||||||
const updatedExtensions = this.state.extensions.map((ext: SNActionsExtension) => {
|
const extensions = this.state.extensions.map((ext: SNActionsExtension) => {
|
||||||
if (extension.uuid === ext.uuid) {
|
if (extension.uuid === ext.uuid) {
|
||||||
return updatedExtension;
|
return updatedExtension;
|
||||||
}
|
}
|
||||||
return ext;
|
return ext;
|
||||||
});
|
});
|
||||||
await this.setState({
|
await this.setState({
|
||||||
extensions: updatedExtensions
|
extensions: extensions
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private async reloadExtension(extension: SNActionsExtension) {
|
||||||
|
const extensionInContext = await this.application.actionsManager!.loadExtensionInContextOfItem(
|
||||||
|
extension,
|
||||||
|
this.props.item
|
||||||
|
);
|
||||||
|
const extensions = this.state.extensions.map((ext: SNActionsExtension) => {
|
||||||
|
if (extension.uuid === ext.uuid) {
|
||||||
|
return extensionInContext;
|
||||||
|
}
|
||||||
|
return ext;
|
||||||
|
});
|
||||||
|
this.setState({
|
||||||
|
extensions: extensions
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user