mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-01-11 22:40:26 +01:00
collection plugin actions
This commit is contained in:
@@ -37,6 +37,7 @@ import { getCreateDropdownItems } from '../hooks/useCreateDropdownItems';
|
||||
import { getGrpcRequestActions } from '../hooks/useGrpcRequestActions';
|
||||
import { useHotKey } from '../hooks/useHotKey';
|
||||
import { getHttpRequestActions } from '../hooks/useHttpRequestActions';
|
||||
import { getHttpCollectionActions } from '../hooks/useHttpCollectionActions';
|
||||
import { useListenToTauriEvent } from '../hooks/useListenToTauriEvent';
|
||||
import { getModelAncestors } from '../hooks/useModelAncestors';
|
||||
import { sendAnyHttpRequest } from '../hooks/useSendAnyHttpRequest';
|
||||
@@ -374,6 +375,17 @@ function Sidebar({ className }: { className?: string }) {
|
||||
if (request != null) await a.call(request);
|
||||
},
|
||||
})),
|
||||
...(items.length === 1 && (child.model === 'folder' || child.model === 'workspace')
|
||||
? await getHttpCollectionActions()
|
||||
: []
|
||||
).map((a) => ({
|
||||
label: a.label,
|
||||
leftSlot: <Icon icon={a.icon ?? 'empty'} />,
|
||||
onSelect: async () => {
|
||||
const model = getModel(child.model, child.id);
|
||||
if (model != null) await a.call(model as any);
|
||||
},
|
||||
})),
|
||||
];
|
||||
const modelCreationItems: DropdownItem[] =
|
||||
items.length === 1 && child.model === 'folder'
|
||||
|
||||
50
src-web/hooks/useHttpCollectionActions.ts
Normal file
50
src-web/hooks/useHttpCollectionActions.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import type { Folder, Workspace } from '@yaakapp-internal/models';
|
||||
import type {
|
||||
CallHttpCollectionActionRequest,
|
||||
GetHttpCollectionActionsResponse,
|
||||
HttpCollectionAction,
|
||||
} from '@yaakapp-internal/plugins';
|
||||
import { useMemo } from 'react';
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
import { usePluginsKey } from './usePlugins';
|
||||
|
||||
export type CallableHttpCollectionAction = Pick<HttpCollectionAction, 'label' | 'icon'> & {
|
||||
call: (model: Folder | Workspace) => Promise<void>;
|
||||
};
|
||||
|
||||
export function useHttpCollectionActions() {
|
||||
const pluginsKey = usePluginsKey();
|
||||
|
||||
const actionsResult = useQuery<CallableHttpCollectionAction[]>({
|
||||
queryKey: ['http_collection_actions', pluginsKey],
|
||||
queryFn: () => getHttpCollectionActions(),
|
||||
});
|
||||
|
||||
// biome-ignore lint/correctness/useExhaustiveDependencies: none
|
||||
const actions = useMemo(() => {
|
||||
return actionsResult.data ?? [];
|
||||
}, [JSON.stringify(actionsResult.data)]);
|
||||
|
||||
return actions;
|
||||
}
|
||||
|
||||
export async function getHttpCollectionActions() {
|
||||
const responses = await invokeCmd<GetHttpCollectionActionsResponse[]>('cmd_http_collection_actions');
|
||||
const actions = responses.flatMap((r) =>
|
||||
r.actions.map((a, i) => ({
|
||||
label: a.label,
|
||||
icon: a.icon,
|
||||
call: async (model: Folder | Workspace) => {
|
||||
const payload: CallHttpCollectionActionRequest = {
|
||||
index: i,
|
||||
pluginRefId: r.pluginRefId,
|
||||
args: (model as any).model === 'folder' ? { folder: model as Folder } : { workspace: model as Workspace },
|
||||
} as any;
|
||||
await invokeCmd('cmd_call_http_collection_action', { req: payload });
|
||||
},
|
||||
})),
|
||||
);
|
||||
|
||||
return actions;
|
||||
}
|
||||
@@ -5,6 +5,7 @@ type TauriCmd =
|
||||
| 'cmd_call_grpc_request_action'
|
||||
| 'cmd_call_http_authentication_action'
|
||||
| 'cmd_call_http_request_action'
|
||||
| 'cmd_call_http_collection_action'
|
||||
| 'cmd_check_for_updates'
|
||||
| 'cmd_create_grpc_request'
|
||||
| 'cmd_curl_to_request'
|
||||
@@ -24,6 +25,7 @@ type TauriCmd =
|
||||
| 'cmd_grpc_reflect'
|
||||
| 'cmd_grpc_request_actions'
|
||||
| 'cmd_http_request_actions'
|
||||
| 'cmd_http_collection_actions'
|
||||
| 'cmd_http_response_body'
|
||||
| 'cmd_import_data'
|
||||
| 'cmd_install_plugin'
|
||||
|
||||
Reference in New Issue
Block a user