fix: wire Proxmox remotes to backend commands
Some checks failed
Test / frontend-tests (pull_request) Successful in 1m46s
Test / frontend-typecheck (pull_request) Successful in 1m54s
PR Review Automation / review (pull_request) Successful in 4m7s
Test / rust-fmt-check (pull_request) Successful in 12m47s
Test / rust-clippy (pull_request) Successful in 14m47s
Test / rust-tests (pull_request) Failing after 15m47s
Some checks failed
Test / frontend-tests (pull_request) Successful in 1m46s
Test / frontend-typecheck (pull_request) Successful in 1m54s
PR Review Automation / review (pull_request) Successful in 4m7s
Test / rust-fmt-check (pull_request) Successful in 12m47s
Test / rust-clippy (pull_request) Successful in 14m47s
Test / rust-tests (pull_request) Failing after 15m47s
- Load remotes from database on page load - Add backend integration for add/edit/remove remote operations - Use ClusterInfo from backend instead of dummy data - Generate unique IDs for new remotes - Remove unused isLoading state
This commit is contained in:
parent
8a7a122b1c
commit
8b14f7faaa
@ -1,4 +1,4 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import { Button } from '@/components/ui/index';
|
import { Button } from '@/components/ui/index';
|
||||||
import { RefreshCw } from 'lucide-react';
|
import { RefreshCw } from 'lucide-react';
|
||||||
import { RemotesList } from '@/components/Proxmox';
|
import { RemotesList } from '@/components/Proxmox';
|
||||||
@ -6,6 +6,8 @@ import { AddRemoteForm } from '@/components/Proxmox';
|
|||||||
import { EditRemoteForm } from '@/components/Proxmox';
|
import { EditRemoteForm } from '@/components/Proxmox';
|
||||||
import { RemoveRemoteDialog } from '@/components/Proxmox';
|
import { RemoveRemoteDialog } from '@/components/Proxmox';
|
||||||
import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/index';
|
import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/index';
|
||||||
|
import { listProxmoxClusters, addProxmoxCluster, removeProxmoxCluster } from '@/lib/proxmoxClient';
|
||||||
|
import { ClusterType } from '@/lib/domain';
|
||||||
|
|
||||||
interface RemoteInfo {
|
interface RemoteInfo {
|
||||||
id: string;
|
id: string;
|
||||||
@ -22,30 +24,87 @@ export function ProxmoxRemotesPage() {
|
|||||||
const [editingRemote, setEditingRemote] = useState<RemoteInfo | null>(null);
|
const [editingRemote, setEditingRemote] = useState<RemoteInfo | null>(null);
|
||||||
const [removingRemote, setRemovingRemote] = useState<RemoteInfo | null>(null);
|
const [removingRemote, setRemovingRemote] = useState<RemoteInfo | null>(null);
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
const loadRemotes = async () => {
|
||||||
const handleAddRemote = (config: any) => {
|
try {
|
||||||
const newRemote: RemoteInfo = {
|
const clusters = await listProxmoxClusters();
|
||||||
id: String(remotes.length + 1),
|
const remotesList: RemoteInfo[] = clusters.map((c) => ({
|
||||||
name: String(config.name),
|
id: c.id,
|
||||||
url: String(config.url),
|
name: c.name,
|
||||||
username: String(config.username),
|
url: c.url,
|
||||||
type: config.type as 'pve' | 'pbs',
|
username: c.username,
|
||||||
status: 'connected',
|
type: c.clusterType === 've' ? 'pve' : 'pbs',
|
||||||
};
|
status: 'connected' as const,
|
||||||
setRemotes([...remotes, newRemote]);
|
}));
|
||||||
setShowAddDialog(false);
|
setRemotes(remotesList);
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Failed to load remotes:', err);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
void loadRemotes();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const generateId = (): string => {
|
||||||
|
return Date.now().toString(36) + Math.random().toString(36).substr(2);
|
||||||
};
|
};
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
const handleEditRemote = (config: any) => {
|
const handleAddRemote = async (config: any) => {
|
||||||
setRemotes(remotes.map(r => r.id === String(config.id) ? { ...r, ...config } as RemoteInfo : r));
|
try {
|
||||||
setEditingRemote(null);
|
const clusterType = config.type === 'pve' ? 've' : 'pbs';
|
||||||
|
const url = config.url.replace(/^https?:\/\//, '');
|
||||||
|
const port = config.type === 'pve' ? 8006 : 8007;
|
||||||
|
const id = config.id || generateId();
|
||||||
|
await addProxmoxCluster(
|
||||||
|
id,
|
||||||
|
config.name,
|
||||||
|
clusterType as ClusterType,
|
||||||
|
{ url, port },
|
||||||
|
config.username,
|
||||||
|
config.password || ''
|
||||||
|
);
|
||||||
|
await loadRemotes();
|
||||||
|
setShowAddDialog(false);
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Failed to add remote:', err);
|
||||||
|
alert('Failed to add remote: ' + String(err));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleRemoveRemote = () => {
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
const handleEditRemote = async (config: any) => {
|
||||||
|
try {
|
||||||
|
const clusterType = config.type === 'pve' ? 've' : 'pbs';
|
||||||
|
const url = config.url.replace(/^https?:\/\//, '');
|
||||||
|
const port = config.type === 'pve' ? 8006 : 8007;
|
||||||
|
await removeProxmoxCluster(config.id);
|
||||||
|
await addProxmoxCluster(
|
||||||
|
config.id,
|
||||||
|
config.name,
|
||||||
|
clusterType as ClusterType,
|
||||||
|
{ url, port },
|
||||||
|
config.username,
|
||||||
|
config.password || ''
|
||||||
|
);
|
||||||
|
await loadRemotes();
|
||||||
|
setEditingRemote(null);
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Failed to edit remote:', err);
|
||||||
|
alert('Failed to edit remote: ' + String(err));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleRemoveRemote = async () => {
|
||||||
if (removingRemote) {
|
if (removingRemote) {
|
||||||
setRemotes(remotes.filter(r => r.id !== removingRemote.id));
|
try {
|
||||||
setRemovingRemote(null);
|
await removeProxmoxCluster(removingRemote.id);
|
||||||
|
await loadRemotes();
|
||||||
|
setRemovingRemote(null);
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Failed to remove remote:', err);
|
||||||
|
alert('Failed to remove remote: ' + String(err));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user