Initial commit - cleaned repository
This commit is contained in:
19
console/frontend/src/App.tsx
Normal file
19
console/frontend/src/App.tsx
Normal file
@ -0,0 +1,19 @@
|
||||
import { Routes, Route } from 'react-router-dom'
|
||||
import Layout from './components/Layout'
|
||||
import Dashboard from './pages/Dashboard'
|
||||
import Services from './pages/Services'
|
||||
import Users from './pages/Users'
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<Routes>
|
||||
<Route path="/" element={<Layout />}>
|
||||
<Route index element={<Dashboard />} />
|
||||
<Route path="services" element={<Services />} />
|
||||
<Route path="users" element={<Users />} />
|
||||
</Route>
|
||||
</Routes>
|
||||
)
|
||||
}
|
||||
|
||||
export default App
|
||||
102
console/frontend/src/components/Layout.tsx
Normal file
102
console/frontend/src/components/Layout.tsx
Normal file
@ -0,0 +1,102 @@
|
||||
import { useState } from 'react'
|
||||
import { Outlet, Link as RouterLink } from 'react-router-dom'
|
||||
import {
|
||||
AppBar,
|
||||
Box,
|
||||
Drawer,
|
||||
IconButton,
|
||||
List,
|
||||
ListItem,
|
||||
ListItemButton,
|
||||
ListItemIcon,
|
||||
ListItemText,
|
||||
Toolbar,
|
||||
Typography,
|
||||
} from '@mui/material'
|
||||
import {
|
||||
Menu as MenuIcon,
|
||||
Dashboard as DashboardIcon,
|
||||
Cloud as CloudIcon,
|
||||
People as PeopleIcon,
|
||||
} from '@mui/icons-material'
|
||||
|
||||
const drawerWidth = 240
|
||||
|
||||
const menuItems = [
|
||||
{ text: 'Dashboard', icon: <DashboardIcon />, path: '/' },
|
||||
{ text: 'Services', icon: <CloudIcon />, path: '/services' },
|
||||
{ text: 'Users', icon: <PeopleIcon />, path: '/users' },
|
||||
]
|
||||
|
||||
function Layout() {
|
||||
const [open, setOpen] = useState(true)
|
||||
|
||||
const handleDrawerToggle = () => {
|
||||
setOpen(!open)
|
||||
}
|
||||
|
||||
return (
|
||||
<Box sx={{ display: 'flex' }}>
|
||||
<AppBar
|
||||
position="fixed"
|
||||
sx={{ zIndex: (theme) => theme.zIndex.drawer + 1 }}
|
||||
>
|
||||
<Toolbar>
|
||||
<IconButton
|
||||
color="inherit"
|
||||
aria-label="open drawer"
|
||||
edge="start"
|
||||
onClick={handleDrawerToggle}
|
||||
sx={{ mr: 2 }}
|
||||
>
|
||||
<MenuIcon />
|
||||
</IconButton>
|
||||
<Typography variant="h6" noWrap component="div">
|
||||
Microservices Console
|
||||
</Typography>
|
||||
</Toolbar>
|
||||
</AppBar>
|
||||
<Drawer
|
||||
variant="persistent"
|
||||
anchor="left"
|
||||
open={open}
|
||||
sx={{
|
||||
width: drawerWidth,
|
||||
flexShrink: 0,
|
||||
'& .MuiDrawer-paper': {
|
||||
width: drawerWidth,
|
||||
boxSizing: 'border-box',
|
||||
},
|
||||
}}
|
||||
>
|
||||
<Toolbar />
|
||||
<Box sx={{ overflow: 'auto' }}>
|
||||
<List>
|
||||
{menuItems.map((item) => (
|
||||
<ListItem key={item.text} disablePadding>
|
||||
<ListItemButton component={RouterLink} to={item.path}>
|
||||
<ListItemIcon>{item.icon}</ListItemIcon>
|
||||
<ListItemText primary={item.text} />
|
||||
</ListItemButton>
|
||||
</ListItem>
|
||||
))}
|
||||
</List>
|
||||
</Box>
|
||||
</Drawer>
|
||||
<Box
|
||||
component="main"
|
||||
sx={{
|
||||
flexGrow: 1,
|
||||
p: 3,
|
||||
marginLeft: open ? `${drawerWidth}px` : 0,
|
||||
transition: 'margin 0.3s',
|
||||
}}
|
||||
>
|
||||
<Toolbar />
|
||||
<Outlet />
|
||||
</Box>
|
||||
</Box>
|
||||
)
|
||||
}
|
||||
|
||||
export default Layout
|
||||
29
console/frontend/src/main.tsx
Normal file
29
console/frontend/src/main.tsx
Normal file
@ -0,0 +1,29 @@
|
||||
import React from 'react'
|
||||
import ReactDOM from 'react-dom/client'
|
||||
import { BrowserRouter } from 'react-router-dom'
|
||||
import { ThemeProvider, createTheme } from '@mui/material/styles'
|
||||
import CssBaseline from '@mui/material/CssBaseline'
|
||||
import App from './App'
|
||||
|
||||
const theme = createTheme({
|
||||
palette: {
|
||||
mode: 'light',
|
||||
primary: {
|
||||
main: '#1976d2',
|
||||
},
|
||||
secondary: {
|
||||
main: '#dc004e',
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
ReactDOM.createRoot(document.getElementById('root')!).render(
|
||||
<React.StrictMode>
|
||||
<BrowserRouter>
|
||||
<ThemeProvider theme={theme}>
|
||||
<CssBaseline />
|
||||
<App />
|
||||
</ThemeProvider>
|
||||
</BrowserRouter>
|
||||
</React.StrictMode>,
|
||||
)
|
||||
153
console/frontend/src/pages/Dashboard.tsx
Normal file
153
console/frontend/src/pages/Dashboard.tsx
Normal file
@ -0,0 +1,153 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import {
|
||||
Grid,
|
||||
Paper,
|
||||
Typography,
|
||||
Box,
|
||||
Card,
|
||||
CardContent,
|
||||
Chip,
|
||||
} from '@mui/material'
|
||||
import {
|
||||
CheckCircle as CheckCircleIcon,
|
||||
Error as ErrorIcon
|
||||
} from '@mui/icons-material'
|
||||
import axios from 'axios'
|
||||
|
||||
interface ServiceStatus {
|
||||
name: string
|
||||
status: 'healthy' | 'unhealthy'
|
||||
endpoint: string
|
||||
lastChecked: string
|
||||
}
|
||||
|
||||
function Dashboard() {
|
||||
const [services, setServices] = useState<ServiceStatus[]>([])
|
||||
const [stats, setStats] = useState({
|
||||
totalServices: 0,
|
||||
healthyServices: 0,
|
||||
unhealthyServices: 0,
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
checkServices()
|
||||
const interval = setInterval(checkServices, 10000)
|
||||
return () => clearInterval(interval)
|
||||
}, [])
|
||||
|
||||
const checkServices = async () => {
|
||||
const serviceChecks = [
|
||||
{ name: 'Console Backend', endpoint: '/api/health' },
|
||||
{ name: 'Users Service', endpoint: '/api/users/health' },
|
||||
]
|
||||
|
||||
const results = await Promise.all(
|
||||
serviceChecks.map(async (service) => {
|
||||
try {
|
||||
await axios.get(service.endpoint)
|
||||
return {
|
||||
...service,
|
||||
status: 'healthy' as const,
|
||||
lastChecked: new Date().toLocaleTimeString(),
|
||||
}
|
||||
} catch {
|
||||
return {
|
||||
...service,
|
||||
status: 'unhealthy' as const,
|
||||
lastChecked: new Date().toLocaleTimeString(),
|
||||
}
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
setServices(results)
|
||||
|
||||
const healthy = results.filter(s => s.status === 'healthy').length
|
||||
setStats({
|
||||
totalServices: results.length,
|
||||
healthyServices: healthy,
|
||||
unhealthyServices: results.length - healthy,
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
<Box>
|
||||
<Typography variant="h4" gutterBottom>
|
||||
Dashboard
|
||||
</Typography>
|
||||
|
||||
<Grid container spacing={3} sx={{ mb: 3 }}>
|
||||
<Grid item xs={12} md={4}>
|
||||
<Card>
|
||||
<CardContent>
|
||||
<Typography color="textSecondary" gutterBottom>
|
||||
Total Services
|
||||
</Typography>
|
||||
<Typography variant="h3">
|
||||
{stats.totalServices}
|
||||
</Typography>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</Grid>
|
||||
<Grid item xs={12} md={4}>
|
||||
<Card>
|
||||
<CardContent>
|
||||
<Typography color="textSecondary" gutterBottom>
|
||||
Healthy Services
|
||||
</Typography>
|
||||
<Typography variant="h3" color="success.main">
|
||||
{stats.healthyServices}
|
||||
</Typography>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</Grid>
|
||||
<Grid item xs={12} md={4}>
|
||||
<Card>
|
||||
<CardContent>
|
||||
<Typography color="textSecondary" gutterBottom>
|
||||
Unhealthy Services
|
||||
</Typography>
|
||||
<Typography variant="h3" color="error.main">
|
||||
{stats.unhealthyServices}
|
||||
</Typography>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
||||
<Paper sx={{ p: 2 }}>
|
||||
<Typography variant="h6" gutterBottom>
|
||||
Service Status
|
||||
</Typography>
|
||||
<Grid container spacing={2}>
|
||||
{services.map((service) => (
|
||||
<Grid item xs={12} md={6} key={service.name}>
|
||||
<Card variant="outlined">
|
||||
<CardContent>
|
||||
<Box display="flex" justifyContent="space-between" alignItems="center">
|
||||
<Box>
|
||||
<Typography variant="h6">{service.name}</Typography>
|
||||
<Typography variant="body2" color="textSecondary">
|
||||
{service.endpoint}
|
||||
</Typography>
|
||||
<Typography variant="caption" color="textSecondary">
|
||||
Last checked: {service.lastChecked}
|
||||
</Typography>
|
||||
</Box>
|
||||
<Chip
|
||||
label={service.status}
|
||||
color={service.status === 'healthy' ? 'success' : 'error'}
|
||||
icon={service.status === 'healthy' ? <CheckCircleIcon /> : <ErrorIcon />}
|
||||
/>
|
||||
</Box>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</Grid>
|
||||
))}
|
||||
</Grid>
|
||||
</Paper>
|
||||
</Box>
|
||||
)
|
||||
}
|
||||
|
||||
export default Dashboard
|
||||
98
console/frontend/src/pages/Services.tsx
Normal file
98
console/frontend/src/pages/Services.tsx
Normal file
@ -0,0 +1,98 @@
|
||||
import {
|
||||
Box,
|
||||
Typography,
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableContainer,
|
||||
TableHead,
|
||||
TableRow,
|
||||
Paper,
|
||||
Chip,
|
||||
} from '@mui/material'
|
||||
|
||||
const servicesData = [
|
||||
{
|
||||
id: 1,
|
||||
name: 'Console',
|
||||
type: 'API Gateway',
|
||||
port: 8011,
|
||||
status: 'Running',
|
||||
description: 'Central orchestrator and API gateway',
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: 'Users',
|
||||
type: 'Microservice',
|
||||
port: 8001,
|
||||
status: 'Running',
|
||||
description: 'User management service',
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
name: 'MongoDB',
|
||||
type: 'Database',
|
||||
port: 27017,
|
||||
status: 'Running',
|
||||
description: 'Document database for persistence',
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
name: 'Redis',
|
||||
type: 'Cache',
|
||||
port: 6379,
|
||||
status: 'Running',
|
||||
description: 'In-memory cache and pub/sub',
|
||||
},
|
||||
]
|
||||
|
||||
function Services() {
|
||||
return (
|
||||
<Box>
|
||||
<Typography variant="h4" gutterBottom>
|
||||
Services
|
||||
</Typography>
|
||||
|
||||
<TableContainer component={Paper}>
|
||||
<Table>
|
||||
<TableHead>
|
||||
<TableRow>
|
||||
<TableCell>Service Name</TableCell>
|
||||
<TableCell>Type</TableCell>
|
||||
<TableCell>Port</TableCell>
|
||||
<TableCell>Status</TableCell>
|
||||
<TableCell>Description</TableCell>
|
||||
</TableRow>
|
||||
</TableHead>
|
||||
<TableBody>
|
||||
{servicesData.map((service) => (
|
||||
<TableRow key={service.id}>
|
||||
<TableCell>
|
||||
<Typography variant="subtitle2">{service.name}</Typography>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Chip
|
||||
label={service.type}
|
||||
size="small"
|
||||
color={service.type === 'API Gateway' ? 'primary' : 'default'}
|
||||
/>
|
||||
</TableCell>
|
||||
<TableCell>{service.port}</TableCell>
|
||||
<TableCell>
|
||||
<Chip
|
||||
label={service.status}
|
||||
size="small"
|
||||
color="success"
|
||||
/>
|
||||
</TableCell>
|
||||
<TableCell>{service.description}</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</TableContainer>
|
||||
</Box>
|
||||
)
|
||||
}
|
||||
|
||||
export default Services
|
||||
208
console/frontend/src/pages/Users.tsx
Normal file
208
console/frontend/src/pages/Users.tsx
Normal file
@ -0,0 +1,208 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
import {
|
||||
Box,
|
||||
Typography,
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableContainer,
|
||||
TableHead,
|
||||
TableRow,
|
||||
Paper,
|
||||
Button,
|
||||
IconButton,
|
||||
TextField,
|
||||
Dialog,
|
||||
DialogTitle,
|
||||
DialogContent,
|
||||
DialogActions,
|
||||
Stack,
|
||||
} from '@mui/material'
|
||||
import {
|
||||
Add as AddIcon,
|
||||
Edit as EditIcon,
|
||||
Delete as DeleteIcon,
|
||||
} from '@mui/icons-material'
|
||||
import axios from 'axios'
|
||||
|
||||
interface User {
|
||||
_id: string
|
||||
username: string
|
||||
email: string
|
||||
full_name?: string
|
||||
created_at: string
|
||||
}
|
||||
|
||||
function Users() {
|
||||
const [users, setUsers] = useState<User[]>([])
|
||||
const [openDialog, setOpenDialog] = useState(false)
|
||||
const [editingUser, setEditingUser] = useState<User | null>(null)
|
||||
const [formData, setFormData] = useState({
|
||||
username: '',
|
||||
email: '',
|
||||
full_name: '',
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
fetchUsers()
|
||||
}, [])
|
||||
|
||||
const fetchUsers = async () => {
|
||||
try {
|
||||
const response = await axios.get('/api/users/')
|
||||
setUsers(response.data)
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch users:', error)
|
||||
}
|
||||
}
|
||||
|
||||
const handleOpenDialog = (user?: User) => {
|
||||
if (user) {
|
||||
setEditingUser(user)
|
||||
setFormData({
|
||||
username: user.username,
|
||||
email: user.email,
|
||||
full_name: user.full_name || '',
|
||||
})
|
||||
} else {
|
||||
setEditingUser(null)
|
||||
setFormData({
|
||||
username: '',
|
||||
email: '',
|
||||
full_name: '',
|
||||
})
|
||||
}
|
||||
setOpenDialog(true)
|
||||
}
|
||||
|
||||
const handleCloseDialog = () => {
|
||||
setOpenDialog(false)
|
||||
setEditingUser(null)
|
||||
setFormData({
|
||||
username: '',
|
||||
email: '',
|
||||
full_name: '',
|
||||
})
|
||||
}
|
||||
|
||||
const handleSubmit = async () => {
|
||||
try {
|
||||
if (editingUser) {
|
||||
await axios.put(`/api/users/${editingUser._id}`, formData)
|
||||
} else {
|
||||
await axios.post('/api/users/', formData)
|
||||
}
|
||||
fetchUsers()
|
||||
handleCloseDialog()
|
||||
} catch (error) {
|
||||
console.error('Failed to save user:', error)
|
||||
}
|
||||
}
|
||||
|
||||
const handleDelete = async (id: string) => {
|
||||
if (confirm('Are you sure you want to delete this user?')) {
|
||||
try {
|
||||
await axios.delete(`/api/users/${id}`)
|
||||
fetchUsers()
|
||||
} catch (error) {
|
||||
console.error('Failed to delete user:', error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Box>
|
||||
<Box display="flex" justifyContent="space-between" alignItems="center" mb={2}>
|
||||
<Typography variant="h4">
|
||||
Users
|
||||
</Typography>
|
||||
<Button
|
||||
variant="contained"
|
||||
startIcon={<AddIcon />}
|
||||
onClick={() => handleOpenDialog()}
|
||||
>
|
||||
Add User
|
||||
</Button>
|
||||
</Box>
|
||||
|
||||
<TableContainer component={Paper}>
|
||||
<Table>
|
||||
<TableHead>
|
||||
<TableRow>
|
||||
<TableCell>Username</TableCell>
|
||||
<TableCell>Email</TableCell>
|
||||
<TableCell>Full Name</TableCell>
|
||||
<TableCell>Created At</TableCell>
|
||||
<TableCell align="right">Actions</TableCell>
|
||||
</TableRow>
|
||||
</TableHead>
|
||||
<TableBody>
|
||||
{users.map((user) => (
|
||||
<TableRow key={user._id}>
|
||||
<TableCell>{user.username}</TableCell>
|
||||
<TableCell>{user.email}</TableCell>
|
||||
<TableCell>{user.full_name || '-'}</TableCell>
|
||||
<TableCell>
|
||||
{new Date(user.created_at).toLocaleDateString()}
|
||||
</TableCell>
|
||||
<TableCell align="right">
|
||||
<IconButton
|
||||
size="small"
|
||||
onClick={() => handleOpenDialog(user)}
|
||||
>
|
||||
<EditIcon />
|
||||
</IconButton>
|
||||
<IconButton
|
||||
size="small"
|
||||
onClick={() => handleDelete(user._id)}
|
||||
>
|
||||
<DeleteIcon />
|
||||
</IconButton>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</TableContainer>
|
||||
|
||||
<Dialog open={openDialog} onClose={handleCloseDialog} maxWidth="sm" fullWidth>
|
||||
<DialogTitle>
|
||||
{editingUser ? 'Edit User' : 'Add New User'}
|
||||
</DialogTitle>
|
||||
<DialogContent>
|
||||
<Stack spacing={2} sx={{ mt: 1 }}>
|
||||
<TextField
|
||||
label="Username"
|
||||
value={formData.username}
|
||||
onChange={(e) => setFormData({ ...formData, username: e.target.value })}
|
||||
fullWidth
|
||||
required
|
||||
/>
|
||||
<TextField
|
||||
label="Email"
|
||||
type="email"
|
||||
value={formData.email}
|
||||
onChange={(e) => setFormData({ ...formData, email: e.target.value })}
|
||||
fullWidth
|
||||
required
|
||||
/>
|
||||
<TextField
|
||||
label="Full Name"
|
||||
value={formData.full_name}
|
||||
onChange={(e) => setFormData({ ...formData, full_name: e.target.value })}
|
||||
fullWidth
|
||||
/>
|
||||
</Stack>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<Button onClick={handleCloseDialog}>Cancel</Button>
|
||||
<Button onClick={handleSubmit} variant="contained">
|
||||
{editingUser ? 'Update' : 'Create'}
|
||||
</Button>
|
||||
</DialogActions>
|
||||
</Dialog>
|
||||
</Box>
|
||||
)
|
||||
}
|
||||
|
||||
export default Users
|
||||
Reference in New Issue
Block a user