mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-08 22:22:17 +02:00
- Added the ensure_publication function to create and verify the zero_publication if it is missing, ensuring idempotency during database initialization. - Integrated ensure_publication into the create_db_and_tables function to prevent zero-cache crash loops on startup. - Introduced a self-check script to validate the ensure_publication functionality on a create_all-bootstrapped database. - Updated various components to reflect the transition from search space to workspace, including adjustments in imports and routing paths.
98 lines
3 KiB
TypeScript
98 lines
3 KiB
TypeScript
import { atomWithMutation } from "jotai-tanstack-query";
|
|
import { toast } from "sonner";
|
|
import type {
|
|
CreateSearchSpaceRequest,
|
|
DeleteSearchSpaceRequest,
|
|
UpdateSearchSpaceApiAccessRequest,
|
|
UpdateSearchSpaceRequest,
|
|
} from "@/contracts/types/workspace.types";
|
|
import { searchSpacesApiService } 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 createSearchSpaceMutationAtom = atomWithMutation(() => {
|
|
return {
|
|
mutationKey: ["create-search-space"],
|
|
mutationFn: async (request: CreateSearchSpaceRequest) => {
|
|
return searchSpacesApiService.createSearchSpace(request);
|
|
},
|
|
|
|
onSuccess: () => {
|
|
toast.success("Search space created successfully");
|
|
queryClient.invalidateQueries({
|
|
queryKey: cacheKeys.searchSpaces.all,
|
|
});
|
|
},
|
|
};
|
|
});
|
|
|
|
export const updateSearchSpaceMutationAtom = atomWithMutation((get) => {
|
|
const activeSearchSpaceId = get(activeWorkspaceIdAtom);
|
|
|
|
return {
|
|
mutationKey: ["update-search-space", activeSearchSpaceId],
|
|
enabled: !!activeSearchSpaceId,
|
|
mutationFn: async (request: UpdateSearchSpaceRequest) => {
|
|
return searchSpacesApiService.updateSearchSpace(request);
|
|
},
|
|
|
|
onSuccess: (_, request: UpdateSearchSpaceRequest) => {
|
|
toast.success("Search space updated successfully");
|
|
queryClient.invalidateQueries({
|
|
queryKey: cacheKeys.searchSpaces.all,
|
|
});
|
|
if (request.id) {
|
|
queryClient.invalidateQueries({
|
|
queryKey: cacheKeys.searchSpaces.detail(String(request.id)),
|
|
});
|
|
}
|
|
},
|
|
};
|
|
});
|
|
|
|
export const updateSearchSpaceApiAccessMutationAtom = atomWithMutation((get) => {
|
|
const activeSearchSpaceId = get(activeWorkspaceIdAtom);
|
|
|
|
return {
|
|
mutationKey: ["update-search-space-api-access", activeSearchSpaceId],
|
|
enabled: !!activeSearchSpaceId,
|
|
mutationFn: async (request: UpdateSearchSpaceApiAccessRequest) => {
|
|
return searchSpacesApiService.updateSearchSpaceApiAccess(request);
|
|
},
|
|
|
|
onSuccess: (_, request: UpdateSearchSpaceApiAccessRequest) => {
|
|
toast.success("API access updated successfully");
|
|
queryClient.invalidateQueries({
|
|
queryKey: cacheKeys.searchSpaces.all,
|
|
});
|
|
queryClient.invalidateQueries({
|
|
queryKey: cacheKeys.searchSpaces.detail(String(request.id)),
|
|
});
|
|
},
|
|
};
|
|
});
|
|
|
|
export const deleteSearchSpaceMutationAtom = atomWithMutation((get) => {
|
|
const activeSearchSpaceId = get(activeWorkspaceIdAtom);
|
|
|
|
return {
|
|
mutationKey: ["delete-search-space", activeSearchSpaceId],
|
|
enabled: !!activeSearchSpaceId,
|
|
mutationFn: async (request: DeleteSearchSpaceRequest) => {
|
|
return searchSpacesApiService.deleteSearchSpace(request);
|
|
},
|
|
|
|
onSuccess: (_, request: DeleteSearchSpaceRequest) => {
|
|
toast.success("Search space deleted successfully");
|
|
queryClient.invalidateQueries({
|
|
queryKey: cacheKeys.searchSpaces.all,
|
|
});
|
|
if (request.id) {
|
|
queryClient.removeQueries({
|
|
queryKey: cacheKeys.searchSpaces.detail(String(request.id)),
|
|
});
|
|
}
|
|
},
|
|
};
|
|
});
|