Skip to content

Commit 0f6e246

Browse files
committed
feat(ui): add delete connection(s)
1 parent 57aec0d commit 0f6e246

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

ui/src/api/v1.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ export function usePostConfig() {
227227
}
228228

229229
export function useDeleteConnections(baseUrl?: string) {
230-
const url = `${baseUrl || ''}/api/connections`
230+
const url = `${baseUrl || ''}/api/connection`
231231
return useSWRMutation<Connection, Error>(
232232
url,
233233
async (url: string) => {
@@ -259,12 +259,11 @@ export function usePostSelect(baseUrl?: string) {
259259
)
260260
}
261261

262-
export function useDeleteConn(uuid: string, baseUrl?: string) {
263-
const url = `${baseUrl || ''}/api/conn/${uuid}`
264-
return useSWRMutation<boolean, Error>(
265-
url,
266-
async (url: string) => {
267-
const response = await fetch(url, { method: 'DELETE' })
262+
export function useDeleteConn(baseUrl?: string) {
263+
return useSWRMutation<boolean, Error, string, string>(
264+
'/api/connection',
265+
async (url: string, { arg: uuid }) => {
266+
const response = await fetch(`${baseUrl || ''}${url}/${uuid}`, { method: 'DELETE' })
268267
if (!response.ok) {
269268
const error: ApiError = await response.json()
270269
throw new Error(error.error)

ui/src/pages/connection/index.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Input } from '@/components/ui/input';
55
import { Card, CardHeader, CardTitle, CardContent } from '@/components/ui/card';
66
import { Badge } from '@/components/ui/badge';
77
import { X } from 'lucide-react';
8-
import { useConnectionsStream, ConnectionInfo, fetcher } from '@/api/v1';
8+
import { useConnectionsStream, ConnectionInfo, useDeleteConn, useDeleteConnections } from '@/api/v1';
99
import { useInstance } from '@/contexts/instance';
1010

1111
// Connection type for UI display
@@ -151,6 +151,8 @@ export const ConnectionsManager = () => {
151151
const [searchQuery, setSearchQuery] = useState('');
152152
const [sortOption, setSortOption] = useState<SortOption>('time');
153153
const [sortDirection, setSortDirection] = useState<SortDirection>('asc');
154+
const { trigger: triggerDeleteAll } = useDeleteConnections(currentInstance?.url);
155+
const { trigger: triggerDeleteConn } = useDeleteConn(currentInstance?.url);
154156

155157
const { formattedConnections, sortedConnections } = useMemo(() => {
156158
if (!state) {
@@ -210,7 +212,7 @@ export const ConnectionsManager = () => {
210212
if (!currentInstance?.url) return;
211213

212214
try {
213-
await fetcher(['/conn/:uuid', 'delete', undefined, { uuid: id }, currentInstance.url]);
215+
await triggerDeleteConn(id);
214216
// The WebSocket connection will update the state automatically
215217
} catch (error) {
216218
console.error('Failed to close connection:', error);
@@ -222,7 +224,7 @@ export const ConnectionsManager = () => {
222224
if (!currentInstance?.url) return;
223225

224226
try {
225-
await fetcher(['/connections', 'delete', undefined, currentInstance.url]);
227+
await triggerDeleteAll();
226228
// The WebSocket connection will update the state automatically
227229
} catch (error) {
228230
console.error('Failed to close all connections:', error);

0 commit comments

Comments
 (0)