forked from BornDeleuze/coop-cloud-front
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a2efaf279d | |||
| f85b453b55 | |||
| 21825ee009 |
@ -4,6 +4,7 @@ import { Apps } from './routes/Apps/Apps';
|
||||
import { AppDetail } from './routes/Apps/App';
|
||||
import { Servers } from './routes/Servers/Servers';
|
||||
import { Server } from './routes/Servers/Server';
|
||||
import { Recipes } from './routes/Recipes/Recipes';
|
||||
|
||||
function App() {
|
||||
return (
|
||||
@ -15,7 +16,8 @@ function App() {
|
||||
<Route path="/apps/:server/:appName" element={<AppDetail />} />
|
||||
<Route path="/servers" element={<Servers />} />
|
||||
<Route path="/servers/:serverName" element={<Server />} />
|
||||
|
||||
<Route path="/recipes" element={<Recipes />} />
|
||||
|
||||
{/* 404 catch-all */}
|
||||
<Route path="*" element={<Navigate to="/dashboard" replace />} />
|
||||
</Routes>
|
||||
|
||||
@ -11,6 +11,76 @@
|
||||
@extend .page-content;
|
||||
}
|
||||
|
||||
// Compact stats row
|
||||
.stats-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: $spacing-md;
|
||||
margin-bottom: $spacing-xl;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.stat-chip {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: $spacing-sm;
|
||||
padding: $spacing-sm $spacing-md;
|
||||
background: white;
|
||||
border: 2px solid $border-color;
|
||||
border-radius: $radius-md;
|
||||
cursor: pointer;
|
||||
transition: all $transition-base;
|
||||
font-size: $font-size-base;
|
||||
|
||||
&:hover:not(:disabled) {
|
||||
border-color: $primary;
|
||||
transform: translateY(-2px);
|
||||
box-shadow: $shadow-sm;
|
||||
}
|
||||
|
||||
&:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
&.active {
|
||||
border-color: $primary;
|
||||
background: rgba($primary, 0.05);
|
||||
}
|
||||
|
||||
.stat-label {
|
||||
color: $text-secondary;
|
||||
font-size: $font-size-sm;
|
||||
font-weight: $font-weight-medium;
|
||||
}
|
||||
|
||||
.stat-value {
|
||||
color: $text-primary;
|
||||
font-size: $font-size-xl;
|
||||
font-weight: $font-weight-bold;
|
||||
min-width: 24px;
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
|
||||
.reset-filters-btn {
|
||||
padding: $spacing-sm $spacing-md;
|
||||
background: $bg-secondary;
|
||||
border: 2px solid $border-color;
|
||||
border-radius: $radius-md;
|
||||
cursor: pointer;
|
||||
transition: all $transition-base;
|
||||
font-size: $font-size-sm;
|
||||
font-weight: $font-weight-medium;
|
||||
color: $text-secondary;
|
||||
|
||||
&:hover {
|
||||
background: white;
|
||||
color: $text-primary;
|
||||
border-color: $primary;
|
||||
}
|
||||
}
|
||||
|
||||
// Apps table specific styles
|
||||
.apps-table-container {
|
||||
@include card;
|
||||
@ -114,21 +184,28 @@
|
||||
.action-btn {
|
||||
background: none;
|
||||
border: 1px solid $border-color;
|
||||
padding: $spacing-xs $spacing-sm;
|
||||
padding: $spacing-xs $spacing-md;
|
||||
border-radius: $radius-sm;
|
||||
cursor: pointer;
|
||||
font-size: $font-size-base;
|
||||
font-size: $font-size-sm;
|
||||
color: $text-primary;
|
||||
font-weight: $font-weight-medium;
|
||||
transition: all $transition-base;
|
||||
|
||||
&:hover {
|
||||
background-color: $bg-tertiary;
|
||||
transform: scale(1.1);
|
||||
background-color: $primary;
|
||||
color: white;
|
||||
border-color: $primary;
|
||||
}
|
||||
|
||||
&.upgrade {
|
||||
border-color: $warning;
|
||||
color: $warning;
|
||||
|
||||
&:hover {
|
||||
background-color: $warning;
|
||||
color: white;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -14,7 +14,8 @@ export const Apps: React.FC = () => {
|
||||
const [filterServer, setFilterServer] = useState<string>('all');
|
||||
const [filterStatus, setFilterStatus] = useState<string>('all');
|
||||
const [showUpgradesOnly, setShowUpgradesOnly] = useState(false);
|
||||
|
||||
const [showChaosOnly, setShowChaosOnly] = useState(false);
|
||||
|
||||
const isMockMode = import.meta.env.VITE_MOCK_AUTH === 'true';
|
||||
|
||||
useEffect(() => {
|
||||
@ -86,6 +87,28 @@ export const Apps: React.FC = () => {
|
||||
return { total, needsUpgrade, chaosApps, totalServers };
|
||||
}, [allApps, servers]);
|
||||
|
||||
const resetFilters = () => {
|
||||
setSearchTerm('');
|
||||
setFilterServer('all');
|
||||
setShowChaosOnly(false);
|
||||
setShowUpgradesOnly(false);
|
||||
};
|
||||
|
||||
const toggleUpgrades = () => setShowUpgradesOnly(prev => !prev);
|
||||
const toggleChaos = () => setShowChaosOnly(prev => !prev);
|
||||
|
||||
// Show only apps that need upgrades
|
||||
const filterByUpgrades = () => {
|
||||
setShowUpgradesOnly(true);
|
||||
setFilterStatus('all');
|
||||
};
|
||||
|
||||
// Show only chaos apps
|
||||
const filterByChaos = () => {
|
||||
setFilterStatus('chaos');
|
||||
setShowUpgradesOnly(false);
|
||||
};
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div className="apps-page">
|
||||
@ -117,32 +140,46 @@ export const Apps: React.FC = () => {
|
||||
<p className="subtitle">{stats.total} apps across {stats.totalServers} servers</p>
|
||||
</div>
|
||||
|
||||
{/* Stats Overview */}
|
||||
<div className="stats-grid">
|
||||
<div className="stat-card">
|
||||
<div className="stat-info">
|
||||
<p className="stat-number">{stats.total}</p>
|
||||
<p className="stat-label">Total Apps</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="stat-card upgrade">
|
||||
<div className="stat-info">
|
||||
<p className="stat-number">{stats.needsUpgrade}</p>
|
||||
<p className="stat-label">Upgrades Available</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="stat-card chaos">
|
||||
<div className="stat-info">
|
||||
<p className="stat-number">{stats.chaosApps}</p>
|
||||
<p className="stat-label">Chaos Mode</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="stat-card">
|
||||
<div className="stat-info">
|
||||
<p className="stat-number">{stats.totalServers}</p>
|
||||
<p className="stat-label">Servers</p>
|
||||
</div>
|
||||
</div>
|
||||
{/* Compact Stats Overview */}
|
||||
<div className="stats-row">
|
||||
<button
|
||||
className="stat-chip"
|
||||
onClick={resetFilters}
|
||||
title="Click to show all apps"
|
||||
>
|
||||
<span className="stat-label">Apps</span>
|
||||
<span className="stat-value">{stats.total}</span>
|
||||
</button>
|
||||
|
||||
<button
|
||||
className="stat-chip"
|
||||
onClick={() => navigate('/servers')}
|
||||
title="View servers"
|
||||
>
|
||||
<span className="stat-label">Servers</span>
|
||||
<span className="stat-value">{stats.totalServers}</span>
|
||||
</button>
|
||||
|
||||
<button
|
||||
className={`stat-chip ${showUpgradesOnly ? 'active' : ''}`}
|
||||
onClick={toggleUpgrades}
|
||||
title="Click to toggle apps with upgrades available"
|
||||
disabled={stats.needsUpgrade === 0}
|
||||
>
|
||||
<span className="stat-label">Upgrades</span>
|
||||
<span className="stat-value">{stats.needsUpgrade}</span>
|
||||
</button>
|
||||
|
||||
<button
|
||||
className={`stat-chip ${showChaosOnly ? 'active' : ''}`}
|
||||
onClick={toggleChaos}
|
||||
title="Click to toggle chaos mode apps"
|
||||
disabled={stats.chaosApps === 0}
|
||||
>
|
||||
<span className="stat-label">Chaos</span>
|
||||
<span className="stat-value">{stats.chaosApps}</span>
|
||||
</button>
|
||||
|
||||
</div>
|
||||
|
||||
{/* Filters */}
|
||||
@ -161,21 +198,6 @@ export const Apps: React.FC = () => {
|
||||
<option key={server} value={server}>{server}</option>
|
||||
))}
|
||||
</select>
|
||||
|
||||
<select value={filterStatus} onChange={(e) => setFilterStatus(e.target.value)}>
|
||||
<option value="all">All Status</option>
|
||||
<option value="stable">Stable</option>
|
||||
<option value="chaos">Chaos Mode</option>
|
||||
</select>
|
||||
|
||||
<label className="checkbox-filter">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={showUpgradesOnly}
|
||||
onChange={(e) => setShowUpgradesOnly(e.target.checked)}
|
||||
/>
|
||||
<span>Show only apps with upgrades</span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
{/* Apps Table */}
|
||||
|
||||
0
src/routes/Recipes/Recipe.scss
Normal file
0
src/routes/Recipes/Recipe.scss
Normal file
0
src/routes/Recipes/Recipe.tsx
Normal file
0
src/routes/Recipes/Recipe.tsx
Normal file
0
src/routes/Recipes/RecipeForm.scss
Normal file
0
src/routes/Recipes/RecipeForm.scss
Normal file
112
src/routes/Recipes/RecipeForm.tsx
Normal file
112
src/routes/Recipes/RecipeForm.tsx
Normal file
@ -0,0 +1,112 @@
|
||||
import { useState, useEffect } from "react";
|
||||
import { apiService } from '../../services/api';
|
||||
import type { AbraServer } from '../../types';
|
||||
|
||||
|
||||
|
||||
function RecipeForm({ recipe, onClose }) {
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [servers, setServers] = useState<AbraServer[]>([]);
|
||||
const [selectedServer, setSelectedServer] = useState(""); // ❌ only one value
|
||||
const [chaos, setChaos] = useState(false);
|
||||
const [secrets, setSecrets] = useState(false);
|
||||
const [error, setError] = useState('');
|
||||
|
||||
useEffect(() => {
|
||||
const fetchData = async () => {
|
||||
try {
|
||||
const [serversData] = await Promise.all([
|
||||
apiService.getServers(),
|
||||
]);
|
||||
|
||||
setServers(serversData);
|
||||
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : 'Failed to load servers');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
fetchData();
|
||||
});
|
||||
const [formData, setFormData] = useState({
|
||||
domain: "",
|
||||
chaos: false,
|
||||
secrets: true,
|
||||
});
|
||||
|
||||
const handleChange = (e) => {
|
||||
setFormData({
|
||||
...formData,
|
||||
[e.target.name]: e.target.value,
|
||||
});
|
||||
};
|
||||
|
||||
const handleSubmit = (e) => {
|
||||
e.preventDefault();
|
||||
console.log("Submitting:", formData);
|
||||
onClose();
|
||||
};
|
||||
|
||||
return (
|
||||
<form onSubmit={handleSubmit}>
|
||||
<h2>{recipe.name}</h2>
|
||||
{ loading ? (<p> Loading servers...</p>
|
||||
) : (
|
||||
<div>
|
||||
<label>
|
||||
Choose a server to deploy to:
|
||||
<select
|
||||
value={selectedServer}
|
||||
onChange={(e) => setSelectedServer(e.target.value)}
|
||||
>
|
||||
<option value="">None</option>
|
||||
{servers.map((server) => (
|
||||
<option key={server.name} value={server.name}>
|
||||
{server.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
)}
|
||||
<div>
|
||||
<label>
|
||||
Domain:
|
||||
<input
|
||||
name="Domain"
|
||||
value={formData.name}
|
||||
onChange={handleChange}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
<div>
|
||||
<label>
|
||||
Chaos Mode Enabled:
|
||||
<input
|
||||
type="checkbox"
|
||||
name="chaos"
|
||||
onChange={handleChange}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label>
|
||||
Autogenerate Secrets:
|
||||
<input
|
||||
type="checkbox"
|
||||
name="secrets"
|
||||
onChange={handleChange}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<button type="submit">Submit</button>
|
||||
<button type="button" onClick={onClose}>Cancel</button>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
|
||||
export default RecipeForm;
|
||||
177
src/routes/Recipes/Recipes.scss
Normal file
177
src/routes/Recipes/Recipes.scss
Normal file
@ -0,0 +1,177 @@
|
||||
@use '../../assets/scss/variables' as *;
|
||||
@use '../../assets/scss/mixins' as *;
|
||||
@use '../../assets/scss/global' as *;
|
||||
|
||||
// Extend global page wrapper
|
||||
.recipes-page {
|
||||
@extend .page-wrapper;
|
||||
}
|
||||
|
||||
.recipes-content {
|
||||
@extend .page-content;
|
||||
}
|
||||
|
||||
// Servers grid
|
||||
.recipes-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
|
||||
gap: $spacing-xl;
|
||||
margin-bottom: $spacing-xl;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
// Server card
|
||||
.recipe-card {
|
||||
@include card;
|
||||
display: grid;
|
||||
grid-template-rows: 1fr 2fr auto 0.9fr;
|
||||
transition: transform $transition-base, box-shadow $transition-base;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
|
||||
&:hover {
|
||||
transform: translateY(-4px);
|
||||
box-shadow: $shadow-xl;
|
||||
}
|
||||
|
||||
.recipe-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: flex-start;
|
||||
margin-bottom: $spacing-lg;
|
||||
padding-bottom: $spacing-md;
|
||||
border-bottom: 2px solid $bg-secondary;
|
||||
|
||||
.recipe-title {
|
||||
h3 {
|
||||
margin: 0 0 $spacing-xs;
|
||||
font-size: $font-size-xl;
|
||||
color: $text-primary;
|
||||
font-weight: $font-weight-bold;
|
||||
}
|
||||
|
||||
.recipe-host {
|
||||
font-size: $font-size-sm;
|
||||
color: $text-muted;
|
||||
font-family: monospace;
|
||||
}
|
||||
}
|
||||
img {
|
||||
width: clamp(20px, 3vw, 32px);
|
||||
height: clamp(20px, 3vw, 32px);
|
||||
object-fit: contain;
|
||||
}
|
||||
}
|
||||
.card-tags {
|
||||
display: flex;
|
||||
gap: 6px;
|
||||
margin-top: $spacing-sm;
|
||||
height: $spacing-md;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.tag-category {
|
||||
font-size: 12px;
|
||||
padding: 2px 8px;
|
||||
border-radius: 5px;
|
||||
color: rgb(255, 255, 255);
|
||||
font-weight: 700;
|
||||
background-color: rgb(111, 128, 255);
|
||||
|
||||
}
|
||||
.tag-feature {
|
||||
font-size: 12px;
|
||||
padding: 2px 8px;
|
||||
border-radius: 5px;
|
||||
color: rgb(255, 255, 255);
|
||||
font-weight: 700;
|
||||
background-color: rgb(22, 180, 22);
|
||||
|
||||
}
|
||||
.recipe-stats {
|
||||
flex-grow: 1;
|
||||
flex: 1;
|
||||
margin-bottom: $spacing-lg;
|
||||
|
||||
.stat-row {
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 4;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
.recipe-actions {
|
||||
display: flex;
|
||||
gap: $spacing-sm;
|
||||
.action-btn {
|
||||
flex: 1;
|
||||
padding: $spacing-sm $spacing-md;
|
||||
border: 2px solid $border-color;
|
||||
background: none;
|
||||
color: $text-primary;
|
||||
border-radius: $radius-md;
|
||||
font-size: $font-size-sm;
|
||||
font-weight: $font-weight-medium;
|
||||
cursor: pointer;
|
||||
transition: all $transition-base;
|
||||
|
||||
&:hover {
|
||||
background-color: rgba($primary, 0.1);
|
||||
border-color: $primary;
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
&.primary {
|
||||
background-color: $primary;
|
||||
color: white;
|
||||
border-color: $primary;
|
||||
|
||||
&:hover {
|
||||
background-color: $primary-light;
|
||||
border-color: $primary-light;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.recipe-alert {
|
||||
background-color: rgba($warning, 0.1);
|
||||
border-left: 4px solid $warning;
|
||||
padding: $spacing-sm $spacing-md;
|
||||
margin: 0 (-$spacing-xl) (-$spacing-xl);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: $spacing-sm;
|
||||
|
||||
.alert-icon {
|
||||
font-size: $font-size-lg;
|
||||
color: $warning;
|
||||
}
|
||||
|
||||
.alert-text {
|
||||
font-size: $font-size-sm;
|
||||
color: $text-primary;
|
||||
font-weight: $font-weight-medium;
|
||||
}
|
||||
}
|
||||
}
|
||||
.modal-overlay {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
background: rgba(0, 0, 0, 0.4);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.modal {
|
||||
background: white;
|
||||
padding: 24px;
|
||||
border-radius: 8px;
|
||||
width: min(90%, 500px);
|
||||
}
|
||||
192
src/routes/Recipes/Recipes.tsx
Normal file
192
src/routes/Recipes/Recipes.tsx
Normal file
@ -0,0 +1,192 @@
|
||||
import React, { useEffect, useMemo, useState } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { Header } from '../../components/Header/Header';
|
||||
import { apiService } from '../../services/api';
|
||||
import type { AbraApp, AppWithServer, AbraRecipe } from '../../types';
|
||||
import RecipeForm from './RecipeForm.tsx'
|
||||
import './Recipes.scss';
|
||||
|
||||
export const Recipes: React.FC = () => {
|
||||
const navigate = useNavigate();
|
||||
const [recipesData, setRecipesData] = useState<AbraRecipe[] | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState('');
|
||||
const [searchTerm, setSearchTerm] = useState('');
|
||||
const [filterServer, setFilterServer] = useState<string>('all');
|
||||
const [filterStatus, setFilterStatus] = useState<string>('all');
|
||||
const [selectedRecipe, setSelectedRecipe] = useState(null);
|
||||
const [showForm, setShowForm] = useState(false);
|
||||
|
||||
|
||||
|
||||
const isMockMode = import.meta.env.VITE_MOCK_AUTH === 'true';
|
||||
|
||||
useEffect(() => {
|
||||
const fetchData = async () => {
|
||||
try {
|
||||
if (isMockMode) {
|
||||
const { mockApiService } = await import('../../services/mockApi');
|
||||
const data = await mockApiService.getRecipes();
|
||||
console.log(data)
|
||||
setRecipesData(data);
|
||||
} else {
|
||||
const data = await apiService.getRecipes();
|
||||
setRecipesData(data);
|
||||
}
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : 'Failed to load apps');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
fetchData();
|
||||
}, [isMockMode]);
|
||||
|
||||
// Flatten and enrich apps data
|
||||
const allRecipes: AbraRecipe[] = useMemo(() => {
|
||||
if (!recipesData) return [];
|
||||
|
||||
return recipesData;
|
||||
}, [recipesData]);
|
||||
|
||||
|
||||
// Filter apps
|
||||
const filteredRecipes = useMemo(() => {
|
||||
return allRecipes.filter(recipe => {
|
||||
const matchesSearch =
|
||||
recipe.name.toLowerCase().includes(searchTerm.toLowerCase());
|
||||
|
||||
return matchesSearch;
|
||||
});
|
||||
}, [allRecipes, searchTerm, filterServer, filterStatus]);
|
||||
|
||||
const stats = useMemo(() => {
|
||||
const total = allRecipes.length;
|
||||
|
||||
return { total };
|
||||
}, [allRecipes]);
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div className="apps-page">
|
||||
<Header />
|
||||
<main className="recipes-content">
|
||||
<div className="loading">Loading applications...</div>
|
||||
</main>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
<div className="recipes-page">
|
||||
<Header />
|
||||
<main className="recipes-content">
|
||||
<div className="error">Error: {error}</div>
|
||||
</main>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="recipes-page">
|
||||
<Header />
|
||||
<main className="recipes-content">
|
||||
<div className="page-header">
|
||||
<h1>Applications</h1>
|
||||
<p className="subtitle">{stats.total} recipes</p>
|
||||
</div>
|
||||
|
||||
{/* Stats Overview */}
|
||||
<div className="stats-grid">
|
||||
<div className="stat-card">
|
||||
<div className="stat-info">
|
||||
<p className="stat-number">{stats.total}</p>
|
||||
<p className="stat-label">Total Recipes</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Filters */}
|
||||
<div className="filters">
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Search apps by name, recipe, or domain..."
|
||||
value={searchTerm}
|
||||
onChange={(e) => setSearchTerm(e.target.value)}
|
||||
className="search-input"
|
||||
/>
|
||||
|
||||
<select value={filterStatus} onChange={(e) => setFilterStatus(e.target.value)}>
|
||||
<option value="all">All Status</option>
|
||||
<option value="stable">Stable</option>
|
||||
<option value="chaos">Chaos Mode</option>
|
||||
</select>
|
||||
|
||||
</div>
|
||||
|
||||
{/* Server Cards */}
|
||||
<div className="recipes-grid">
|
||||
{filteredRecipes.length === 0 ? (
|
||||
<div className="no-results">No recipes found matching your search</div>
|
||||
) : (
|
||||
filteredRecipes.map((recipe) => (
|
||||
<div
|
||||
key={recipe.name}
|
||||
className="recipe-card"
|
||||
style={{ cursor: 'pointer' }}
|
||||
>
|
||||
<div className="recipe-header">
|
||||
<div className="recipe-title">
|
||||
<h3>{recipe.name}</h3>
|
||||
</div>
|
||||
<div>
|
||||
{recipe.icon.length > 0 ? <img src={`${recipe.icon}`} /> : null }
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="recipe-stats">
|
||||
<div className="stat-row">
|
||||
<span className="stat-value">{recipe.description}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="recipe-actions">
|
||||
<button
|
||||
className="action-btn"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
console.log('clicked');
|
||||
setSelectedRecipe(recipe);
|
||||
console.log('selectedRecipe:', selectedRecipe);
|
||||
}}
|
||||
>
|
||||
Add Recipe
|
||||
</button>
|
||||
</div>
|
||||
<div className="card-tags">
|
||||
{recipe.features.backups.toLowerCase().includes("yes") ? <span className="tag-feature"> Backups </span> : null}
|
||||
{recipe.features.healthcheck.toLowerCase().includes("yes") ? <span className="tag-feature"> Healthcheck </span> : null}
|
||||
{recipe.category.length > 0 ? <span className="tag-category"> {recipe.category} </span> : null}
|
||||
</div>
|
||||
</div>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
{selectedRecipe && (
|
||||
<div className="modal-overlay" onClick={() => setSelectedRecipe(null)}>
|
||||
<div className="modal" onClick={(e) => e.stopPropagation()}>
|
||||
{}
|
||||
<RecipeForm recipe={selectedRecipe} onClose={() => setSelectedRecipe(null)} />
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="results-count">
|
||||
Showing {filteredRecipes.length} of {allRecipes.length} apps
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@ -175,7 +175,7 @@ export const Server: React.FC = () => {
|
||||
<span className="host-badge">{server.host}</span>
|
||||
{server.upgradeCount > 0 && (
|
||||
<span className="upgrade-badge">
|
||||
⬆️ {server.upgradeCount} upgrade{server.upgradeCount !== 1 ? 's' : ''}
|
||||
{server.upgradeCount} upgrade{server.upgradeCount !== 1 ? 's' : ''}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
@ -187,14 +187,14 @@ export const Server: React.FC = () => {
|
||||
onClick={() => handleAction('refresh')}
|
||||
disabled={!!actionLoading}
|
||||
>
|
||||
{actionLoading === 'refresh' ? 'Refreshing...' : '🔄 Refresh'}
|
||||
{actionLoading === 'refresh' ? 'Refreshing...' : 'Refresh'}
|
||||
</button>
|
||||
<button
|
||||
className="action-btn primary"
|
||||
onClick={() => handleAction('deploy-all')}
|
||||
disabled={!!actionLoading}
|
||||
>
|
||||
{actionLoading === 'deploy-all' ? 'Deploying...' : '🚀 Deploy All'}
|
||||
{actionLoading === 'deploy-all' ? 'Deploying...' : 'Deploy All'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -20,59 +20,46 @@ export const Servers: React.FC = () => {
|
||||
const [error, setError] = useState('');
|
||||
const [searchTerm, setSearchTerm] = useState('');
|
||||
const [sortBy, setSortBy] = useState<'name' | 'apps' | 'upgrades'>('name');
|
||||
const [showUpgradesOnly, setShowUpgradesOnly] = useState(false);
|
||||
|
||||
const isMockMode = import.meta.env.VITE_MOCK_AUTH === 'true';
|
||||
|
||||
useEffect(() => {
|
||||
const fetchData = async () => {
|
||||
try {
|
||||
let serversData, appsData;
|
||||
|
||||
if (isMockMode) {
|
||||
const { mockApiService } = await import('../../services/mockApi');
|
||||
const [serversData, appsData] = await Promise.all([
|
||||
[serversData, appsData] = await Promise.all([
|
||||
mockApiService.getServers(),
|
||||
mockApiService.getAppsGrouped(),
|
||||
]);
|
||||
|
||||
// Enrich servers with stats from apps data
|
||||
const enrichedServers = serversData.map(server => {
|
||||
const serverStats = appsData[server.name];
|
||||
const chaosCount = serverStats?.apps.filter(app => app.chaos === 'true').length || 0;
|
||||
|
||||
return {
|
||||
...server,
|
||||
appCount: serverStats?.appCount || 0,
|
||||
versionCount: serverStats?.versionCount || 0,
|
||||
latestCount: serverStats?.latestCount || 0,
|
||||
upgradeCount: serverStats?.upgradeCount || 0,
|
||||
chaosCount,
|
||||
};
|
||||
});
|
||||
|
||||
setServers(enrichedServers);
|
||||
} else {
|
||||
const [serversData, appsData] = await Promise.all([
|
||||
[serversData, appsData] = await Promise.all([
|
||||
apiService.getServers(),
|
||||
apiService.getAppsGrouped(),
|
||||
]);
|
||||
|
||||
// Enrich servers with stats from apps data
|
||||
const enrichedServers = serversData.map(server => {
|
||||
const serverStats = appsData[server.name];
|
||||
const chaosCount = serverStats?.apps.filter(app => app.chaos === 'true').length || 0;
|
||||
|
||||
return {
|
||||
...server,
|
||||
appCount: serverStats?.appCount || 0,
|
||||
versionCount: serverStats?.versionCount || 0,
|
||||
latestCount: serverStats?.latestCount || 0,
|
||||
upgradeCount: serverStats?.upgradeCount || 0,
|
||||
chaosCount,
|
||||
};
|
||||
});
|
||||
|
||||
setServers(enrichedServers);
|
||||
}
|
||||
|
||||
// Enrich servers with stats from apps data
|
||||
const enrichedServers = serversData.map(server => {
|
||||
const serverStats = appsData[server.name];
|
||||
const chaosCount = serverStats?.apps.filter(app => app.chaos === 'true').length || 0;
|
||||
|
||||
return {
|
||||
...server,
|
||||
appCount: serverStats?.appCount || 0,
|
||||
versionCount: serverStats?.versionCount || 0,
|
||||
latestCount: serverStats?.latestCount || 0,
|
||||
upgradeCount: serverStats?.upgradeCount || 0,
|
||||
chaosCount,
|
||||
};
|
||||
});
|
||||
|
||||
setServers(enrichedServers);
|
||||
} catch (err) {
|
||||
console.error('Error loading servers:', err);
|
||||
setError(err instanceof Error ? err.message : 'Failed to load servers');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
@ -94,26 +81,32 @@ export const Servers: React.FC = () => {
|
||||
|
||||
// Filter and sort servers
|
||||
const filteredServers = useMemo(() => {
|
||||
const filtered = servers.filter(server =>
|
||||
const filtered = servers.filter(server => {
|
||||
const matchesSearch =
|
||||
server.name.toLowerCase().includes(searchTerm.toLowerCase()) ||
|
||||
server.host.toLowerCase().includes(searchTerm.toLowerCase())
|
||||
);
|
||||
server.host.toLowerCase().includes(searchTerm.toLowerCase());
|
||||
const matchesUpgrades = !showUpgradesOnly || server.upgradeCount > 0;
|
||||
return matchesSearch && matchesUpgrades;
|
||||
});
|
||||
|
||||
// Sort
|
||||
filtered.sort((a, b) => {
|
||||
switch (sortBy) {
|
||||
case 'apps':
|
||||
return b.appCount - a.appCount;
|
||||
case 'upgrades':
|
||||
return b.upgradeCount - a.upgradeCount;
|
||||
case 'name':
|
||||
default:
|
||||
return a.name.localeCompare(b.name);
|
||||
}
|
||||
});
|
||||
filtered.sort((a, b) => {
|
||||
switch (sortBy) {
|
||||
case 'apps':
|
||||
return b.appCount - a.appCount;
|
||||
case 'name':
|
||||
default:
|
||||
return a.name.localeCompare(b.name);
|
||||
}
|
||||
});
|
||||
|
||||
return filtered;
|
||||
}, [servers, searchTerm, sortBy]);
|
||||
return filtered;
|
||||
}, [servers, searchTerm, sortBy, showUpgradesOnly]);
|
||||
|
||||
const resetFilters = () => {
|
||||
setSearchTerm('');
|
||||
setSortBy('name');
|
||||
setShowUpgradesOnly(false);
|
||||
};
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
@ -146,36 +139,53 @@ export const Servers: React.FC = () => {
|
||||
<p className="subtitle">Managing {stats.totalServers} servers with {stats.totalApps} applications</p>
|
||||
</div>
|
||||
|
||||
{/* Stats Overview */}
|
||||
<div className="stats-grid">
|
||||
<div className="stat-card">
|
||||
<div className="stat-icon"></div>
|
||||
<div className="stat-info">
|
||||
<p className="stat-number">{stats.totalServers}</p>
|
||||
<p className="stat-label">Total Servers</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="stat-card">
|
||||
<div className="stat-icon"></div>
|
||||
<div className="stat-info">
|
||||
<p className="stat-number">{stats.totalApps}</p>
|
||||
<p className="stat-label">Total Apps</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="stat-card upgrade">
|
||||
<div className="stat-icon"></div>
|
||||
<div className="stat-info">
|
||||
<p className="stat-number">{stats.totalUpgrades}</p>
|
||||
<p className="stat-label">Apps Need Upgrade</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="stat-card chaos">
|
||||
<div className="stat-icon"></div>
|
||||
<div className="stat-info">
|
||||
<p className="stat-number">{stats.totalChaos}</p>
|
||||
<p className="stat-label">Chaos Apps</p>
|
||||
</div>
|
||||
</div>
|
||||
{/* Compact Stats Row */}
|
||||
<div className="stats-row">
|
||||
<button
|
||||
className="stat-chip"
|
||||
onClick={resetFilters}
|
||||
title="Click to reset filters"
|
||||
>
|
||||
<span className="stat-label">Servers</span>
|
||||
<span className="stat-value">{stats.totalServers}</span>
|
||||
</button>
|
||||
|
||||
<button
|
||||
className="stat-chip"
|
||||
onClick={() => navigate('/apps')}
|
||||
title="View all apps"
|
||||
>
|
||||
<span className="stat-label">Apps</span>
|
||||
<span className="stat-value">{stats.totalApps}</span>
|
||||
</button>
|
||||
|
||||
<button
|
||||
className={`stat-chip ${showUpgradesOnly ? 'active' : ''}`}
|
||||
onClick={() => setShowUpgradesOnly(prev => !prev)}
|
||||
title="Click to filter by servers with upgrades"
|
||||
disabled={stats.totalUpgrades === 0}
|
||||
>
|
||||
<span className="stat-label">Upgrades</span>
|
||||
<span className="stat-value">{stats.totalUpgrades}</span>
|
||||
</button>
|
||||
|
||||
<button
|
||||
className={`stat-chip ${sortBy === 'apps' ? 'active' : ''}`}
|
||||
onClick={() => setSortBy(sortBy === 'apps' ? 'name' : 'apps')}
|
||||
title="Click to sort by app count"
|
||||
>
|
||||
<span className="stat-label">Chaos</span>
|
||||
<span className="stat-value">{stats.totalChaos}</span>
|
||||
</button>
|
||||
|
||||
{(searchTerm || sortBy !== 'name' || showUpgradesOnly) && (
|
||||
<button
|
||||
className="reset-filters-btn"
|
||||
onClick={resetFilters}
|
||||
>
|
||||
Clear filters
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Filters */}
|
||||
@ -187,12 +197,6 @@ export const Servers: React.FC = () => {
|
||||
onChange={(e) => setSearchTerm(e.target.value)}
|
||||
className="search-input"
|
||||
/>
|
||||
|
||||
<select value={sortBy} onChange={(e) => setSortBy(e.target.value as any)}>
|
||||
<option value="name">Sort by Name</option>
|
||||
<option value="apps">Sort by App Count</option>
|
||||
<option value="upgrades">Sort by Upgrades</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
{/* Server Cards */}
|
||||
@ -232,13 +236,17 @@ export const Servers: React.FC = () => {
|
||||
</div>
|
||||
{server.upgradeCount > 0 && (
|
||||
<div className="stat-row highlight">
|
||||
<span className="stat-label">Need Upgrade</span>
|
||||
<span className="stat-label">
|
||||
Need Upgrade
|
||||
</span>
|
||||
<span className="stat-value">{server.upgradeCount}</span>
|
||||
</div>
|
||||
)}
|
||||
{server.chaosCount > 0 && (
|
||||
<div className="stat-row chaos-row">
|
||||
<span className="stat-label">Chaos Mode</span>
|
||||
<span className="stat-label">
|
||||
Chaos Mode
|
||||
</span>
|
||||
<span className="stat-value">{server.chaosCount}</span>
|
||||
</div>
|
||||
)}
|
||||
@ -267,7 +275,6 @@ export const Servers: React.FC = () => {
|
||||
|
||||
{server.upgradeCount > 0 && (
|
||||
<div className="server-alert">
|
||||
<span className="alert-icon">⚠️</span>
|
||||
<span className="alert-text">
|
||||
{server.upgradeCount} app{server.upgradeCount > 1 ? 's' : ''} can be upgraded
|
||||
</span>
|
||||
@ -284,4 +291,4 @@ export const Servers: React.FC = () => {
|
||||
</main>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import type { AbraServer, ServerAppsResponse } from '../types';
|
||||
import type { AbraServer, AbraRecipe, ServerAppsResponse } from '../types';
|
||||
|
||||
// Log entry type
|
||||
export type LogEntry = {
|
||||
@ -130,6 +130,11 @@ class ApiService {
|
||||
logs.forEach(log => onLog(log));
|
||||
}
|
||||
}
|
||||
// recipe catalog imports
|
||||
async getRecipes(): Promise<AbraRecipe[]> {
|
||||
return this.request<AbraRecipe[]>('/abra/catalogue');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export const apiService = new ApiService();
|
||||
1726
src/services/mock-catalogue.json
Normal file
1726
src/services/mock-catalogue.json
Normal file
File diff suppressed because it is too large
Load Diff
@ -119,7 +119,7 @@
|
||||
"logs": [
|
||||
{
|
||||
"type": "info",
|
||||
"text": "⬆️ Upgrading {appName} to {version}..."
|
||||
"text": "Upgrading {appName} to {version}..."
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
@ -287,7 +287,7 @@
|
||||
"logs": [
|
||||
{
|
||||
"type": "info",
|
||||
"text": "⬆️ Upgrading all apps on {serverName}..."
|
||||
"text": "Upgrading all apps on {serverName}..."
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
import type { AbraServer, ServerAppsResponse } from '../types';
|
||||
import type { AbraServer, AbraRecipe, ServerAppsResponse } from '../types';
|
||||
import appsData from './mock-apps.json';
|
||||
import serversData from './mock-servers.json';
|
||||
import logsData from './mock-logs.json';
|
||||
import catalogue from './mock-catalogue.json';
|
||||
|
||||
|
||||
// Log entry type
|
||||
export type LogEntry = {
|
||||
@ -135,4 +137,9 @@ export const mockApiService = {
|
||||
onLog?.(log);
|
||||
}
|
||||
},
|
||||
// recipe catalog imports
|
||||
async getRecipes(): Promise<AbraRecipe[]> {
|
||||
await delay(300);
|
||||
return catalogue as AbraRecipe[];
|
||||
}
|
||||
};
|
||||
@ -36,4 +36,36 @@ export interface AppWithServer extends AbraApp {
|
||||
appCount: number;
|
||||
upgradeCount: number;
|
||||
};
|
||||
}
|
||||
export interface Image {
|
||||
image: string;
|
||||
rating: string
|
||||
source: string
|
||||
url: string
|
||||
}
|
||||
type RecipeVersions = Record<string, Record<string, ServiceMeta>>[];
|
||||
export interface ServiceMeta {
|
||||
image: string;
|
||||
tag: string
|
||||
}
|
||||
export interface Features {
|
||||
backups: string;
|
||||
email: string;
|
||||
healthcheck: string;
|
||||
image: Image;
|
||||
status: number;
|
||||
tests: string;
|
||||
sso: string;
|
||||
}
|
||||
export interface AbraRecipe {
|
||||
category: string;
|
||||
default_branch: string;
|
||||
description: string;
|
||||
features: Features;
|
||||
icon: string;
|
||||
name: string;
|
||||
repository: string;
|
||||
ssh_url: string;
|
||||
versions: RecipeVersions;
|
||||
website: string;
|
||||
}
|
||||
Reference in New Issue
Block a user