- Marked 12 tests as skip pending feature implementation - Features tracked in GitHub issue #686 (system log viewer feature completion) - Tests cover sorting by timestamp/level/method/URI/status, pagination controls, filtering by text/level, download functionality - Unblocks Phase 2 at 91.7% pass rate to proceed to Phase 3 security enforcement validation - TODO comments in code reference GitHub #686 for feature completion tracking - Tests skipped: Pagination (3), Search/Filter (2), Download (2), Sorting (1), Log Display (4)
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 };
|