mirror of
https://github.com/jhd3197/ServerKit.git
synced 2026-12-01 20:55:16 +09:00
feat(frontend): icon-first permission level picker with info tooltips
Each level card now shows an illustration, title and allowed/blocked capability icons; the full explanation moved into an (i) tooltip. The enforced-by-agent note is a single compact line. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
89cb315353
commit
be1968746f
6 files changed
+236
-24
No files matched your search
@@ -0,0 +1,49 @@
|
||||
// Small inline illustrations for the permission-level cards. They use
|
||||
// currentColor plus the panel accent variables, so they follow the theme.
|
||||
const common = {
|
||||
viewBox: '0 0 96 56',
|
||||
height: 56,
|
||||
'aria-hidden': true,
|
||||
focusable: 'false',
|
||||
fill: 'none',
|
||||
stroke: 'currentColor',
|
||||
strokeWidth: 2,
|
||||
strokeLinecap: 'round',
|
||||
strokeLinejoin: 'round',
|
||||
};
|
||||
|
||||
const Monitor = () => (
|
||||
<svg {...common}>
|
||||
<path d="M8 24c9-12 21-18 40-18s31 6 40 18c-9 12-21 18-40 18S17 36 8 24z" opacity=".45" />
|
||||
<circle cx="48" cy="24" r="9" opacity=".45" />
|
||||
<path d="M4 48h22l6-10 8 16 7-12 5 6h40" stroke="var(--accent, currentColor)" />
|
||||
</svg>
|
||||
);
|
||||
|
||||
const Protect = () => (
|
||||
<svg {...common}>
|
||||
<path d="M48 4l28 8v16c0 13-10 21-28 26-18-5-28-13-28-26V12z" opacity=".45" />
|
||||
<path d="M34 22h28M34 30h28M34 38h28M48 22v8M41 30v8M55 30v8" opacity=".5" />
|
||||
<path d="M39 29l7 7 13-14" stroke="var(--accent, currentColor)" strokeWidth={3} />
|
||||
</svg>
|
||||
);
|
||||
|
||||
const Full = () => (
|
||||
<svg {...common}>
|
||||
<rect x="8" y="6" width="80" height="44" rx="5" opacity=".45" />
|
||||
<path d="M8 16h80" opacity=".45" />
|
||||
<path d="M16 26l7 6-7 6" stroke="var(--accent, currentColor)" />
|
||||
<path d="M28 40h10" opacity=".5" />
|
||||
<circle cx="62" cy="31" r="6" stroke="var(--accent, currentColor)" />
|
||||
<path d="M68 31h16M78 31v6M84 31v4" stroke="var(--accent, currentColor)" />
|
||||
</svg>
|
||||
);
|
||||
|
||||
const ILLUSTRATIONS = { monitor: Monitor, protect: Protect, full: Full };
|
||||
|
||||
const LevelIllustration = ({ level }) => {
|
||||
const Svg = ILLUSTRATIONS[level] || Monitor;
|
||||
return <Svg />;
|
||||
};
|
||||
|
||||
export default LevelIllustration;
|
||||
@@ -5670,6 +5670,8 @@
|
||||
"agentFound": "Agent found",
|
||||
"agentPairedSuccessfully": "Agent paired",
|
||||
"autoDetectedFromAgentOptional": "Auto-detected from agent (optional)",
|
||||
"capAllowed": "allowed",
|
||||
"capBlocked": "blocked",
|
||||
"clearSelection": "Clear selection",
|
||||
"confirmThisFingerprintMatchesTheOne": "Confirm this fingerprint matches the one shown by the agent before continuing.",
|
||||
"connectionString": "Connection string",
|
||||
@@ -5704,10 +5706,11 @@
|
||||
"lastSeen": "Last seen",
|
||||
"leaveBlankToUseTheAgent": "Leave blank to use the agent's hostname.",
|
||||
"levelColumn": "Level",
|
||||
"levelEnforcedByAgent": "The level is enforced by the agent and can only be changed on the server itself, with",
|
||||
"levelEnforcedShort": "Enforced on the server by the agent. Change with",
|
||||
"levelFull": "Full",
|
||||
"levelFullCan": "Everything the agent supports: Docker, files, terminal, packages, services and more.",
|
||||
"levelFullCannot": "No restrictions. Choose this only for servers you want this panel to fully manage.",
|
||||
"levelInfo": "What can {{level}} do?",
|
||||
"levelMonitor": "Monitor",
|
||||
"levelMonitorCan": "Reports CPU, memory, disk and service health (web server, PHP-FPM, database) to this panel.",
|
||||
"levelMonitorCannot": "Cannot run commands, open a terminal or change anything. The panel cannot send it any instructions.",
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { useState, useEffect, useCallback, useMemo, useId } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { ChevronRight, Folder, Plus, RefreshCw, Server as ServerLucideIcon, X } from 'lucide-react';
|
||||
import { Ban, ChevronRight, Container, Cpu, Database, Flame, Folder, HardDrive, Info, Lock, MemoryStick, Plus, RefreshCw, Server as ServerLucideIcon, Terminal, X } from 'lucide-react';
|
||||
import { Tooltip, TooltipTrigger, TooltipContent } from '@/components/ui/tooltip';
|
||||
import LevelIllustration from '../components/servers/LevelIllustrations';
|
||||
import api from '../services/api';
|
||||
import { useToast } from '../contexts/useToast.js';
|
||||
import EmptyState from '../components/EmptyState';
|
||||
@@ -30,7 +32,7 @@ import { t } from '../i18n/t';
|
||||
import { toastError } from '@/utils/errorMessage';
|
||||
import { formatDate } from '@/utils/intl';
|
||||
import {
|
||||
DEFAULT_LEVEL, PERMISSION_LEVELS, buildInstallCommands, levelKind, serverHealth,
|
||||
DEFAULT_LEVEL, PERMISSION_LEVELS, buildInstallCommands, levelAllows, levelKind, serverHealth,
|
||||
} from '@/utils/agentPermissionLevel';
|
||||
|
||||
// Radix Select items cannot use '' — stands in for "no group".
|
||||
@@ -820,6 +822,19 @@ const healthLabel = (code) => {
|
||||
}
|
||||
};
|
||||
|
||||
const CAPABILITY_ICONS = {
|
||||
cpu: [Cpu, 'CPU'],
|
||||
memory: [MemoryStick, 'Memory'],
|
||||
disk: [HardDrive, 'Disk'],
|
||||
services: [ServerLucideIcon, 'Web server and PHP'],
|
||||
database: [Database, 'Database'],
|
||||
firewall: [Flame, 'Firewall'],
|
||||
ban: [Ban, 'Ban (fail2ban, CrowdSec)'],
|
||||
terminal: [Terminal, 'Terminal'],
|
||||
docker: [Container, 'Docker'],
|
||||
files: [Folder, 'Files'],
|
||||
};
|
||||
|
||||
const LevelPicker = ({ value, onChange }) => {
|
||||
const { t } = useTranslation();
|
||||
const copy = {
|
||||
@@ -836,24 +851,59 @@ const LevelPicker = ({ value, onChange }) => {
|
||||
cannot: t('app.servers.levelFullCannot', 'No restrictions. Choose this only for servers you want this panel to fully manage.'),
|
||||
},
|
||||
};
|
||||
const onKeyDown = (e, level) => {
|
||||
if (e.key === ' ' || e.key === 'Enter') {
|
||||
e.preventDefault();
|
||||
onChange(level);
|
||||
}
|
||||
};
|
||||
return (
|
||||
<div className="form-group">
|
||||
<span className="form-label" id="add-server-level-label">{t('app.servers.permissionLevel', 'Permission level')}</span>
|
||||
<div className="level-picker" role="radiogroup" aria-labelledby="add-server-level-label">
|
||||
{PERMISSION_LEVELS.map((level) => (
|
||||
<Button variant="unstyled" type="button" key={level} role="radio"
|
||||
aria-checked={value === level}
|
||||
className={`level-picker__opt${value === level ? ' is-active' : ''}`}
|
||||
onClick={() => onChange(level)}
|
||||
>
|
||||
<span className="level-picker__head">{levelLabel(level)}</span>
|
||||
<span className="level-picker__desc">{copy[level].can}</span>
|
||||
<span className="level-picker__desc">{copy[level].cannot}</span>
|
||||
</Button>
|
||||
<div key={level} className="level-picker__cell">
|
||||
<div role="radio" tabIndex={0}
|
||||
aria-checked={value === level}
|
||||
className={`level-picker__opt${value === level ? ' is-active' : ''}`}
|
||||
onClick={() => onChange(level)}
|
||||
onKeyDown={(e) => onKeyDown(e, level)}
|
||||
>
|
||||
<span className="level-picker__art"><LevelIllustration level={level} /></span>
|
||||
<span className="level-picker__head">{levelLabel(level)}</span>
|
||||
<span className="level-picker__caps">
|
||||
{Object.entries(CAPABILITY_ICONS).map(([cap, [Icon, label]]) => {
|
||||
const allowed = levelAllows(level, cap);
|
||||
const text = `${label}: ${allowed ? t('app.servers.capAllowed', 'allowed') : t('app.servers.capBlocked', 'blocked')}`;
|
||||
return (
|
||||
<span key={cap} role="img" aria-label={text} title={text}
|
||||
className={`level-picker__cap${allowed ? '' : ' is-blocked'}`}>
|
||||
<Icon size={16} aria-hidden="true" />
|
||||
</span>
|
||||
);
|
||||
})}
|
||||
</span>
|
||||
</div>
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Button variant="unstyled" type="button" className="level-picker__info"
|
||||
aria-label={t('app.servers.levelInfo', 'What can {{level}} do?', { level: levelLabel(level) })}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
<Info size={14} aria-hidden="true" />
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="top" align="end" className="level-picker__tip">
|
||||
<span>{copy[level].can}</span>
|
||||
<span>{copy[level].cannot}</span>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<span className="form-hint">
|
||||
{t('app.servers.levelEnforcedByAgent', 'The level is enforced by the agent and can only be changed on the server itself, with')}
|
||||
<span className="form-hint level-picker__note">
|
||||
<Lock size={12} aria-hidden="true" />
|
||||
{t('app.servers.levelEnforcedShort', 'Enforced on the server by the agent. Change with')}
|
||||
{' '}<code>{SET_HINT}</code>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@@ -2584,42 +2584,124 @@
|
||||
// Permission-level picker in the Add Server drawer
|
||||
.level-picker {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
gap: $space-2;
|
||||
|
||||
@media (max-width: 560px) {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
// The (i) button is a sibling of the radio card, not nested in it.
|
||||
&__cell {
|
||||
position: relative;
|
||||
display: flex;
|
||||
}
|
||||
|
||||
&__opt {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: $space-1;
|
||||
align-items: center;
|
||||
gap: $space-2;
|
||||
padding: $space-3;
|
||||
text-align: start;
|
||||
text-align: center;
|
||||
color: $text-tertiary;
|
||||
background: $bg-card;
|
||||
border: 1px solid $border-subtle;
|
||||
border-radius: $radius-control;
|
||||
cursor: pointer;
|
||||
transition: border-color $transition-fast, background $transition-fast;
|
||||
transition: border-color $transition-fast, background $transition-fast, box-shadow $transition-fast;
|
||||
|
||||
&:hover {
|
||||
border-color: $border-active;
|
||||
background: $bg-elevated;
|
||||
}
|
||||
|
||||
&:focus-visible {
|
||||
outline: 2px solid var(--accent-dim);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
&.is-active {
|
||||
color: var(--accent);
|
||||
border-color: var(--accent-dim);
|
||||
background: var(--accent-bg);
|
||||
}
|
||||
}
|
||||
|
||||
&__art svg {
|
||||
display: block;
|
||||
width: auto;
|
||||
max-width: 100%;
|
||||
height: 56px;
|
||||
}
|
||||
|
||||
&__head {
|
||||
font-size: $text-xs;
|
||||
font-size: $text-sm;
|
||||
font-weight: $font-weight-semibold;
|
||||
color: $text-primary;
|
||||
}
|
||||
|
||||
&__desc {
|
||||
font-size: $text-xs;
|
||||
&__caps {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: center;
|
||||
gap: $space-1;
|
||||
}
|
||||
|
||||
&__cap {
|
||||
position: relative;
|
||||
display: inline-flex;
|
||||
color: $text-secondary;
|
||||
|
||||
.is-active & {
|
||||
color: var(--accent);
|
||||
}
|
||||
|
||||
&.is-blocked {
|
||||
color: $text-tertiary;
|
||||
opacity: .5;
|
||||
|
||||
&::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
inset: 50% -2px auto;
|
||||
height: 1.5px;
|
||||
background: currentColor;
|
||||
transform: rotate(-45deg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&__info {
|
||||
position: absolute;
|
||||
top: $space-1;
|
||||
inset-inline-end: $space-1;
|
||||
display: inline-flex;
|
||||
padding: $space-1;
|
||||
color: $text-tertiary;
|
||||
line-height: 1.45;
|
||||
background: none;
|
||||
border: 0;
|
||||
border-radius: 50%;
|
||||
cursor: pointer;
|
||||
|
||||
&:hover,
|
||||
&:focus-visible {
|
||||
color: $text-primary;
|
||||
}
|
||||
}
|
||||
|
||||
&__tip {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
max-width: 260px;
|
||||
white-space: normal;
|
||||
}
|
||||
|
||||
&__note {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: $space-1;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { buildInstallCommands, normalizeLevel, serverHealth } from '../agentPermissionLevel.js';
|
||||
import { buildInstallCommands, CAPABILITIES, levelAllows, normalizeLevel, serverHealth } from '../agentPermissionLevel.js';
|
||||
|
||||
const NOW = Date.parse('2026-01-01T12:00:00Z');
|
||||
const ago = (s) => new Date(NOW - s * 1000).toISOString();
|
||||
@@ -26,3 +26,13 @@ test('health combines status, report age and checks', () => {
|
||||
assert.equal(serverHealth({ ...base, status: 'offline' }, NOW).kind, 'red');
|
||||
assert.equal(serverHealth({ status: 'pending' }, NOW).code, 'pending');
|
||||
});
|
||||
|
||||
test('capability matrix per level', () => {
|
||||
const blocked = (level) => CAPABILITIES.filter((c) => !levelAllows(level, c));
|
||||
assert.deepEqual(blocked('monitor'), ['firewall', 'ban', 'terminal', 'docker', 'files']);
|
||||
assert.deepEqual(blocked('protect'), ['terminal', 'docker', 'files']);
|
||||
assert.deepEqual(blocked('full'), []);
|
||||
assert.equal(levelAllows('protect', 'firewall'), true);
|
||||
assert.equal(levelAllows('protect', 'ban'), true);
|
||||
assert.equal(levelAllows('bogus', 'terminal'), false);
|
||||
});
|
||||
@@ -51,3 +51,21 @@ export function serverHealth(server, now = Date.now()) {
|
||||
if (degraded.length) return { kind: 'amber', code: 'degraded', failing, degraded };
|
||||
return { kind: 'green', code: 'healthy', failing, degraded };
|
||||
}
|
||||
|
||||
// What each level lets the panel do on a server. Mirrors
|
||||
// backend/app/services/permission_levels.py: monitor is report-only, protect
|
||||
// adds the PROTECT_ACTIONS (firewall, fail2ban/CrowdSec, Cloudflare origin
|
||||
// lock), full is everything.
|
||||
export const CAPABILITIES = ['cpu', 'memory', 'disk', 'services', 'database', 'firewall', 'ban', 'terminal', 'docker', 'files'];
|
||||
const HEALTH = ['cpu', 'memory', 'disk', 'services', 'database'];
|
||||
const PROTECT = [...HEALTH, 'firewall', 'ban'];
|
||||
|
||||
export const LEVEL_CAPABILITIES = {
|
||||
monitor: HEALTH,
|
||||
protect: PROTECT,
|
||||
full: CAPABILITIES,
|
||||
};
|
||||
|
||||
export function levelAllows(level, capability) {
|
||||
return (LEVEL_CAPABILITIES[normalizeLevel(level) || DEFAULT_LEVEL] || []).includes(capability);
|
||||
}
|
||||
Reference in new issue
Block a user