mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-01-11 22:40:26 +01:00
Refactor new actions apis
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -0,0 +1,11 @@
|
||||
import type { Context } from './Context';
|
||||
import type { Folder } from '../bindings/gen_models';
|
||||
import type { Icon } from '../bindings/gen_events';
|
||||
|
||||
export type FolderAction = { label: string; icon?: Icon };
|
||||
|
||||
export type CallFolderActionArgs = { folder: Folder };
|
||||
|
||||
export type FolderActionPlugin = FolderAction & {
|
||||
onSelect(ctx: Context, args: CallFolderActionArgs): Promise<void> | void;
|
||||
};
|
||||
@@ -1,11 +0,0 @@
|
||||
import type { Context } from './Context';
|
||||
import type { Folder, Workspace } from '../bindings/gen_models';
|
||||
import type { Icon } from '../bindings/gen_events';
|
||||
|
||||
export type HttpCollectionAction = { label: string; icon?: Icon };
|
||||
|
||||
export type CallHttpCollectionActionArgs = { folder?: Folder; workspace?: Workspace };
|
||||
|
||||
export type HttpCollectionActionPlugin = HttpCollectionAction & {
|
||||
onSelect(ctx: Context, args: CallHttpCollectionActionArgs): Promise<void> | void;
|
||||
};
|
||||
@@ -0,0 +1,6 @@
|
||||
import type { CallWebSocketRequestActionArgs, WebSocketRequestAction } from '../bindings/gen_events';
|
||||
import type { Context } from './Context';
|
||||
|
||||
export type WebSocketRequestActionPlugin = WebSocketRequestAction & {
|
||||
onSelect(ctx: Context, args: CallWebSocketRequestActionArgs): Promise<void> | void;
|
||||
};
|
||||
@@ -0,0 +1,11 @@
|
||||
import type { Context } from './Context';
|
||||
import type { Workspace } from '../bindings/gen_models';
|
||||
import type { Icon } from '../bindings/gen_events';
|
||||
|
||||
export type WorkspaceAction = { label: string; icon?: Icon };
|
||||
|
||||
export type CallWorkspaceActionArgs = { workspace: Workspace };
|
||||
|
||||
export type WorkspaceActionPlugin = WorkspaceAction & {
|
||||
onSelect(ctx: Context, args: CallWorkspaceActionArgs): Promise<void> | void;
|
||||
};
|
||||
@@ -4,7 +4,9 @@ import type { Context } from './Context';
|
||||
import type { FilterPlugin } from './FilterPlugin';
|
||||
import { GrpcRequestActionPlugin } from './GrpcRequestActionPlugin';
|
||||
import type { HttpRequestActionPlugin } from './HttpRequestActionPlugin';
|
||||
import type { HttpCollectionActionPlugin } from './HttpCollectionActionPlugin';
|
||||
import type { WebSocketRequestActionPlugin } from './WebSocketRequestActionPlugin';
|
||||
import type { WorkspaceActionPlugin } from './WorkspaceActionPlugin';
|
||||
import type { FolderActionPlugin } from './FolderActionPlugin';
|
||||
import type { ImporterPlugin } from './ImporterPlugin';
|
||||
import type { TemplateFunctionPlugin } from './TemplateFunctionPlugin';
|
||||
import type { ThemePlugin } from './ThemePlugin';
|
||||
@@ -13,7 +15,8 @@ export type { Context };
|
||||
export type { DynamicTemplateFunctionArg } from './TemplateFunctionPlugin';
|
||||
export type { DynamicAuthenticationArg } from './AuthenticationPlugin';
|
||||
export type { TemplateFunctionPlugin };
|
||||
export type { HttpCollectionActionPlugin } from './HttpCollectionActionPlugin';
|
||||
export type { WorkspaceActionPlugin } from './WorkspaceActionPlugin';
|
||||
export type { FolderActionPlugin } from './FolderActionPlugin';
|
||||
|
||||
/**
|
||||
* The global structure of a Yaak plugin
|
||||
@@ -26,7 +29,9 @@ export type PluginDefinition = {
|
||||
filter?: FilterPlugin;
|
||||
authentication?: AuthenticationPlugin;
|
||||
httpRequestActions?: HttpRequestActionPlugin[];
|
||||
httpCollectionActions?: HttpCollectionActionPlugin[];
|
||||
websocketRequestActions?: WebSocketRequestActionPlugin[];
|
||||
workspaceActions?: WorkspaceActionPlugin[];
|
||||
folderActions?: FolderActionPlugin[];
|
||||
grpcRequestActions?: GrpcRequestActionPlugin[];
|
||||
templateFunctions?: TemplateFunctionPlugin[];
|
||||
};
|
||||
|
||||
@@ -174,16 +174,49 @@ export class PluginInstance {
|
||||
}
|
||||
|
||||
if (
|
||||
payload.type === 'get_http_collection_actions_request' &&
|
||||
Array.isArray(this.#mod?.httpCollectionActions)
|
||||
payload.type === 'get_websocket_request_actions_request' &&
|
||||
Array.isArray(this.#mod?.websocketRequestActions)
|
||||
) {
|
||||
const reply: HttpRequestAction[] = this.#mod.httpCollectionActions.map((a) => ({
|
||||
const reply = this.#mod.websocketRequestActions.map((a) => ({
|
||||
...a,
|
||||
// Add everything except onSelect
|
||||
onSelect: undefined,
|
||||
}));
|
||||
const replyPayload: InternalEventPayload = {
|
||||
type: 'get_http_collection_actions_response',
|
||||
type: 'get_websocket_request_actions_response',
|
||||
pluginRefId: this.#workerData.pluginRefId,
|
||||
actions: reply,
|
||||
};
|
||||
this.#sendPayload(context, replyPayload, replyId);
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
payload.type === 'get_workspace_actions_request' &&
|
||||
Array.isArray(this.#mod?.workspaceActions)
|
||||
) {
|
||||
const reply = this.#mod.workspaceActions.map((a) => ({
|
||||
...a,
|
||||
onSelect: undefined,
|
||||
}));
|
||||
const replyPayload: InternalEventPayload = {
|
||||
type: 'get_workspace_actions_response',
|
||||
pluginRefId: this.#workerData.pluginRefId,
|
||||
actions: reply,
|
||||
};
|
||||
this.#sendPayload(context, replyPayload, replyId);
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
payload.type === 'get_folder_actions_request' &&
|
||||
Array.isArray(this.#mod?.folderActions)
|
||||
) {
|
||||
const reply = this.#mod.folderActions.map((a) => ({
|
||||
...a,
|
||||
onSelect: undefined,
|
||||
}));
|
||||
const replyPayload: InternalEventPayload = {
|
||||
type: 'get_folder_actions_response',
|
||||
pluginRefId: this.#workerData.pluginRefId,
|
||||
actions: reply,
|
||||
};
|
||||
@@ -322,10 +355,34 @@ export class PluginInstance {
|
||||
}
|
||||
|
||||
if (
|
||||
payload.type === 'call_http_collection_action_request' &&
|
||||
Array.isArray(this.#mod.httpCollectionActions)
|
||||
payload.type === 'call_websocket_request_action_request' &&
|
||||
Array.isArray(this.#mod.websocketRequestActions)
|
||||
) {
|
||||
const action = this.#mod.httpCollectionActions[payload.index];
|
||||
const action = this.#mod.websocketRequestActions[payload.index];
|
||||
if (typeof action?.onSelect === 'function') {
|
||||
await action.onSelect(ctx, payload.args);
|
||||
this.#sendEmpty(context, replyId);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
payload.type === 'call_workspace_action_request' &&
|
||||
Array.isArray(this.#mod.workspaceActions)
|
||||
) {
|
||||
const action = this.#mod.workspaceActions[payload.index];
|
||||
if (typeof action?.onSelect === 'function') {
|
||||
await action.onSelect(ctx, payload.args);
|
||||
this.#sendEmpty(context, replyId);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
payload.type === 'call_folder_action_request' &&
|
||||
Array.isArray(this.#mod.folderActions)
|
||||
) {
|
||||
const action = this.#mod.folderActions[payload.index];
|
||||
if (typeof action?.onSelect === 'function') {
|
||||
await action.onSelect(ctx, payload.args);
|
||||
this.#sendEmpty(context, replyId);
|
||||
|
||||
Reference in New Issue
Block a user