13 Commits

Author SHA1 Message Date
hey 6ecc158268 add creating new app and fix terminal bug 2026-04-18 17:35:50 -04:00
hey 864640a15e merged recipes with log streaming 2026-04-18 13:32:10 -04:00
hey 9b1eaf168f added service information for each app 2026-04-18 13:28:19 -04:00
BornDeleuze df61028185 Merge pull request 'recipes' (#6) from recipes into dev
Reviewed-on: BornDeleuze/coop-cloud-front#6
2026-04-17 20:10:14 +00:00
Matt Beaudoin f85b453b55 basic functionality working 2026-04-17 13:06:15 -07:00
Matt Beaudoin 21825ee009 add recipe from jjsfunhouse 2026-04-17 12:34:40 -07:00
Matt Beaudoin a9a3b0c4e6 add local websocket url 2026-03-24 21:36:22 -07:00
Matt Beaudoin 10acf1f0f2 style pass 2026-03-24 21:30:59 -07:00
Matt Beaudoin b1863f8dcf remove duplicate start 2026-03-24 21:27:12 -07:00
Matt Beaudoin a588a16b96 fix scss imports 2026-03-24 21:25:19 -07:00
Matt Beaudoin 9be82e9e95 remove user / auth 2026-03-24 21:22:39 -07:00
Matt Beaudoin 9cde325a02 remove duplicate function 2026-03-24 21:16:06 -07:00
Matt Beaudoin a08f42b8af api changes 2026-03-22 14:15:59 -07:00
33 changed files with 7754 additions and 586 deletions
+1
View File
@@ -1,2 +1,3 @@
VITE_API_URL=http://localhost:3000/api
VITE_WS_URL=ws://localhost:3000
VITE_MOCK_AUTH=true
+1 -1
View File
@@ -1,5 +1,5 @@
# API base URL for the backend that wraps the abra CLI
VITE_API_URL=http://localhost:3000/api
# Set to 'true' to bypass authentication for development
# Set to 'true' to use mock data
VITE_MOCK_AUTH=true
-14
View File
@@ -1,14 +0,0 @@
[build]
command = "npm run build"
publish = "dist"
# Environment variables for build
[build.environment]
VITE_MOCK_AUTH = "true"
VITE_API_URL = "http://localhost:3000/api"
# Redirect all requests to index.html for client-side routing
[[redirects]]
from = "/*"
to = "/index.html"
status = 200
+5062
View File
File diff suppressed because it is too large Load Diff
+16 -25
View File
@@ -1,37 +1,28 @@
import { BrowserRouter, Navigate, Route, Routes } from 'react-router-dom';
import { AuthProvider } from './context/AuthContext';
import { LoginForm } from './routes/Login/LoginForm';
import { Authenticated } from './components/Authenticated';
import { Dashboard } from './routes/Authenticated/Dashboard/Dashboard';
import { Apps } from './routes/Authenticated/Apps/Apps';
import { AppDetail } from './routes/Authenticated/Apps/App';
import { Servers } from './routes/Authenticated/Servers/Servers';
import { Server } from './routes/Authenticated/Servers/Server';
import { Dashboard } from './routes/Dashboard/Dashboard';
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 (
<BrowserRouter>
<AuthProvider>
<Routes>
{/* Public routes */}
<Route path="/login" element={<LoginForm />} />
{/* Protected routes */}
<Route element={<Authenticated />}>
<Route path="/" element={<Navigate to="/dashboard" replace />} />
<Route path="/dashboard" element={<Dashboard />} />
<Route path="/apps" element={<Apps />} />
<Route path="/apps/:server/:appName" element={<AppDetail />} />
<Route path="/servers" element={<Servers />} />
<Route path="/servers/:serverName" element={<Server />} />
</Route>
<Routes>
<Route path="/" element={<Navigate to="/dashboard" replace />} />
<Route path="/dashboard" element={<Dashboard />} />
<Route path="/apps" element={<Apps />} />
<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>
</AuthProvider>
</BrowserRouter>
);
}
export default App;
export default App;
-24
View File
@@ -1,24 +0,0 @@
import React from 'react';
import { Navigate, Outlet } from 'react-router-dom';
import { useAuth } from '../context/AuthContext';
export const Authenticated: React.FC = () => {
const { isAuthenticated, loading } = useAuth();
console.log('ProtectedRoute:', { isAuthenticated, loading });
if (loading) {
return (
<div style={{
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
height: '100vh'
}}>
<p>Loading...</p>
</div>
);
}
return isAuthenticated ? <Outlet /> : <Navigate to="/login" replace />;
};
+3 -14
View File
@@ -1,6 +1,5 @@
import React from 'react';
import { useNavigate } from 'react-router-dom';
import { useAuth } from '../../hooks/useAuth';
import './_Header.scss';
import logo from '../../assets/coopcloud_logo_grey.svg';
@@ -10,13 +9,7 @@ interface HeaderProps {
}
export const Header: React.FC<HeaderProps> = ({ children }) => {
const { user, logout } = useAuth();
const navigate = useNavigate();
const handleLogout = async () => {
await logout();
navigate('/login');
};
return(
<header className="layout-header">
<div className="header-content">
@@ -33,14 +26,10 @@ return(
<button onClick={() => navigate('/servers')} className="nav-link">
Servers
</button>
</nav>
<div className="user-menu">
<span className="username">{user?.username}</span>
<button onClick={handleLogout} className="logout-button">
Logout
<button onClick={() => navigate('/recipes')} className="nav-link">
Recipes
</button>
</div>
</nav>
</div>
</header>
)}
-46
View File
@@ -78,50 +78,4 @@
font-size: $font-size-xl;
}
}
.user-menu {
display: flex;
align-items: center;
gap: $spacing-lg;
@media (max-width: 768px) {
width: 100%;
justify-content: space-between;
}
.username {
font-weight: $font-weight-medium;
font-size: $font-size-base;
@media (max-width: 480px) {
font-size: $font-size-sm;
}
}
.logout-button {
background: rgba(255, 255, 255, 0.2);
border: 1px solid rgba(255, 255, 255, 0.4);
color: $text-primary;
padding: $spacing-sm $spacing-lg;
border-radius: $radius-md;
cursor: pointer;
transition: all $transition-base;
font-weight: $font-weight-medium;
&:hover {
background: rgba(255, 255, 255, 0.3);
transform: translateY(-1px);
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}
&:active {
transform: translateY(0);
}
@media (max-width: 480px) {
padding: $spacing-sm $spacing-md;
font-size: $font-size-sm;
}
}
}
}
+7 -10
View File
@@ -10,26 +10,25 @@ interface TerminalProps {
export const Terminal: React.FC<TerminalProps> = ({ logs, isActive, onClose }) => {
const terminalRef = useRef<HTMLDivElement>(null);
const indexRef = useRef(0);
const [displayedLogs, setDisplayedLogs] = useState<LogEntry[]>([]);
// Stream logs in with delays for realistic effect
useEffect(() => {
if (!isActive || logs.length === 0) {
indexRef.current = 0;
setDisplayedLogs([]);
return;
}
setDisplayedLogs([]);
let currentIndex = 0;
const streamLogs = () => {
if (currentIndex < logs.length) {
setDisplayedLogs(prev => [...prev, logs[currentIndex]]);
currentIndex++;
if (indexRef.current < logs.length) {
setDisplayedLogs(prev => [...prev, logs[indexRef.current]]);
indexRef.current++;
// Variable delay based on log type
const delay = logs[currentIndex - 1]?.type === 'command' ? 200 :
logs[currentIndex - 1]?.type === 'output' ? 100 : 300;
const delay = logs[indexRef.current - 1]?.type === 'command' ? 200 :
logs[indexRef.current - 1]?.type === 'output' ? 100 : 300;
setTimeout(streamLogs, delay);
}
@@ -37,7 +36,6 @@ export const Terminal: React.FC<TerminalProps> = ({ logs, isActive, onClose }) =
streamLogs();
}, [logs, isActive]);
// Auto-scroll to bottom
useEffect(() => {
if (terminalRef.current) {
@@ -73,7 +71,6 @@ export const Terminal: React.FC<TerminalProps> = ({ logs, isActive, onClose }) =
<div className="terminal-content" ref={terminalRef}>
{displayedLogs.filter(log => log && log.type).map((log, index) => (
<div key={index} className={`terminal-line terminal-${log.type}`}>
<span className="terminal-timestamp">[{formatTime(log.timestamp)}]</span>
<span className="terminal-text">{log.text}</span>
</div>
))}
-89
View File
@@ -1,89 +0,0 @@
import React, { createContext, ReactNode, useContext, useEffect, useState } from 'react';
import { apiService } from '../services/api';
import type { LoginCredentials, User } from '../types';
interface AuthContextType {
user: User | null;
loading: boolean;
login: (credentials: LoginCredentials) => Promise<void>;
logout: () => Promise<void>;
isAuthenticated: boolean;
}
export const AuthContext = createContext<AuthContextType | undefined>(undefined);
interface AuthProviderProps {
children: ReactNode;
}
export const AuthProvider: React.FC<AuthProviderProps> = ({ children }) => {
const [user, setUser] = useState<User | null>(null);
const [loading, setLoading] = useState(true);
const isMockMode = import.meta.env.VITE_MOCK_AUTH === 'true';
useEffect(() => {
const checkAuth = async () => {
console.log('checkAuth running, isMockMode:', isMockMode);
try {
if (isMockMode) {
console.log('Mock mode - setting mock user');
setUser({
id: 'mock-user-1',
username: 'developer',
email: 'dev@coopcloud.tech',
});
setLoading(false);
console.log('Mock user set, loading set to false');
return;
}
const token = localStorage.getItem('auth_token');
if (token) {
const currentUser = await apiService.getCurrentUser();
setUser(currentUser);
}
} catch (error) {
console.error('Auth check failed:', error);
localStorage.removeItem('auth_token');
} finally {
setLoading(false);
}
};
checkAuth();
}, [isMockMode]);
const login = async (credentials: LoginCredentials) => {
try {
const response = await apiService.login(credentials);
setUser(response.user);
} catch (error) {
throw error;
}
};
const logout = async () => {
await apiService.logout();
setUser(null);
};
const value: AuthContextType = {
user,
loading,
login,
logout,
isAuthenticated: !!user,
};
console.log('AuthContext state:', { user, loading, isAuthenticated: !!user });
return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>;
};
export function useAuth() {
const context = useContext(AuthContext);
if (context === undefined) {
throw new Error('useAuth must be used within an AuthProvider');
}
return context;
}
-12
View File
@@ -1,12 +0,0 @@
import { useContext } from 'react';
import { AuthContext } from '../context/AuthContext';
export const useAuth = () => {
const context = useContext(AuthContext);
if (context === undefined) {
throw new Error('useAuth must be used within an AuthProvider');
}
return context;
};
@@ -1,6 +1,6 @@
@use '../../../assets/scss/variables' as *;
@use '../../../assets/scss/mixins' as *;
@use '../../../assets/scss/global' as *;
@use '../../assets/scss/variables' as *;
@use '../../assets/scss/mixins' as *;
@use '../../assets/scss/global' as *;
.app-detail-page {
@extend .page-wrapper;
@@ -77,7 +77,12 @@
border-color: $primary-light;
}
}
&.service {
&:hover:not(:disabled) {
background: #3fff5c9d;
}
}
&.secondary {
background: $bg-secondary;
color: $text-primary;
@@ -132,6 +137,49 @@
}
}
// service grid
.service-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(200px, 2fr));
gap: $spacing-md;
}
.service-card {
@include card;
transition: transform $transition-base, box-shadow $transition-base;
position: relative;
overflow: hidden;
padding: $spacing-md;
.service-name {
h3 {
font-size: $font-size-lg;
color: $text-primary;
font-weight: $font-weight-bold;
}
}
.service-row {
flex-grow: 1;
flex: 1;
.service-value {
font-size: $font-size-sm;
display: -webkit-box;
}
}
&.dark-green {
background-color: #3fff5c;
}
&.green {
background-color: #3fff5c9d;
}
&.red {
background-color: #ff1313;
}
&.gray {
background-color: rgb(187, 187, 187)
}
}
// Info grid
.info-grid {
display: grid;
@@ -347,7 +395,6 @@
background: rgba($error, 0.05);
}
}
.action-text {
flex: 1;
font-weight: $font-weight-medium;
@@ -1,10 +1,10 @@
import React, { useEffect, useState } from 'react';
import React, { useEffect, useState, useRef } from 'react';
import { useParams, useNavigate } from 'react-router-dom';
import { Header } from '../../../components/Header/Header';
import { Terminal } from '../../../components/Terminal/Terminal';
import { apiService } from '../../../services/api';
import type { AbraApp } from '../../../types';
import type { LogEntry } from '../../../services/mockApi';
import { Header } from '../../components/Header/Header';
import { Terminal } from '../../components/Terminal/Terminal';
import { apiService } from '../../services/api';
import type { AbraApp, AbraAppService, AbraServiceState } from '../../types';
import type { LogEntry } from '../../services/mockApi';
import './App.scss';
export const AppDetail: React.FC = () => {
@@ -12,6 +12,9 @@ export const AppDetail: React.FC = () => {
const navigate = useNavigate();
const [app, setApp] = useState<AbraApp | null>(null);
const [deployState, setDeployState] = useState("undeployed | deploying | deployed | failed");
const [serviceState, setServiceState] = useState<Record<string, AbraServiceState>>({});
const [services, setServices] = useState<AbraAppService[]>();
const [loading, setLoading] = useState(true);
const [error, setError] = useState('');
const [actionLoading, setActionLoading] = useState<string | null>(null);
@@ -20,13 +23,31 @@ export const AppDetail: React.FC = () => {
const [terminalLogs, setTerminalLogs] = useState<LogEntry[]>([]);
const [terminalActive, setTerminalActive] = useState(false);
const isMockMode = import.meta.env.VITE_MOCK_AUTH === 'true';
// Stream state
const stopRef = useRef<null | (() => void)>(null);
const deployRef = useRef<null | (() => void)>(null);
// Use to refresh page
const [refreshKey, setRefreshKey] = useState(0);
const isMockMode = false;
const getServiceClass = (state: string, status: string) => {
if (state === "running" && status.includes("\(healthy\)")) return "service-card dark-green";
if (status.includes("unhealthy")) return "service-card red"
if (state === "running") return "service-card green";
return "service-card gray";
};
const getServiceClassDeploying = (state: string, status: string) => {
if (state.includes("converged") && status.includes("\(healthy\)")) return "service-card dark-green";
if (status.includes("unhealthy")) return "service-card red"
if (state.includes("converged")) return "service-card green";
return "service-card gray";
};
useEffect(() => {
const fetchApp = async () => {
try {
if (isMockMode) {
const { mockApiService } = await import('../../../services/mockApi');
const { mockApiService } = await import('../../services/mockApi');
const appsData = await mockApiService.getAppsGrouped();
const serverApps = appsData[server || ''];
@@ -38,12 +59,17 @@ export const AppDetail: React.FC = () => {
setError('App not found');
}
} else {
console.log('fetching app...');
const appsData = await apiService.getAppsGrouped();
const serverApps = appsData[server || ''];
const foundApp = serverApps?.apps.find(a => a.appName === appName);
if (foundApp) {
setApp(foundApp);
// when the app is deploying it should handle setting the deploy state itself after success/failure.
if (deployState !== "deploying") {
setDeployState(foundApp.status === "deployed" ? "deployed" : "undeployed");
}
} else {
setError('App not found');
}
@@ -56,33 +82,48 @@ export const AppDetail: React.FC = () => {
};
fetchApp();
}, [server, appName, isMockMode]);
}, [server, appName, isMockMode, refreshKey]);
// checks status of app containers
useEffect(() => {
let isMounted = true;
const heartbeat = async () => {
while (isMounted) {
if (deployState === "deployed" && appName) {
const services = await apiService.getServices(appName);
if (services) {
setServices(services);
} else {
setServices([]);
}
}
await new Promise(resolve => setTimeout(resolve, 10000));
}
};
heartbeat();
return () => {
isMounted = false;
};
}, [deployState, appName]);
const handleAction = async (action: string, version?: string) => {
if (!app) return;
setActionLoading(action);
setTerminalActive(true);
setTerminalLogs([]);
try {
if (isMockMode) {
const { mockApiService } = await import('../../../services/mockApi');
const { mockApiService } = await import('../../services/mockApi');
const onLog = (log: LogEntry) => {
setTerminalLogs(prev => [...prev, log]);
};
switch (action) {
case 'start':
await mockApiService.startApp(app.appName, onLog);
case 'deploy':
await mockApiService.deployApp(app.appName, onLog);
break;
case 'stop':
await mockApiService.stopApp(app.appName, onLog);
break;
case 'deploy':
await mockApiService.deployApp(app.appName, onLog);
break;
case 'upgrade':
if (version) {
await mockApiService.upgradeApp(app.appName, version, onLog);
@@ -95,15 +136,56 @@ export const AppDetail: React.FC = () => {
} else {
// Real API calls
switch (action) {
case 'start':
await apiService.startApp(app.appName);
break;
case 'stop':
await apiService.stopApp(app.appName);
setRefreshKey(prev => prev + 1);
break;
case 'deploy':
await apiService.deployApp(app.appName);
setDeployState("deploying");
console.log("deploying");
deployRef.current = apiService.deployLogs(app.appName,
(update) => {
if (update.type === "service") {
console.log(update.data.name)
const serviceName = update.data.name.slice(app.appName.length+1)
setServiceState(prev => ({
...prev,
[serviceName]: {
...prev[serviceName] ?? {},
...update.data
}
}))
}
if (update.type === "done") {
console.log("done?");
console.log(update.data.failed, update.data.count);
if (update.data.failed) {
setDeployState('failed');
console.log("Deploy failed?");
} else {
setDeployState("deployed");
}
setRefreshKey(prev => prev + 1);
}
}
)
break;
case 'logs':
setTerminalActive(true);
setTerminalLogs([]);
if (version) {
stopRef.current = apiService.getLogs(app.appName, version,
(line) => {
console.log(line);
setTerminalLogs(prev => [...prev, {
type: 'info',
text: `${line}`,
timestamp: new Date()
}]);
}
)
}
}
}
} catch (err) {
@@ -142,8 +224,8 @@ export const AppDetail: React.FC = () => {
</div>
);
}
const upgradeVersions = app.upgrade !== 'latest' ? app.upgrade.split('\n') : [];
// TODO: make sure this makes sense when app.upgrade is unknown
const upgradeVersions = (app.upgrade !== 'latest' && app.upgrade !== 'unknown') ? app.upgrade.split('\n') : [];
return (
<div className="app-detail-page">
@@ -191,7 +273,11 @@ export const AppDetail: React.FC = () => {
<Terminal
logs={terminalLogs}
isActive={terminalActive}
onClose={() => setTerminalActive(false)}
onClose={() => {
stopRef.current?.();
stopRef.current = null;
setTerminalActive(false)
}}
/>
<div className="content-grid">
@@ -247,7 +333,70 @@ export const AppDetail: React.FC = () => {
</div>
</div>
</section>
{(deployState === "deployed" || deployState === "failed") && (
<section className="info-card">
<h2> Service Information </h2>
<div className="service-grid">
{services === undefined || services?.length === 0 ? (
<div className="no-services"> Loading services... </div>
) : (
services.map((service) => (
<div
key={service.service}
className={getServiceClass(service.state, service.status)}
>
<div className="service-name">
<h3> {service.service} </h3>
</div>
<div className="service-row">
<span className="service-value">{service.state}</span>
<span className="service-value">{service.status}</span>
</div>
<button
className="action-btn"
onClick={() => handleAction('logs', service.service)}
disabled={!!actionLoading}
>
Logs
</button>
</div>
))
)}
</div>
</section>)}
{(deployState === "deploying") && (
<section className="info-card">
<h2> Service Information </h2>
<div className="service-grid">
{serviceState === undefined || Object.keys(serviceState).length === 0 ? (
<div className="no-services"> Preparing services... </div>
) : (
Object.keys(serviceState).map((name) => (
<div
key={name}
className={getServiceClass(serviceState[name].status, serviceState[name].health)}
>
<div className="service-name">
<h3> {name} </h3>
</div>
<div className="service-row">
<span className="service-value">{serviceState[name].status}</span>
<span className="service-value">{serviceState[name].health}</span>
</div>
<button
className="action-btn"
onClick={() => handleAction('logs', appName)}
disabled={!!actionLoading}
>
Logs
</button>
</div>
))
)}
</div>
</section>)}
<section className="info-card">
<h2>Version Information</h2>
@@ -287,6 +436,18 @@ export const AppDetail: React.FC = () => {
</div>
)}
{app.upgrade === 'unknown' && (
<div className="version-upgrades">
<label>
Available Upgrades
</label>
<div className="upgrade-list">
<div className="upgrade-item">
<code>None</code>
</div>
</div>
</div>
)}
{app.upgrade === 'latest' && (
<div className="version-latest">
Running latest version
@@ -302,12 +463,13 @@ export const AppDetail: React.FC = () => {
<h2>Quick Actions</h2>
<div className="action-list">
<button
className="action-list-item"
onClick={() => handleAction('start')}
onClick={() => handleAction('deploy')}
disabled={!!actionLoading}
>
<span className="action-text"> Start Application</span>
<span className="action-text">Deploy Application</span>
</button>
<button
@@ -315,15 +477,7 @@ export const AppDetail: React.FC = () => {
onClick={() => handleAction('stop')}
disabled={!!actionLoading}
>
<span className="action-text"> Stop Application</span>
</button>
<button
className="action-list-item"
onClick={() => handleAction('deploy')}
disabled={!!actionLoading}
>
<span className="action-text">🚀 Deploy Application</span>
<span className="action-text">Stop Application</span>
</button>
<button
@@ -335,7 +489,7 @@ export const AppDetail: React.FC = () => {
}}
disabled={!!actionLoading}
>
<span className="action-text">🗑 Remove Application</span>
<span className="action-text">Remove Application</span>
</button>
</div>
</section>
@@ -1,6 +1,6 @@
@use '../../../assets/scss/variables' as *;
@use '../../../assets/scss/mixins' as *;
@use '../../../assets/scss/global' as *;
@use '../../assets/scss/variables' as *;
@use '../../assets/scss/mixins' as *;
@use '../../assets/scss/global' as *;
// Extend global page wrapper
.apps-page {
@@ -1,8 +1,8 @@
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, ServerAppsResponse } from '../../../types';
import { Header } from '../../components/Header/Header';
import { apiService } from '../../services/api';
import type { AbraApp, AppWithServer, ServerAppsResponse } from '../../types';
import './Apps.scss';
export const Apps: React.FC = () => {
@@ -15,13 +15,13 @@ export const Apps: React.FC = () => {
const [filterStatus, setFilterStatus] = useState<string>('all');
const [showUpgradesOnly, setShowUpgradesOnly] = useState(false);
const isMockMode = import.meta.env.VITE_MOCK_AUTH === 'true';
const isMockMode = false;
useEffect(() => {
const fetchData = async () => {
try {
if (isMockMode) {
const { mockApiService } = await import('../../../services/mockApi');
const { mockApiService } = await import('../../services/mockApi');
const data = await mockApiService.getAppsGrouped();
setAppsData(data);
} else {
@@ -1,8 +1,8 @@
import React, { useEffect, useState } from 'react';
import { Header } from '../../../components/Header/Header';
import { Header } from '../../components/Header/Header';
import { useNavigate } from 'react-router-dom';
import { apiService } from '../../../services/api';
import type { AbraApp, AbraServer } from '../../../types';
import { apiService } from '../../services/api';
import type { AbraApp, AbraServer } from '../../types';
import './_Dashboard.scss';
export const Dashboard: React.FC = () => {
@@ -12,14 +12,14 @@ export const Dashboard: React.FC = () => {
const [error, setError] = useState('');
const navigate = useNavigate();
const isMockMode = import.meta.env.VITE_MOCK_AUTH === 'true';
const isMockMode = false;
useEffect(() => {
const fetchData = async () => {
try {
if (isMockMode) {
// Use mock API in development
const { mockApiService } = await import('../../../services/mockApi');
const { mockApiService } = await import('../../services/mockApi');
const [appsData, serversData] = await Promise.all([
mockApiService.getAppsGrouped(),
mockApiService.getServers(),
@@ -1,6 +1,6 @@
@use '../../../assets/scss/variables' as *;
@use '../../../assets/scss/mixins' as *;
@use '../../../assets/scss/global' as *;
@use '../../assets/scss/variables' as *;
@use '../../assets/scss/mixins' as *;
@use '../../assets/scss/global' as *;
// Extend global page wrapper
.dashboard-page {
-94
View File
@@ -1,94 +0,0 @@
@use '../../assets/scss/variables' as *;
@use '../../assets/scss/mixins' as *;
.login-container {
@include flex-center;
min-height: 100vh;
width: 100%;
// @include gradient-primary;
background-color: $primary-light;
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
.login-card {
@include card;
width: 100%;
max-width: 400px;
h1 {
margin: 0 0 $spacing-sm;
font-size: $font-size-3xl;
color: $text-primary;
text-align: center;
}
.login-subtitle {
text-align: center;
color: $text-secondary;
margin: 0 0 $spacing-2xl;
font-size: $font-size-sm;
}
}
.form-group {
margin-bottom: $spacing-lg;
label {
display: block;
margin-bottom: $spacing-sm;
color: $text-primary;
font-weight: $font-weight-medium;
font-size: $font-size-sm;
}
input {
width: 100%;
padding: $spacing-md;
border: 2px solid $border-color;
border-radius: $radius-md;
font-size: $font-size-base;
transition: border-color $transition-base;
box-sizing: border-box;
&:focus {
outline: none;
border-color: $primary;
}
&:disabled {
background-color: $bg-secondary;
cursor: not-allowed;
}
}
}
.error-message {
// background-color: rgba($error, 0.1);
// color: darken($error, 10%);
padding: $spacing-md;
border-radius: $radius-md;
margin-bottom: $spacing-md;
font-size: $font-size-sm;
// border-left: 4px solid $error;
}
.login-button {
@include button-base;
@include gradient-primary;
width: 100%;
color: white;
font-size: $font-size-base;
&:hover:not(:disabled) {
transform: translateY(-2px);
box-shadow: 0 8px 16px rgba($primary, 0.4);
}
&:active:not(:disabled) {
transform: translateY(0);
}
}
-72
View File
@@ -1,72 +0,0 @@
import React, { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { useAuth } from '../../hooks/useAuth';
import './LoginForm.scss';
export const LoginForm: React.FC = () => {
const [username, setUsername] = useState('');
const [password, setPassword] = useState('');
const [error, setError] = useState('');
const [loading, setLoading] = useState(false);
const { login } = useAuth();
const navigate = useNavigate();
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
setError('');
setLoading(true);
try {
await login({ username, password });
navigate('/dashboard');
} catch (err) {
setError(err instanceof Error ? err.message : 'Login failed');
} finally {
setLoading(false);
}
};
return (
<div className="login-container">
<div className="login-card">
<h1>Coop Cloud</h1>
<p className="login-subtitle">Sign in to manage your applications</p>
<form onSubmit={handleSubmit}>
{error && <div className="error-message">{error}</div>}
<div className="form-group">
<label htmlFor="username">Username</label>
<input
id="username"
type="text"
value={username}
onChange={(e) => setUsername(e.target.value)}
required
autoComplete="username"
disabled={loading}
/>
</div>
<div className="form-group">
<label htmlFor="password">Password</label>
<input
id="password"
type="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
required
autoComplete="current-password"
disabled={loading}
/>
</div>
<button type="submit" disabled={loading} className="login-button">
{loading ? 'Signing in...' : 'Sign in'}
</button>
</form>
</div>
</div>
);
};
View File
View File
View File
+116
View File
@@ -0,0 +1,116 @@
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 [error, setError] = useState('');
useEffect(() => {
const fetchData = async () => {
try {
if (servers.length === 0) {
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({
server: "",
domain: "",
chaos: false,
secrets: false,
});
const handleChange = (e) => {
const {name, type, value, checked} = e.target;
setFormData((prev) => ({
...prev,
[name]: type === "checkbox" ? checked : value,
}));
console.log(formData);
};
const handleSubmit = (e) => {
e.preventDefault();
console.log("Submitting:", formData);
apiService.newApp(recipe.name, formData);
onClose();
};
return (
<form onSubmit={handleSubmit}>
<h2>{recipe.name}</h2>
{ loading ? (<p> Loading servers...</p>
) : (
<div>
<label>
Choose a server to deploy to:
<select
name="server"
value={formData.server || ""}
onChange={handleChange}
>
<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.domain}
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
View 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
View 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 = false;
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 recipes...</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>
);
};
@@ -1,6 +1,6 @@
@use '../../../assets/scss/variables' as *;
@use '../../../assets/scss/mixins' as *;
@use '../../../assets/scss/global' as *;
@use '../../assets/scss/variables' as *;
@use '../../assets/scss/mixins' as *;
@use '../../assets/scss/global' as *;
.server-detail-page {
@extend .page-wrapper;
@@ -1,10 +1,10 @@
import React, { useEffect, useState } from 'react';
import { useParams, useNavigate } from 'react-router-dom';
import { Header } from '../../../components/Header/Header';
import { Terminal } from '../../../components/Terminal/Terminal';
import { apiService } from '../../../services/api';
import type { AbraServer, ServerAppsResponse } from '../../../types';
import type { LogEntry } from '../../../services/mockApi';
import { Header } from '../../components/Header/Header';
import { Terminal } from '../../components/Terminal/Terminal';
import { apiService } from '../../services/api';
import type { AbraServer, ServerAppsResponse } from '../../types';
import type { LogEntry } from '../../services/mockApi';
import './Server.scss';
interface ServerWithApps extends AbraServer {
@@ -29,13 +29,13 @@ export const Server: React.FC = () => {
const [terminalLogs, setTerminalLogs] = useState<LogEntry[]>([]);
const [terminalActive, setTerminalActive] = useState(false);
const isMockMode = import.meta.env.VITE_MOCK_AUTH === 'true';
const isMockMode = false;
useEffect(() => {
const fetchServer = async () => {
try {
if (isMockMode) {
const { mockApiService } = await import('../../../services/mockApi');
const { mockApiService } = await import('../../services/mockApi');
const appsData = await mockApiService.getAppsGrouped();
const serversData = await mockApiService.getServers();
@@ -95,7 +95,7 @@ export const Server: React.FC = () => {
try {
if (isMockMode) {
const { mockApiService } = await import('../../../services/mockApi');
const { mockApiService } = await import('../../services/mockApi');
const onLog = (log: LogEntry) => {
setTerminalLogs(prev => [...prev, log]);
@@ -319,7 +319,7 @@ export const Server: React.FC = () => {
onClick={() => handleAction('refresh')}
disabled={!!actionLoading}
>
<span className="action-text">🔄 Refresh Server Info</span>
<span className="action-text">Refresh Server Info</span>
</button>
<button
@@ -327,7 +327,7 @@ export const Server: React.FC = () => {
onClick={() => handleAction('deploy-all')}
disabled={!!actionLoading}
>
<span className="action-text">🚀 Deploy All Apps</span>
<span className="action-text">Deploy All Apps</span>
</button>
<button
@@ -335,7 +335,7 @@ export const Server: React.FC = () => {
onClick={() => handleAction('upgrade-all')}
disabled={!!actionLoading || server.upgradeCount === 0}
>
<span className="action-text"> Upgrade All Apps</span>
<span className="action-text">Upgrade All Apps</span>
</button>
</div>
</section>
@@ -1,6 +1,6 @@
@use '../../../assets/scss/variables' as *;
@use '../../../assets/scss/mixins' as *;
@use '../../../assets/scss/global' as *;
@use '../../assets/scss/variables' as *;
@use '../../assets/scss/mixins' as *;
@use '../../assets/scss/global' as *;
// Extend global page wrapper
.servers-page {
@@ -1,8 +1,8 @@
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 { AbraServer, ServerAppsResponse } from '../../../types';
import { Header } from '../../components/Header/Header';
import { apiService } from '../../services/api';
import type { AbraServer, ServerAppsResponse } from '../../types';
import './Servers.scss';
interface ServerWithStats extends AbraServer {
@@ -21,13 +21,13 @@ export const Servers: React.FC = () => {
const [searchTerm, setSearchTerm] = useState('');
const [sortBy, setSortBy] = useState<'name' | 'apps' | 'upgrades'>('name');
const isMockMode = import.meta.env.VITE_MOCK_AUTH === 'true';
const isMockMode = false;
useEffect(() => {
const fetchData = async () => {
try {
if (isMockMode) {
const { mockApiService } = await import('../../../services/mockApi');
const { mockApiService } = await import('../../services/mockApi');
const [serversData, appsData] = await Promise.all([
mockApiService.getServers(),
mockApiService.getAppsGrouped(),
@@ -232,17 +232,13 @@ export const Servers: React.FC = () => {
</div>
{server.upgradeCount > 0 && (
<div className="stat-row highlight">
<span className="stat-label">
<span className="upgrade-icon"></span> 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">
<span className="chaos-icon"></span> Chaos Mode
</span>
<span className="stat-label">Chaos Mode</span>
<span className="stat-value">{server.chaosCount}</span>
</div>
)}
+94 -74
View File
@@ -1,6 +1,6 @@
import type { AbraServer, ServerAppsResponse, AuthResponse, LoginCredentials, User } from '../types';
import type { AbraServer, AbraRecipe, ServerAppsResponse, AbraAppService, DeployEvent } from '../types';
// Log entry type - shared between mock and real API
// Log entry type
export type LogEntry = {
type: 'info' | 'success' | 'error' | 'warning' | 'command' | 'output';
text: string;
@@ -19,12 +19,6 @@ const processLogResponse = (logData: any[]): LogEntry[] => {
};
class ApiService {
private token: string | null = null;
constructor() {
this.token = localStorage.getItem('auth_token');
}
private async request<T>(
endpoint: string,
options: RequestInit = {}
@@ -34,10 +28,6 @@ class ApiService {
...options.headers,
};
if (this.token) {
headers['Authorization'] = `Bearer ${this.token}`;
}
const response = await fetch(`${API_BASE_URL}${endpoint}`, {
...options,
headers,
@@ -47,66 +37,81 @@ class ApiService {
const error = await response.json().catch(() => ({ message: 'An error occurred' }));
throw new Error(error.message || `HTTP ${response.status}`);
}
return response.json();
}
// Auth methods
async login(credentials: LoginCredentials): Promise<AuthResponse> {
const response = await this.request<AuthResponse>('/auth/login', {
method: 'POST',
body: JSON.stringify(credentials),
});
this.token = response.token;
localStorage.setItem('auth_token', response.token);
return response;
}
async logout(): Promise<void> {
this.token = null;
localStorage.removeItem('auth_token');
}
async getCurrentUser(): Promise<User> {
return this.request<User>('/auth/me');
}
// Abra CLI wrapper methods
async getAppsGrouped(): Promise<ServerAppsResponse> {
return this.request<ServerAppsResponse>('/abra/apps');
}
async getServers(): Promise<AbraServer[]> {
return this.request<AbraServer[]>('/abra/servers');
}
// App actions with log streaming
async deployApp(appName: string, onLog?: (log: LogEntry) => void): Promise<void> {
const response = await this.request<{ logs: any[] }>(`/abra/apps/${appName}/deploy`, {
method: 'POST',
});
// Process logs and stream to callback
if (onLog && response.logs) {
const logs = processLogResponse(response.logs);
logs.forEach(log => onLog(log));
if (response.status === 204) {
return undefined as T;
}
const contentType = response.headers.get('content-type');
if (contentType?.includes('application/json')) {
return response.json();
}
return response.text() as unknown as T;
}
private stream<T>(
endpoint: string,
handlers: {
onMessage: (data: T) => void;
onError?: (err: any) => void;
onOpen?: () => void;
parser?: (raw: string) => T;
}
) {
const es = new EventSource(`${API_BASE_URL}${endpoint}`);
es.onopen = () => {
handlers.onOpen?.();
};
es.onmessage = (event) => {
try {
const data = handlers.parser
? handlers.parser(event.data)
: (event.data as unknown as T);
handlers.onMessage(data);
} catch (err) {
handlers.onError?.(err);
}
};
es.onerror = (err) => {
handlers.onError?.(err);
es.close();
};
return () => es.close();
}
// Get Logs for service
getLogs(appName: string, serviceName: string, msgHandler: (data: String) => void) {
return this.stream(`/apps/${appName}/${serviceName}/logs`, {onMessage: msgHandler})
}
// Get all apps grouped by server
async getAppsGrouped(): Promise<ServerAppsResponse> {
return this.request<ServerAppsResponse>('/apps');
}
// Get all servers
async getServers(): Promise<AbraServer[]> {
return this.request<AbraServer[]>('/servers');
}
// Get services for app
async getServices(appName: string): Promise<AbraAppService[]> {
return this.request<AbraAppService[]>(`/apps/${appName}/services`);
}
// App actions with log streaming (websocket future)
async deployApp(appName: string): Promise<void> {
return this.request<void>(`/apps/${appName}/deploy`, {
method: 'POST',
});
}
deployLogs(appName: string, msgHandler: (data: DeployEvent) => void) {
return this.stream(`/apps/${appName}/deploy`, {parser: JSON.parse, onMessage: msgHandler})
}
async stopApp(appName: string, onLog?: (log: LogEntry) => void): Promise<void> {
const response = await this.request<{ logs: any[] }>(`/abra/apps/${appName}/stop`, {
method: 'POST',
});
if (onLog && response.logs) {
const logs = processLogResponse(response.logs);
logs.forEach(log => onLog(log));
}
}
async startApp(appName: string, onLog?: (log: LogEntry) => void): Promise<void> {
const response = await this.request<{ logs: any[] }>(`/abra/apps/${appName}/start`, {
const response = await this.request<{ logs: any[] }>(`/apps/${appName}/stop`, {
method: 'POST',
});
@@ -117,7 +122,7 @@ class ApiService {
}
async upgradeApp(appName: string, version: string, onLog?: (log: LogEntry) => void): Promise<void> {
const response = await this.request<{ logs: any[] }>(`/abra/apps/${appName}/upgrade`, {
const response = await this.request<{ logs: any[] }>(`/apps/${appName}/upgrade`, {
method: 'POST',
body: JSON.stringify({ version }),
});
@@ -129,7 +134,7 @@ class ApiService {
}
async removeApp(appName: string, onLog?: (log: LogEntry) => void): Promise<void> {
const response = await this.request<{ logs: any[] }>(`/abra/apps/${appName}/remove`, {
const response = await this.request<{ logs: any[] }>(`/apps/${appName}/remove`, {
method: 'POST',
});
@@ -138,10 +143,20 @@ class ApiService {
logs.forEach(log => onLog(log));
}
}
async newApp(appName: string, formData: Object): Promise<void> {
const response = await this.request<void>(`/apps/${appName}/new`, {
method: 'POST',
headers: {
'Accept': 'application/json'
},
body: JSON.stringify(formData)
});
return response
}
// Server actions with log streaming
async refreshServer(serverName: string, onLog?: (log: LogEntry) => void): Promise<void> {
const response = await this.request<{ logs: any[] }>(`/abra/servers/${serverName}/refresh`, {
const response = await this.request<{ logs: any[] }>(`/servers/${serverName}/refresh`, {
method: 'POST',
});
@@ -152,7 +167,7 @@ class ApiService {
}
async deployAllApps(serverName: string, appCount: number, onLog?: (log: LogEntry) => void): Promise<void> {
const response = await this.request<{ logs: any[] }>(`/abra/servers/${serverName}/deploy-all`, {
const response = await this.request<{ logs: any[] }>(`/servers/${serverName}/deploy-all`, {
method: 'POST',
});
@@ -163,7 +178,7 @@ class ApiService {
}
async upgradeAllApps(serverName: string, upgradeCount: number, onLog?: (log: LogEntry) => void): Promise<void> {
const response = await this.request<{ logs: any[] }>(`/abra/servers/${serverName}/upgrade-all`, {
const response = await this.request<{ logs: any[] }>(`/servers/${serverName}/upgrade-all`, {
method: 'POST',
});
@@ -172,6 +187,11 @@ class ApiService {
logs.forEach(log => onLog(log));
}
}
// recipe catalog imports
async getRecipes(): Promise<AbraRecipe[]> {
return this.request<AbraRecipe[]>('/catalogue');
}
}
export const apiService = new ApiService();
export const apiService = new ApiService();
File diff suppressed because it is too large Load Diff
+8 -10
View File
@@ -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 = {
@@ -91,15 +93,6 @@ export const mockApiService = {
}
},
async startApp(appName: string, onLog?: (log: LogEntry) => void): Promise<void> {
const logs = processLogs('start', { appName });
for (const log of logs) {
await delay(150);
onLog?.(log);
}
},
async upgradeApp(appName: string, version: string, onLog?: (log: LogEntry) => void): Promise<void> {
const logs = processLogs('upgrade', { appName, version });
@@ -144,4 +137,9 @@ export const mockApiService = {
onLog?.(log);
}
},
// recipe catalog imports
async getRecipes(): Promise<AbraRecipe[]> {
await delay(300);
return catalogue as AbraRecipe[];
}
};
+70 -17
View File
@@ -1,19 +1,3 @@
export interface User {
id: string;
username: string;
email: string;
}
export interface AuthResponse {
user: User;
token: string;
}
export interface LoginCredentials {
username: string;
password: string;
}
export interface ApiError {
message: string;
status: number;
@@ -52,4 +36,73 @@ export interface AppWithServer extends AbraApp {
appCount: number;
upgradeCount: number;
};
}
}
export interface AbraAppService {
service: string;
chaos: boolean;
created: string;
image: string;
ports: string;
state: string;
status: string;
version: string;
}
export interface AbraServiceState {
name: string;
err: string;
id: string;
status: string;
retries: number;
health: string;
rollback: boolean;
failed: boolean;
}
export interface DeployState {
count: number;
total: number;
failed: boolean;
quit: boolean;
}
export type DeployEvent =
| {
type: "service";
data: AbraServiceState;
}
| {
type: "done";
data: DeployState;
}
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;
}