Compare commits

...

4 Commits

Author SHA1 Message Date
c25d277abf save style 2025-06-10 13:17:49 +03:00
2715353d14 MUI 2025-06-10 09:10:27 +03:00
69ad5b657a Change title color 2025-06-10 09:02:02 +03:00
cdf7e40005 Create branch style 2025-06-10 03:15:14 +03:00
11 changed files with 1170 additions and 146 deletions

File diff suppressed because it is too large Load Diff

View File

@ -10,6 +10,11 @@
"preview": "vite preview" "preview": "vite preview"
}, },
"dependencies": { "dependencies": {
"@emotion/react": "^11.14.0",
"@emotion/styled": "^11.14.0",
"@mui/base": "^5.0.0-beta.70",
"@mui/icons-material": "^7.1.1",
"@mui/material": "^7.1.1",
"axios": "^1.9.0", "axios": "^1.9.0",
"react": "^19.1.0", "react": "^19.1.0",
"react-dom": "^19.1.0" "react-dom": "^19.1.0"

View File

@ -1,42 +1,17 @@
#root { .app-wrapper {
max-width: 1280px; display: flex;
margin: 0 auto; flex-direction: column;
align-items: center;
justify-content: center;
min-height: 100vh;
background-color: #121212;
padding: 2rem; padding: 2rem;
margin: 0 auto;
max-width: 100%;
}
.title {
color: white;
text-align: center; text-align: center;
} margin-bottom: 2rem;
.logo {
height: 6em;
padding: 1.5em;
will-change: filter;
transition: filter 300ms;
}
.logo:hover {
filter: drop-shadow(0 0 2em #646cffaa);
}
.logo.react:hover {
filter: drop-shadow(0 0 2em #61dafbaa);
}
@keyframes logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
@media (prefers-reduced-motion: no-preference) {
a:nth-of-type(2) .logo {
animation: logo-spin infinite 20s linear;
}
}
.card {
padding: 2em;
}
.read-the-docs {
color: #888;
} }

View File

@ -1,13 +1,16 @@
import './App.css';
import './style/global.css';
import BackupForm from './components/BackupForm'; import BackupForm from './components/BackupForm';
import RestoreForm from './components/RestoreForm'; import RestoreForm from './components/RestoreForm';
function App() { function App() {
return ( return (
<div style={{ padding: "2rem" }}> <div className="app-wrapper">
<h1>🚀 Snapix Dashboard</h1> <h1 className="title">🚀 Snapix Dashboard</h1>
<BackupForm /> <div className="form-sections">
<hr /> <BackupForm />
<RestoreForm /> <RestoreForm />
</div>
</div> </div>
); );
} }

View File

@ -1,10 +0,0 @@
import axios from 'axios';
const api = axios.create({
baseURL: 'http://localhost:8000', // שנה לכתובת האמיתית שלך
});
export const getNamespaces = () => api.get('/namespaces');
export const getPVCs = (namespace) => api.get(`/pvcs/${namespace}`);
export const createBackup = (payload) => api.post('/backup', payload);
export const restoreBackup = (payload) => api.post('/restore', payload);

View File

@ -1,67 +1,74 @@
import { useEffect, useState } from 'react'; import { useState, useEffect } from 'react';
import { getNamespaces, getPVCs, createBackup } from '../api/snapix'; import { getNamespaces, getPVCs, createBackup } from '../service';
import '../style/BackupForm.css';
import { Button, Input, Select, Option } from '@mui/base';
export default function BackupForm() { function BackupForm() {
const [namespaces, setNamespaces] = useState([]); const [namespaces, setNamespaces] = useState([]);
const [pvcs, setPvcs] = useState([]); const [pvcs, setPvcs] = useState([]);
const [selectedNs, setSelectedNs] = useState(''); const [namespace, setNamespace] = useState('');
const [selectedPvc, setSelectedPvc] = useState(''); const [pvc, setPvc] = useState('');
const [backupName, setBackupName] = useState(''); const [backupName, setBackupName] = useState('');
useEffect(() => { useEffect(() => {
getNamespaces().then(res => setNamespaces(res.data)); getNamespaces().then(setNamespaces);
}, []); }, []);
useEffect(() => { useEffect(() => {
if (selectedNs) { if (namespace) {
getPVCs(selectedNs).then(res => setPvcs(res.data)); getPVCs(namespace).then(setPvcs);
} else { } else {
setPvcs([]); setPvcs([]);
} }
}, [selectedNs]); }, [namespace]);
const handleSubmit = () => { const handleSubmit = async () => {
if (selectedNs && selectedPvc && backupName) { try {
createBackup({ await createBackup({ namespace, pvcName: pvc, backupName });
namespace: selectedNs, alert('✅ Backup created successfully!');
pvc_name: selectedPvc, } catch (error) {
backup_name: backupName, console.error(error);
}).then(() => { alert('❌ Backup failed');
alert("Backup started!");
setBackupName('');
});
} }
}; };
return ( return (
<div> <div className="form-container BackupForm">
<h2>📦 Backup PVC</h2> <h3>📦 Create Backup</h3>
<div className="form-group">
<label>Namespace</label>
<Select value={namespace} onChange={(e) => setNamespace(e.target.value)}>
<Option value="">-- Select Namespace --</Option>
{namespaces.map((ns) => (
<Option key={ns} value={ns}>{ns}</Option>
))}
</Select>
</div>
<label>Namespace:</label> <div className="form-group">
<select onChange={e => setSelectedNs(e.target.value)} value={selectedNs}> <label>PVC</label>
<option value="">-- Select Namespace --</option> <Select value={pvc} onChange={(e) => setPvc(e.target.value)} disabled={!namespace}>
{namespaces.map(ns => <option key={ns}>{ns}</option>)} <Option value="">-- Select PVC --</Option>
</select> {pvcs.map((p) => (
<Option key={p} value={p}>{p}</Option>
))}
</Select>
</div>
<label>PVC:</label> <div className="form-group">
<select <label>Backup Name</label>
onChange={e => setSelectedPvc(e.target.value)} <Input
value={selectedPvc} type="text"
disabled={!selectedNs} value={backupName}
> onChange={(e) => setBackupName(e.target.value)}
<option value="">-- Select PVC --</option> />
{pvcs.map(pvc => <option key={pvc}>{pvc}</option>)} </div>
</select>
<label>Backup Name:</label> <Button className="btn" onClick={handleSubmit} disabled={!namespace || !pvc || !backupName}>
<input Create Backup
type="text" </Button>
value={backupName}
onChange={e => setBackupName(e.target.value)}
placeholder="e.g. git-bkp"
/>
<button onClick={handleSubmit}>Create Backup</button>
</div> </div>
); );
} }
export default BackupForm;

View File

@ -1,49 +1,58 @@
import { useState } from 'react'; import { useState } from 'react';
import { restoreBackup } from '../api/snapix'; import { restoreBackup } from '../service';
import '../style/RestoreForm.css';
import { Button, Input } from '@mui/base';
export default function RestoreForm() { function RestoreForm() {
const [namespace, setNamespace] = useState('');
const [targetPVC, setTargetPVC] = useState('');
const [backupName, setBackupName] = useState(''); const [backupName, setBackupName] = useState('');
const [targetNs, setTargetNs] = useState('');
const [targetPvc, setTargetPvc] = useState('');
const handleRestore = () => { const handleSubmit = async () => {
if (backupName && targetNs && targetPvc) { try {
restoreBackup({ await restoreBackup({ namespace, targetPVC, backupName });
backup_name: backupName, alert('✅ Restore completed successfully!');
target_namespace: targetNs, } catch (error) {
target_pvc: targetPvc, console.error(error);
}).then(() => { alert('❌ Restore failed');
alert("Restore started!");
});
} }
}; };
return ( return (
<div> <div className="form-container RestoreForm">
<h2>🔁 Restore PVC</h2> <h3> Restore from Backup</h3>
<div className="form-group">
<label>Namespace</label>
<input
type="text"
value={namespace}
onChange={(e) => setNamespace(e.target.value)}
/>
</div>
<label>Backup Name:</label> <div className="form-group">
<input <label>Target PVC</label>
type="text" <input
value={backupName} type="text"
onChange={e => setBackupName(e.target.value)} value={targetPVC}
/> onChange={(e) => setTargetPVC(e.target.value)}
/>
</div>
<label>Target Namespace:</label> <div className="form-group">
<input <label>Backup Name</label>
type="text" <Input
value={targetNs} type="text"
onChange={e => setTargetNs(e.target.value)} value={backupName}
/> onChange={(e) => setBackupName(e.target.value)}
/>
</div>
<label>Target PVC:</label> <Button className="btn" onClick={handleSubmit} disabled={!namespace || !targetPVC || !backupName}>
<input Restore
type="text" </Button>
value={targetPvc}
onChange={e => setTargetPvc(e.target.value)}
/>
<button onClick={handleRestore}>Restore</button>
</div> </div>
); );
} }
export default RestoreForm;

33
frontend/src/service.js Normal file
View File

@ -0,0 +1,33 @@
const API_BASE = "http://localhost:8000";
export async function getNamespaces() {
const res = await fetch(`${API_BASE}/namespaces`);
if (!res.ok) throw new Error("Failed to fetch namespaces");
return await res.json();
}
export async function getPVCs(namespace) {
const res = await fetch(`${API_BASE}/pvcs/${namespace}`);
if (!res.ok) throw new Error("Failed to fetch PVCs");
return await res.json();
}
export async function createBackup({ namespace, pvcName, backupName }) {
const res = await fetch(`${API_BASE}/backup`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ namespace, pvc_name: pvcName, backup_name: backupName }),
});
if (!res.ok) throw new Error("Failed to create backup");
return await res.json();
}
export async function restoreBackup({ namespace, targetPVC, backupName }) {
const res = await fetch(`${API_BASE}/restore`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ namespace, target_pvc: targetPVC, backup_name: backupName }),
});
if (!res.ok) throw new Error("Failed to restore backup");
return await res.json();
}

View File

@ -0,0 +1,7 @@
.BackupForm {
background: #e3f2fd;
padding: 24px;
border-radius: 8px;
box-shadow: 0 2px 6px rgba(0,0,0,0.2);
color: rgb(0, 0, 0);
}

View File

@ -0,0 +1,7 @@
.RestoreForm {
background: #f1f8e9;
padding: 24px;
border-radius: 8px;
box-shadow: 0 2px 6px rgba(0,0,0,0.2);
color: rgb(0, 0, 0);
}

View File

@ -0,0 +1,58 @@
/* Global button style */
.btn {
padding: 10px;
font-weight: bold;
background: #1976d2;
color: white;
border: none;
border-radius: 6px;
cursor: pointer;
}
.btn:disabled {
background: #ccc;
cursor: not-allowed;
}
/* Inputs */
input, select {
padding: 8px;
font-size: 1rem;
border: 1px solid #ccc;
border-radius: 4px;
}
/* Shared spacing for forms */
.form-group {
margin-bottom: 16px;
display: flex;
flex-direction: column;
}
.form-group label {
margin-bottom: 4px;
font-weight: 500;
color: #333;
}
.form-sections {
width: 100%;
max-width: 480px;
display: flex;
flex-direction: column;
gap: 2rem;
margin: 0 auto;
}
.form-container {
display: flex;
flex-direction: column;
}
/* .input {
padding: 8px;
font-size: 1rem;
border: 1px solid #ccc;
border-radius: 4px;
background-color: transparent;
} */