mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-22 16:48:30 +02:00
Refresh query when plugins reload in useTemplateFunctionConfig hook
This commit is contained in:
@@ -1,12 +1,14 @@
|
|||||||
import { useQuery } from '@tanstack/react-query';
|
import { useQuery } from '@tanstack/react-query';
|
||||||
import type {
|
import {
|
||||||
Folder,
|
environmentsAtom,
|
||||||
GrpcRequest,
|
type Folder,
|
||||||
HttpRequest,
|
type GrpcRequest,
|
||||||
WebsocketRequest,
|
type HttpRequest,
|
||||||
Workspace,
|
httpResponsesAtom,
|
||||||
|
pluginsAtom,
|
||||||
|
type WebsocketRequest,
|
||||||
|
type Workspace,
|
||||||
} from '@yaakapp-internal/models';
|
} from '@yaakapp-internal/models';
|
||||||
import { environmentsAtom, httpResponsesAtom } from '@yaakapp-internal/models';
|
|
||||||
import type { GetTemplateFunctionConfigResponse, JsonPrimitive } from '@yaakapp-internal/plugins';
|
import type { GetTemplateFunctionConfigResponse, JsonPrimitive } from '@yaakapp-internal/plugins';
|
||||||
import { useAtomValue } from 'jotai';
|
import { useAtomValue } from 'jotai';
|
||||||
import { md5 } from 'js-md5';
|
import { md5 } from 'js-md5';
|
||||||
@@ -19,6 +21,7 @@ export function useTemplateFunctionConfig(
|
|||||||
values: Record<string, JsonPrimitive>,
|
values: Record<string, JsonPrimitive>,
|
||||||
model: HttpRequest | GrpcRequest | WebsocketRequest | Folder | Workspace,
|
model: HttpRequest | GrpcRequest | WebsocketRequest | Folder | Workspace,
|
||||||
) {
|
) {
|
||||||
|
const pluginsKey = useAtomValue(pluginsAtom);
|
||||||
const workspaceId = useAtomValue(activeWorkspaceIdAtom);
|
const workspaceId = useAtomValue(activeWorkspaceIdAtom);
|
||||||
const environmentId = useAtomValue(activeEnvironmentIdAtom);
|
const environmentId = useAtomValue(activeEnvironmentIdAtom);
|
||||||
const responses = useAtomValue(httpResponsesAtom);
|
const responses = useAtomValue(httpResponsesAtom);
|
||||||
@@ -40,10 +43,11 @@ export function useTemplateFunctionConfig(
|
|||||||
model,
|
model,
|
||||||
functionName,
|
functionName,
|
||||||
values,
|
values,
|
||||||
responseKey,
|
workspaceId, // Refresh when the active workspace changes
|
||||||
workspaceId,
|
environmentId, // Refresh when the active environment changes
|
||||||
environmentId,
|
environmentsKey, // Refresh when environments change
|
||||||
environmentsKey,
|
responseKey, // Refresh when responses change
|
||||||
|
pluginsKey, // Refresh when plugins reload
|
||||||
],
|
],
|
||||||
placeholderData: (prev) => prev, // Keep previous data on refetch
|
placeholderData: (prev) => prev, // Keep previous data on refetch
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user