SurfSense/surfsense_web/atoms/workspaces/workspace-mutation.atoms.ts
Anish Sarkar a8c1fb660d feat(rename): complete searchSpace to workspace transition across frontend and backend
- Introduced a comprehensive specification for renaming `searchSpace` to `workspace` in `surfsense_web` and `surfsense_desktop`, ensuring all TypeScript identifiers, React props, and local data structures are updated.
- Implemented migration shims for persisted local state to prevent data loss during the transition.
- Updated observability metrics and IPC channels to reflect the new naming convention.
- Removed legacy `active-search-space` module and replaced it with `active-workspace` to maintain consistency.
- Ensured no behavioral changes or data loss for users during the renaming process.
2026-07-06 15:12:40 +05:30

98 lines
2.9 KiB
TypeScript

import { atomWithMutation } from "jotai-tanstack-query";
import { toast } from "sonner";
import type {
CreateWorkspaceRequest,
DeleteWorkspaceRequest,
UpdateWorkspaceApiAccessRequest,
UpdateWorkspaceRequest,
} from "@/contracts/types/workspace.types";
import { workspacesApiService } from "@/lib/apis/workspaces-api.service";
import { cacheKeys } from "@/lib/query-client/cache-keys";
import { queryClient } from "@/lib/query-client/client";
import { activeWorkspaceIdAtom } from "./workspace-query.atoms";
export const createWorkspaceMutationAtom = atomWithMutation(() => {
return {
mutationKey: ["create-workspace"],
mutationFn: async (request: CreateWorkspaceRequest) => {
return workspacesApiService.createWorkspace(request);
},
onSuccess: () => {
toast.success("Search space created successfully");
queryClient.invalidateQueries({
queryKey: cacheKeys.workspaces.all,
});
},
};
});
export const updateWorkspaceMutationAtom = atomWithMutation((get) => {
const activeWorkspaceId = get(activeWorkspaceIdAtom);
return {
mutationKey: ["update-workspace", activeWorkspaceId],
enabled: !!activeWorkspaceId,
mutationFn: async (request: UpdateWorkspaceRequest) => {
return workspacesApiService.updateWorkspace(request);
},
onSuccess: (_, request: UpdateWorkspaceRequest) => {
toast.success("Search space updated successfully");
queryClient.invalidateQueries({
queryKey: cacheKeys.workspaces.all,
});
if (request.id) {
queryClient.invalidateQueries({
queryKey: cacheKeys.workspaces.detail(String(request.id)),
});
}
},
};
});
export const updateWorkspaceApiAccessMutationAtom = atomWithMutation((get) => {
const activeWorkspaceId = get(activeWorkspaceIdAtom);
return {
mutationKey: ["update-workspace-api-access", activeWorkspaceId],
enabled: !!activeWorkspaceId,
mutationFn: async (request: UpdateWorkspaceApiAccessRequest) => {
return workspacesApiService.updateWorkspaceApiAccess(request);
},
onSuccess: (_, request: UpdateWorkspaceApiAccessRequest) => {
toast.success("API access updated successfully");
queryClient.invalidateQueries({
queryKey: cacheKeys.workspaces.all,
});
queryClient.invalidateQueries({
queryKey: cacheKeys.workspaces.detail(String(request.id)),
});
},
};
});
export const deleteWorkspaceMutationAtom = atomWithMutation((get) => {
const activeWorkspaceId = get(activeWorkspaceIdAtom);
return {
mutationKey: ["delete-workspace", activeWorkspaceId],
enabled: !!activeWorkspaceId,
mutationFn: async (request: DeleteWorkspaceRequest) => {
return workspacesApiService.deleteWorkspace(request);
},
onSuccess: (_, request: DeleteWorkspaceRequest) => {
toast.success("Search space deleted successfully");
queryClient.invalidateQueries({
queryKey: cacheKeys.workspaces.all,
});
if (request.id) {
queryClient.removeQueries({
queryKey: cacheKeys.workspaces.detail(String(request.id)),
});
}
},
};
});