feat(scenarios): add detail page, comfortable DescriptionList layout, and environment card refactor
- Add ScenarioDetailPage with DescriptionList, steps table, run/delete actions - Add /scenarios/:id route - Add i18n keys for scenario detail fields, steps columns, and 404 error - Add 'comfortable' and 'inline' layout variants to DescriptionList (with compact as default stacked) - Apply layout="comfortable" to session, environment, and scenario detail pages - Apply layout="compact" to EnvironmentsPage card DescriptionList - Refactor EnvironmentsPage card to use ContextMenu (view/edit/delete) with icons - Add ScenariosPage clickable rows, Play icon (primary) and Trash2 icon (danger) action buttons - Add Page.module.css sectionHeading and stepsSection utility classes - Fix Notification.tsx and Table.tsx formatting (prettier)
This commit is contained in:
1 parent
d342637eb6
commit
a5f87b904e
14 files changed
+275
-56
No files matched your search
@@ -91,11 +91,7 @@ export function CreateEnvironmentPage() {
|
||||
</div>
|
||||
|
||||
<div className={styles.formActions}>
|
||||
<Button
|
||||
type="button"
|
||||
variant="secondary"
|
||||
onClick={() => navigate('/environments')}
|
||||
>
|
||||
<Button type="button" variant="secondary" onClick={() => navigate('/environments')}>
|
||||
{t('environments.action_cancel')}
|
||||
</Button>
|
||||
<Button type="submit" loading={saving}>
|
||||
|
||||
@@ -41,7 +41,11 @@ export function EnvironmentDetailPage() {
|
||||
/>
|
||||
{env && (
|
||||
<div className={styles.toolbarActions}>
|
||||
<Button variant="secondary" size="sm" onClick={() => navigate(`/environments/${env.id}/edit`)}>
|
||||
<Button
|
||||
variant="secondary"
|
||||
size="sm"
|
||||
onClick={() => navigate(`/environments/${env.id}/edit`)}
|
||||
>
|
||||
<Pencil size={14} />
|
||||
{t('environments.action_edit')}
|
||||
</Button>
|
||||
@@ -68,6 +72,7 @@ export function EnvironmentDetailPage() {
|
||||
<>
|
||||
<div className={styles.detailMeta}>
|
||||
<DescriptionList
|
||||
layout="comfortable"
|
||||
items={[
|
||||
{ term: t('environments.field_id'), detail: env.id },
|
||||
{
|
||||
@@ -88,6 +93,7 @@ export function EnvironmentDetailPage() {
|
||||
<p className={styles.muted}>{t('environments.no_urls')}</p>
|
||||
) : (
|
||||
<DescriptionList
|
||||
layout="comfortable"
|
||||
items={Object.entries(env.urls)
|
||||
.filter(([, v]) => v)
|
||||
.map(([key, value]) => ({
|
||||
|
||||
@@ -15,32 +15,34 @@ function EnvironmentCard({ env, onDelete }: { env: Environment; onDelete: (id: n
|
||||
const header = (
|
||||
<div className={styles.envCardHeader}>
|
||||
<span className={styles.envCardName}>{env.name}</span>
|
||||
<div onClick={(e) => e.stopPropagation()}><ContextMenu
|
||||
align="right"
|
||||
trigger={
|
||||
<Button variant="ghost" size="sm" aria-label={t('environments.menu_label')}>
|
||||
<Settings size={14} />
|
||||
</Button>
|
||||
}
|
||||
items={[
|
||||
{
|
||||
label: t('environments.action_view'),
|
||||
icon: <ExternalLink size={14} />,
|
||||
onClick: () => navigate(`/environments/${env.id}`),
|
||||
},
|
||||
{
|
||||
label: t('environments.action_edit'),
|
||||
icon: <Pencil size={14} />,
|
||||
onClick: () => navigate(`/environments/${env.id}/edit`),
|
||||
},
|
||||
{
|
||||
label: t('environments.action_delete'),
|
||||
icon: <Trash2 size={14} />,
|
||||
variant: 'danger',
|
||||
onClick: () => onDelete(env.id),
|
||||
},
|
||||
]}
|
||||
/></div>
|
||||
<div onClick={(e) => e.stopPropagation()}>
|
||||
<ContextMenu
|
||||
align="right"
|
||||
trigger={
|
||||
<Button variant="ghost" size="sm" aria-label={t('environments.menu_label')}>
|
||||
<Settings size={14} />
|
||||
</Button>
|
||||
}
|
||||
items={[
|
||||
{
|
||||
label: t('environments.action_view'),
|
||||
icon: <ExternalLink size={14} />,
|
||||
onClick: () => navigate(`/environments/${env.id}`),
|
||||
},
|
||||
{
|
||||
label: t('environments.action_edit'),
|
||||
icon: <Pencil size={14} />,
|
||||
onClick: () => navigate(`/environments/${env.id}/edit`),
|
||||
},
|
||||
{
|
||||
label: t('environments.action_delete'),
|
||||
icon: <Trash2 size={14} />,
|
||||
variant: 'danger',
|
||||
onClick: () => onDelete(env.id),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -60,7 +62,11 @@ function EnvironmentCard({ env, onDelete }: { env: Environment; onDelete: (id: n
|
||||
onClick={() => navigate(`/environments/${env.id}`)}
|
||||
>
|
||||
{urlEntries.length > 0 && (
|
||||
<DescriptionList truncate items={urlEntries.map(([key, value]) => ({ term: key, detail: value }))} />
|
||||
<DescriptionList
|
||||
layout="compact"
|
||||
truncate
|
||||
items={urlEntries.map(([key, value]) => ({ term: key, detail: value }))}
|
||||
/>
|
||||
)}
|
||||
{urlEntries.length === 0 && (
|
||||
<p className={styles.envCardEmpty}>{t('environments.no_urls')}</p>
|
||||
|
||||
@@ -5,6 +5,17 @@
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
.sectionHeading {
|
||||
margin: var(--space-6) 0 var(--space-3);
|
||||
font-size: var(--font-size-md);
|
||||
font-weight: 600;
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
.stepsSection {
|
||||
margin-top: var(--space-2);
|
||||
}
|
||||
|
||||
.breadcrumbs {
|
||||
margin-bottom: var(--space-4);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useNavigate, useParams } from 'react-router-dom';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Play, Trash2 } from 'lucide-react';
|
||||
import { scenarios } from '../api';
|
||||
import type { Scenario, ScenarioStep } from '../api';
|
||||
import {
|
||||
Badge,
|
||||
Breadcrumbs,
|
||||
Button,
|
||||
Card,
|
||||
DescriptionList,
|
||||
Notification,
|
||||
Table,
|
||||
Timestamp,
|
||||
type TableColumn,
|
||||
} from '../ui';
|
||||
import styles from './Page.module.css';
|
||||
|
||||
const STEP_TYPE_VARIANT: Record<string, 'info' | 'warning' | 'success'> = {
|
||||
login: 'success',
|
||||
exec: 'info',
|
||||
sign: 'warning',
|
||||
};
|
||||
|
||||
export function ScenarioDetailPage() {
|
||||
const { t } = useTranslation();
|
||||
const { id } = useParams<{ id: string }>();
|
||||
const navigate = useNavigate();
|
||||
const [scenario, setScenario] = useState<(Scenario & { steps: ScenarioStep[] }) | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!id) return;
|
||||
scenarios
|
||||
.get(Number(id))
|
||||
.then(setScenario)
|
||||
.catch((err: Error) => setError(err.message))
|
||||
.finally(() => setLoading(false));
|
||||
}, [id]);
|
||||
|
||||
const handleRun = async () => {
|
||||
if (!scenario) return;
|
||||
await scenarios.run(scenario.id);
|
||||
};
|
||||
|
||||
const handleDelete = async () => {
|
||||
if (!scenario) return;
|
||||
await scenarios.remove(scenario.id);
|
||||
navigate('/scenarios');
|
||||
};
|
||||
|
||||
const stepColumns: TableColumn<ScenarioStep>[] = [
|
||||
{ key: 'order', header: t('scenarios.step_order'), render: (s) => s.order, width: 60 },
|
||||
{
|
||||
key: 'type',
|
||||
header: t('scenarios.step_type'),
|
||||
width: 90,
|
||||
render: (s) => <Badge variant={STEP_TYPE_VARIANT[s.type] ?? 'neutral'}>{s.type}</Badge>,
|
||||
},
|
||||
{ key: 'session', header: t('scenarios.step_session'), render: (s) => s.sessionName },
|
||||
{
|
||||
key: 'updated',
|
||||
header: t('scenarios.step_updated'),
|
||||
width: 140,
|
||||
render: (s) => <Timestamp value={s.updatedAt} />,
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className={styles.pageToolbar}>
|
||||
<Breadcrumbs
|
||||
items={[
|
||||
{ label: t('scenarios.title'), onClick: () => navigate('/scenarios') },
|
||||
{ label: scenario?.name ?? `#${id}` },
|
||||
]}
|
||||
/>
|
||||
{scenario && (
|
||||
<div className={styles.toolbarActions}>
|
||||
<Button size="sm" onClick={handleRun}>
|
||||
<Play size={14} />
|
||||
{t('scenarios.action_run')}
|
||||
</Button>
|
||||
<Button variant="danger" size="sm" onClick={handleDelete}>
|
||||
<Trash2 size={14} />
|
||||
{t('scenarios.action_delete')}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{error && (
|
||||
<Notification
|
||||
variant="error"
|
||||
title={error.startsWith('404') ? t('errors.not_found') : undefined}
|
||||
>
|
||||
{error.startsWith('404') ? t('errors.not_found_scenario', { id }) : error}
|
||||
</Notification>
|
||||
)}
|
||||
{loading && <p className={styles.muted}>{t('scenarios.loading')}</p>}
|
||||
|
||||
{scenario && (
|
||||
<>
|
||||
<Card>
|
||||
<DescriptionList
|
||||
layout="comfortable"
|
||||
items={[
|
||||
{ term: t('scenarios.field_id'), detail: scenario.id },
|
||||
{ term: t('scenarios.field_name'), detail: scenario.name },
|
||||
{ term: t('scenarios.field_steps'), detail: scenario.steps.length },
|
||||
{
|
||||
term: t('scenarios.field_created'),
|
||||
detail: <Timestamp value={scenario.createdAt} />,
|
||||
},
|
||||
{
|
||||
term: t('scenarios.field_updated'),
|
||||
detail: <Timestamp value={scenario.updatedAt} />,
|
||||
},
|
||||
]}
|
||||
/>
|
||||
</Card>
|
||||
|
||||
{scenario.steps.length > 0 && (
|
||||
<div className={styles.stepsSection}>
|
||||
<h2 className={styles.sectionHeading}>{t('scenarios.steps_heading')}</h2>
|
||||
<Table
|
||||
columns={stepColumns}
|
||||
data={scenario.steps}
|
||||
rowKey={(s) => s.id}
|
||||
loading={false}
|
||||
emptyMessage=""
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Play, Trash2 } from 'lucide-react';
|
||||
import { scenarios } from '../api';
|
||||
import type { Scenario } from '../api';
|
||||
import { Breadcrumbs, Button, Table, type TableColumn, Timestamp } from '../ui';
|
||||
@@ -7,6 +9,7 @@ import styles from './Page.module.css';
|
||||
|
||||
export function ScenariosPage() {
|
||||
const { t } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
const [items, setItems] = useState<Scenario[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
@@ -45,15 +48,20 @@ export function ScenariosPage() {
|
||||
{
|
||||
key: 'actions',
|
||||
header: '',
|
||||
width: 140,
|
||||
width: 100,
|
||||
align: 'right',
|
||||
render: (s) => (
|
||||
<span style={{ display: 'inline-flex', gap: 6 }}>
|
||||
<Button size="sm" onClick={() => handleRun(s.id)}>
|
||||
{t('scenarios.action_run')}
|
||||
<Button size="sm" title={t('scenarios.action_run')} onClick={() => handleRun(s.id)}>
|
||||
<Play size={14} />
|
||||
</Button>
|
||||
<Button variant="secondary" size="sm" onClick={() => handleDelete(s.id)}>
|
||||
{t('scenarios.action_delete')}
|
||||
<Button
|
||||
variant="danger"
|
||||
size="sm"
|
||||
title={t('scenarios.action_delete')}
|
||||
onClick={() => handleDelete(s.id)}
|
||||
>
|
||||
<Trash2 size={14} />
|
||||
</Button>
|
||||
</span>
|
||||
),
|
||||
@@ -72,6 +80,7 @@ export function ScenariosPage() {
|
||||
emptyMessage={t('scenarios.empty')}
|
||||
pageSize={10}
|
||||
pageSizeOptions={[10, 25, 50]}
|
||||
onRowClick={(s) => navigate(`/scenarios/${s.id}`)}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -60,6 +60,7 @@ export function SessionDetailPage() {
|
||||
{session && (
|
||||
<Card>
|
||||
<DescriptionList
|
||||
layout="comfortable"
|
||||
items={[
|
||||
{ term: t('sessions.field_id'), detail: session.id },
|
||||
{ term: t('sessions.field_name'), detail: session.sessionName },
|
||||
@@ -71,7 +72,10 @@ export function SessionDetailPage() {
|
||||
</Badge>
|
||||
),
|
||||
},
|
||||
{ term: t('sessions.field_token'), detail: <code className={styles.codeInline}>{session.token}</code> },
|
||||
{
|
||||
term: t('sessions.field_token'),
|
||||
detail: <code className={styles.codeInline}>{session.token}</code>,
|
||||
},
|
||||
{
|
||||
term: t('sessions.field_lastUsed'),
|
||||
detail: session.lastUsedAt ? <Timestamp value={session.lastUsedAt} /> : '—',
|
||||
|
||||
@@ -39,9 +39,7 @@ export function SessionsPage() {
|
||||
key: 'status',
|
||||
header: t('sessions.col_status'),
|
||||
width: 100,
|
||||
render: (s) => (
|
||||
<Badge variant={s.status === 'open' ? 'success' : 'error'}>{s.status}</Badge>
|
||||
),
|
||||
render: (s) => <Badge variant={s.status === 'open' ? 'success' : 'error'}>{s.status}</Badge>,
|
||||
},
|
||||
{
|
||||
key: 'lastUsed',
|
||||
|
||||
Reference in new issue
Block a user