mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-24 17:48:30 +02:00
Add test actions to copy-curl plugin and add WebSocket request actions to Sidebar
This commit is contained in:
@@ -22,6 +22,45 @@ export const plugin: PluginDefinition = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
websocketRequestActions: [
|
||||||
|
{
|
||||||
|
label: 'Test WebSocket Action',
|
||||||
|
icon: 'bug',
|
||||||
|
async onSelect(ctx, args) {
|
||||||
|
await ctx.toast.show({
|
||||||
|
message: `WebSocket action called for: ${args.websocketRequest.name}`,
|
||||||
|
icon: 'bug',
|
||||||
|
color: 'info',
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
workspaceActions: [
|
||||||
|
{
|
||||||
|
label: 'Test Workspace Action',
|
||||||
|
icon: 'bug',
|
||||||
|
async onSelect(ctx, args) {
|
||||||
|
await ctx.toast.show({
|
||||||
|
message: `Workspace action called for: ${args.workspace.name}`,
|
||||||
|
icon: 'bug',
|
||||||
|
color: 'info',
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
folderActions: [
|
||||||
|
{
|
||||||
|
label: 'Test Folder Action',
|
||||||
|
icon: 'bug',
|
||||||
|
async onSelect(ctx, args) {
|
||||||
|
await ctx.toast.show({
|
||||||
|
message: `Folder action called for: ${args.folder.name}`,
|
||||||
|
icon: 'bug',
|
||||||
|
color: 'info',
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function convertToCurl(request: Partial<HttpRequest>) {
|
export async function convertToCurl(request: Partial<HttpRequest>) {
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ import { getCreateDropdownItems } from '../hooks/useCreateDropdownItems';
|
|||||||
import { getGrpcRequestActions } from '../hooks/useGrpcRequestActions';
|
import { getGrpcRequestActions } from '../hooks/useGrpcRequestActions';
|
||||||
import { useHotKey } from '../hooks/useHotKey';
|
import { useHotKey } from '../hooks/useHotKey';
|
||||||
import { getHttpRequestActions } from '../hooks/useHttpRequestActions';
|
import { getHttpRequestActions } from '../hooks/useHttpRequestActions';
|
||||||
|
import { getWebSocketRequestActions } from '../hooks/useWebSocketRequestActions';
|
||||||
import { getWorkspaceActions } from '../hooks/useWorkspaceActions';
|
import { getWorkspaceActions } from '../hooks/useWorkspaceActions';
|
||||||
import { getFolderActions } from '../hooks/useFolderActions';
|
import { getFolderActions } from '../hooks/useFolderActions';
|
||||||
import { useListenToTauriEvent } from '../hooks/useListenToTauriEvent';
|
import { useListenToTauriEvent } from '../hooks/useListenToTauriEvent';
|
||||||
@@ -376,6 +377,17 @@ function Sidebar({ className }: { className?: string }) {
|
|||||||
if (request != null) await a.call(request);
|
if (request != null) await a.call(request);
|
||||||
},
|
},
|
||||||
})),
|
})),
|
||||||
|
...(items.length === 1 && child.model === 'websocket_request'
|
||||||
|
? await getWebSocketRequestActions()
|
||||||
|
: []
|
||||||
|
).map((a) => ({
|
||||||
|
label: a.label,
|
||||||
|
leftSlot: <Icon icon={a.icon ?? 'empty'} />,
|
||||||
|
onSelect: async () => {
|
||||||
|
const request = getModel('websocket_request', child.id);
|
||||||
|
if (request != null) await a.call(request);
|
||||||
|
},
|
||||||
|
})),
|
||||||
...(items.length === 1 && child.model === 'workspace'
|
...(items.length === 1 && child.model === 'workspace'
|
||||||
? await getWorkspaceActions()
|
? await getWorkspaceActions()
|
||||||
: []
|
: []
|
||||||
|
|||||||
52
src-web/hooks/useWebSocketRequestActions.ts
Normal file
52
src-web/hooks/useWebSocketRequestActions.ts
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
import { useQuery } from '@tanstack/react-query';
|
||||||
|
import type { WebsocketRequest } from '@yaakapp-internal/models';
|
||||||
|
import type {
|
||||||
|
CallWebSocketRequestActionRequest,
|
||||||
|
GetWebSocketRequestActionsResponse,
|
||||||
|
WebSocketRequestAction,
|
||||||
|
} from '@yaakapp-internal/plugins';
|
||||||
|
import { useMemo } from 'react';
|
||||||
|
import { invokeCmd } from '../lib/tauri';
|
||||||
|
import { usePluginsKey } from './usePlugins';
|
||||||
|
|
||||||
|
export type CallableWebSocketRequestAction = Pick<WebSocketRequestAction, 'label' | 'icon'> & {
|
||||||
|
call: (request: WebsocketRequest) => Promise<void>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function useWebSocketRequestActions() {
|
||||||
|
const pluginsKey = usePluginsKey();
|
||||||
|
|
||||||
|
const actionsResult = useQuery<CallableWebSocketRequestAction[]>({
|
||||||
|
queryKey: ['websocket_request_actions', pluginsKey],
|
||||||
|
queryFn: () => getWebSocketRequestActions(),
|
||||||
|
});
|
||||||
|
|
||||||
|
// biome-ignore lint/correctness/useExhaustiveDependencies: none
|
||||||
|
const actions = useMemo(() => {
|
||||||
|
return actionsResult.data ?? [];
|
||||||
|
}, [JSON.stringify(actionsResult.data)]);
|
||||||
|
|
||||||
|
return actions;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getWebSocketRequestActions() {
|
||||||
|
const responses = await invokeCmd<GetWebSocketRequestActionsResponse[]>(
|
||||||
|
'cmd_websocket_request_actions',
|
||||||
|
);
|
||||||
|
const actions = responses.flatMap((r) =>
|
||||||
|
r.actions.map((a, i) => ({
|
||||||
|
label: a.label,
|
||||||
|
icon: a.icon,
|
||||||
|
call: async (websocketRequest: WebsocketRequest) => {
|
||||||
|
const payload: CallWebSocketRequestActionRequest = {
|
||||||
|
index: i,
|
||||||
|
pluginRefId: r.pluginRefId,
|
||||||
|
args: { websocketRequest },
|
||||||
|
};
|
||||||
|
await invokeCmd('cmd_call_websocket_request_action', { req: payload });
|
||||||
|
},
|
||||||
|
})),
|
||||||
|
);
|
||||||
|
|
||||||
|
return actions;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user