8294d6ee49
- Created `qa-test-output-after-fix.txt` and `qa-test-output.txt` to log results of certificate page authentication tests. - Added `build.sh` for deterministic backend builds in CI, utilizing `go list` for efficiency. - Introduced `codeql_scan.sh` for CodeQL database creation and analysis for Go and JavaScript/TypeScript. - Implemented `dockerfile_check.sh` to validate Dockerfiles for base image and package manager mismatches. - Added `sourcery_precommit_wrapper.sh` to facilitate Sourcery CLI usage in pre-commit hooks.
64 lines
1.9 KiB
TypeScript
64 lines
1.9 KiB
TypeScript
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
|
import {
|
|
getRemoteServers,
|
|
createRemoteServer,
|
|
updateRemoteServer,
|
|
deleteRemoteServer,
|
|
testRemoteServerConnection,
|
|
RemoteServer
|
|
} from '../api/remoteServers';
|
|
|
|
export const QUERY_KEY = ['remote-servers'];
|
|
|
|
export function useRemoteServers(enabledOnly = false) {
|
|
const queryClient = useQueryClient();
|
|
|
|
const query = useQuery({
|
|
queryKey: [...QUERY_KEY, { enabled: enabledOnly }],
|
|
queryFn: () => getRemoteServers(enabledOnly),
|
|
});
|
|
|
|
const createMutation = useMutation({
|
|
mutationFn: (server: Partial<RemoteServer>) => createRemoteServer(server),
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: QUERY_KEY });
|
|
},
|
|
});
|
|
|
|
const updateMutation = useMutation({
|
|
mutationFn: ({ uuid, data }: { uuid: string; data: Partial<RemoteServer> }) =>
|
|
updateRemoteServer(uuid, data),
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: QUERY_KEY });
|
|
},
|
|
});
|
|
|
|
const deleteMutation = useMutation({
|
|
mutationFn: (uuid: string) => deleteRemoteServer(uuid),
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: QUERY_KEY });
|
|
},
|
|
});
|
|
|
|
const testConnectionMutation = useMutation({
|
|
mutationFn: (uuid: string) => testRemoteServerConnection(uuid),
|
|
});
|
|
|
|
return {
|
|
servers: query.data || [],
|
|
loading: query.isLoading,
|
|
isFetching: query.isFetching,
|
|
error: query.error ? (query.error as Error).message : null,
|
|
createServer: createMutation.mutateAsync,
|
|
updateServer: (uuid: string, data: Partial<RemoteServer>) => updateMutation.mutateAsync({ uuid, data }),
|
|
deleteServer: deleteMutation.mutateAsync,
|
|
testConnection: testConnectionMutation.mutateAsync,
|
|
isCreating: createMutation.isPending,
|
|
isUpdating: updateMutation.isPending,
|
|
isDeleting: deleteMutation.isPending,
|
|
isTestingConnection: testConnectionMutation.isPending,
|
|
};
|
|
}
|
|
|
|
export type { RemoteServer };
|