mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-17 23:13:51 +01:00
plugin:yaak-models|upsert PoC
This commit is contained in:
@@ -86,7 +86,6 @@ export function HttpResponsePane({ style, className, activeRequestId }: Props) {
|
||||
},
|
||||
[activeRequestId, setActiveTabs],
|
||||
);
|
||||
console.log("ACTIVE RESPONSE", activeResponse);
|
||||
|
||||
return (
|
||||
<div
|
||||
|
||||
@@ -152,7 +152,9 @@ export const SidebarItem = memo(function SidebarItem({
|
||||
if (request == null) return;
|
||||
await upsertWebsocketRequest.mutateAsync({ ...request, name: el.value });
|
||||
}
|
||||
setEditing(false);
|
||||
|
||||
// Slight delay for the model to propagate to the local store
|
||||
setTimeout(() => setEditing(false));
|
||||
},
|
||||
[itemId, itemModel, updateGrpcRequest, updateHttpRequest],
|
||||
);
|
||||
@@ -268,10 +270,7 @@ export const SidebarItem = memo(function SidebarItem({
|
||||
size="sm"
|
||||
icon="chevron_right"
|
||||
color="secondary"
|
||||
className={classNames(
|
||||
'transition-transform',
|
||||
!collapsed && 'transform rotate-90',
|
||||
)}
|
||||
className={classNames('transition-transform', !collapsed && 'transform rotate-90')}
|
||||
/>
|
||||
)}
|
||||
<div className="flex items-center gap-2 min-w-0">
|
||||
|
||||
@@ -1,15 +1,10 @@
|
||||
import type { CookieJar } from '@yaakapp-internal/models';
|
||||
import { useSetAtom } from 'jotai';
|
||||
import { InlineCode } from '../components/core/InlineCode';
|
||||
import { showConfirmDelete } from '../lib/confirm';
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
import { cookieJarsAtom } from './useCookieJars';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import { removeModelById } from './useSyncModelStores';
|
||||
|
||||
export function useDeleteCookieJar(cookieJar: CookieJar | null) {
|
||||
const setCookieJars = useSetAtom(cookieJarsAtom);
|
||||
|
||||
return useFastMutation<CookieJar | null, string>({
|
||||
mutationKey: ['delete_cookie_jar', cookieJar?.id],
|
||||
mutationFn: async () => {
|
||||
@@ -25,10 +20,5 @@ export function useDeleteCookieJar(cookieJar: CookieJar | null) {
|
||||
if (!confirmed) return null;
|
||||
return invokeCmd('cmd_delete_cookie_jar', { cookieJarId: cookieJar?.id });
|
||||
},
|
||||
onSuccess: (cookieJar) => {
|
||||
if (cookieJar == null) return;
|
||||
|
||||
setCookieJars(removeModelById(cookieJar));
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,15 +1,10 @@
|
||||
import type { Environment } from '@yaakapp-internal/models';
|
||||
import { useSetAtom } from 'jotai';
|
||||
import { InlineCode } from '../components/core/InlineCode';
|
||||
import { showConfirmDelete } from '../lib/confirm';
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
import { environmentsAtom } from './useEnvironments';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import { removeModelById } from './useSyncModelStores';
|
||||
|
||||
export function useDeleteEnvironment(environment: Environment | null) {
|
||||
const setEnvironments = useSetAtom(environmentsAtom);
|
||||
|
||||
return useFastMutation<Environment | null, string>({
|
||||
mutationKey: ['delete_environment', environment?.id],
|
||||
mutationFn: async () => {
|
||||
@@ -25,10 +20,5 @@ export function useDeleteEnvironment(environment: Environment | null) {
|
||||
if (!confirmed) return null;
|
||||
return invokeCmd('cmd_delete_environment', { environmentId: environment?.id });
|
||||
},
|
||||
onSuccess: (environment) => {
|
||||
if (environment == null) return;
|
||||
|
||||
setEnvironments(removeModelById(environment));
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
import type { Folder } from '@yaakapp-internal/models';
|
||||
import { useSetAtom } from 'jotai';
|
||||
import { InlineCode } from '../components/core/InlineCode';
|
||||
import { showConfirmDelete } from '../lib/confirm';
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import { foldersAtom, getFolder } from './useFolders';
|
||||
import { removeModelById } from './useSyncModelStores';
|
||||
import { getFolder } from './useFolders';
|
||||
|
||||
export function useDeleteFolder(id: string | null) {
|
||||
const setFolders = useSetAtom(foldersAtom);
|
||||
|
||||
return useFastMutation<Folder | null, string>({
|
||||
mutationKey: ['delete_folder', id],
|
||||
mutationFn: async () => {
|
||||
@@ -26,10 +22,5 @@ export function useDeleteFolder(id: string | null) {
|
||||
if (!confirmed) return null;
|
||||
return invokeCmd('cmd_delete_folder', { folderId: id });
|
||||
},
|
||||
onSuccess: (folder) => {
|
||||
if (folder == null) return;
|
||||
|
||||
setFolders(removeModelById(folder));
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,21 +1,12 @@
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import type { GrpcConnection } from '@yaakapp-internal/models';
|
||||
import {useSetAtom} from "jotai";
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
import {grpcConnectionsAtom} from "./useGrpcConnections";
|
||||
import {removeModelById} from "./useSyncModelStores";
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
|
||||
export function useDeleteGrpcConnection(id: string | null) {
|
||||
const setGrpcConnections = useSetAtom(grpcConnectionsAtom);
|
||||
return useFastMutation<GrpcConnection>({
|
||||
mutationKey: ['delete_grpc_connection', id],
|
||||
mutationFn: async () => {
|
||||
return await invokeCmd('cmd_delete_grpc_connection', { id: id });
|
||||
},
|
||||
onSuccess: (connection) => {
|
||||
if (connection == null) return;
|
||||
|
||||
setGrpcConnections(removeModelById(connection));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,19 +1,12 @@
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import type { HttpResponse } from '@yaakapp-internal/models';
|
||||
import {useSetAtom} from "jotai";
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
import {httpResponsesAtom} from "./useHttpResponses";
|
||||
import {removeModelById} from "./useSyncModelStores";
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
|
||||
export function useDeleteHttpResponse(id: string | null) {
|
||||
const setHttpResponses = useSetAtom(httpResponsesAtom);
|
||||
return useFastMutation<HttpResponse>({
|
||||
mutationKey: ['delete_http_response', id],
|
||||
mutationFn: async () => {
|
||||
return await invokeCmd('cmd_delete_http_response', { id: id });
|
||||
},
|
||||
onSuccess: (response) => {
|
||||
setHttpResponses(removeModelById(response));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ export function useSyncModelStores() {
|
||||
});
|
||||
}
|
||||
|
||||
export function updateModelList<T extends AnyModel>(model: T) {
|
||||
function updateModelList<T extends AnyModel>(model: T) {
|
||||
// Mark these models as DESC instead of ASC
|
||||
const pushToFront =
|
||||
model.model === 'http_response' ||
|
||||
@@ -152,7 +152,7 @@ export function updateModelList<T extends AnyModel>(model: T) {
|
||||
};
|
||||
}
|
||||
|
||||
export function removeModelById<T extends { id: string }>(model: T) {
|
||||
function removeModelById<T extends { id: string }>(model: T) {
|
||||
return (prevEntries: T[] | undefined) => {
|
||||
const entries = prevEntries?.filter((e) => e.id !== model.id) ?? [];
|
||||
|
||||
@@ -165,7 +165,7 @@ export function removeModelById<T extends { id: string }>(model: T) {
|
||||
};
|
||||
}
|
||||
|
||||
export function removeModelByKv(model: KeyValue) {
|
||||
function removeModelByKv(model: KeyValue) {
|
||||
return (prevEntries: KeyValue[] | undefined) =>
|
||||
prevEntries?.filter(
|
||||
(e) =>
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
import type { Folder } from '@yaakapp-internal/models';
|
||||
import { useSetAtom } from 'jotai/index';
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import { foldersAtom, getFolder } from './useFolders';
|
||||
import { updateModelList } from './useSyncModelStores';
|
||||
import { getFolder } from './useFolders';
|
||||
|
||||
export function useUpdateAnyFolder() {
|
||||
const setFolders = useSetAtom(foldersAtom);
|
||||
return useFastMutation<Folder, unknown, { id: string; update: (r: Folder) => Folder }>({
|
||||
mutationKey: ['update_any_folder'],
|
||||
mutationFn: async ({ id, update }) => {
|
||||
@@ -17,8 +14,5 @@ export function useUpdateAnyFolder() {
|
||||
|
||||
return invokeCmd<Folder>('cmd_update_folder', { folder: update(folder) });
|
||||
},
|
||||
onSuccess: async (folder) => {
|
||||
setFolders(updateModelList(folder));
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
import type { GrpcRequest } from '@yaakapp-internal/models';
|
||||
import { useSetAtom } from 'jotai/index';
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import { getGrpcRequest, grpcRequestsAtom } from './useGrpcRequests';
|
||||
import { updateModelList } from './useSyncModelStores';
|
||||
import { getGrpcRequest } from './useGrpcRequests';
|
||||
|
||||
export function useUpdateAnyGrpcRequest() {
|
||||
const setGrpcRequests = useSetAtom(grpcRequestsAtom);
|
||||
return useFastMutation<
|
||||
GrpcRequest,
|
||||
unknown,
|
||||
@@ -23,8 +20,5 @@ export function useUpdateAnyGrpcRequest() {
|
||||
typeof update === 'function' ? update(request) : { ...request, ...update };
|
||||
return invokeCmd<GrpcRequest>('cmd_update_grpc_request', { request: patchedRequest });
|
||||
},
|
||||
onSuccess: (request) => {
|
||||
setGrpcRequests(updateModelList(request));
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
import type { HttpRequest } from '@yaakapp-internal/models';
|
||||
import { useSetAtom } from 'jotai/index';
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
import { upsertAnyModel } from '@yaakapp-internal/models';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import { getHttpRequest, httpRequestsAtom } from './useHttpRequests';
|
||||
import { updateModelList } from './useSyncModelStores';
|
||||
import { getHttpRequest } from './useHttpRequests';
|
||||
|
||||
export function useUpdateAnyHttpRequest() {
|
||||
const setHttpRequests = useSetAtom(httpRequestsAtom);
|
||||
return useFastMutation<
|
||||
HttpRequest,
|
||||
void,
|
||||
unknown,
|
||||
{ id: string; update: Partial<HttpRequest> | ((r: HttpRequest) => HttpRequest) }
|
||||
>({
|
||||
@@ -21,10 +18,7 @@ export function useUpdateAnyHttpRequest() {
|
||||
|
||||
const patchedRequest =
|
||||
typeof update === 'function' ? update(request) : { ...request, ...update };
|
||||
return invokeCmd<HttpRequest>('cmd_upsert_http_request', { request: patchedRequest });
|
||||
},
|
||||
onSuccess: async (request) => {
|
||||
setHttpRequests(updateModelList(request));
|
||||
await upsertAnyModel(patchedRequest);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import type { CookieJar } from '@yaakapp-internal/models';
|
||||
import { useSetAtom } from 'jotai/index';
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
import { cookieJarsAtom, getCookieJar } from './useCookieJars';
|
||||
import { updateModelList } from './useSyncModelStores';
|
||||
import { getCookieJar } from './useCookieJars';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
|
||||
export function useUpdateCookieJar(id: string | null) {
|
||||
const setCookieJars = useSetAtom(cookieJarsAtom);
|
||||
return useFastMutation<CookieJar, unknown, Partial<CookieJar> | ((j: CookieJar) => CookieJar)>({
|
||||
mutationKey: ['update_cookie_jar', id],
|
||||
mutationFn: async (v) => {
|
||||
@@ -18,8 +15,5 @@ export function useUpdateCookieJar(id: string | null) {
|
||||
const newCookieJar = typeof v === 'function' ? v(cookieJar) : { ...cookieJar, ...v };
|
||||
return invokeCmd<CookieJar>('cmd_update_cookie_jar', { cookieJar: newCookieJar });
|
||||
},
|
||||
onSuccess: (cookieJar) => {
|
||||
setCookieJars(updateModelList(cookieJar));
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
import type { Environment } from '@yaakapp-internal/models';
|
||||
import { useSetAtom } from 'jotai/index';
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
import { environmentsAtom, getEnvironment } from './useEnvironments';
|
||||
import { getEnvironment } from './useEnvironments';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import { updateModelList } from './useSyncModelStores';
|
||||
|
||||
export function useUpdateEnvironment(id: string | null) {
|
||||
const setEnvironments = useSetAtom(environmentsAtom);
|
||||
return useFastMutation<
|
||||
Environment,
|
||||
unknown,
|
||||
@@ -22,8 +19,5 @@ export function useUpdateEnvironment(id: string | null) {
|
||||
const newEnvironment = typeof v === 'function' ? v(environment) : { ...environment, ...v };
|
||||
return invokeCmd<Environment>('cmd_update_environment', { environment: newEnvironment });
|
||||
},
|
||||
onSuccess: async (environment) => {
|
||||
setEnvironments(updateModelList(environment));
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user