Move Tailscale, Semaphore, and Gitea to their own top-level pages
Same move as Docker: each was buried inside the generic Integrations
browsing view, sharing one "pick any integration" dropdown across six
unrelated types. Give them dedicated pages instead.
New web/src/pages/{Tailscale,Semaphore,Gitea}.tsx each reuse the
existing, unchanged API routes and adapters (no server changes) with
their own integration picker scoped to just that type. Added matching
nav items (Tailscale, Semaphore, Gitea, right after Docker) and routes.
Removed the corresponding state/handlers/tables from Integrations.tsx
entirely (374 lines). Adding, editing, enabling/disabling, and
deleting each credential itself still happens under Integrations ->
Manage integrations, same as Proxmox and Synology, which stay on the
Integrations page. Selecting one of these three types in Integrations'
generic browsing dropdown now points to its new page instead of
rendering a table there too.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
35afcc4a37
commit
8fef68c27a
7 files changed
+646
-382
No files matched your search
@@ -0,0 +1,204 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import {
|
||||
api,
|
||||
type CurrentUser,
|
||||
type IntegrationSummary,
|
||||
type SemaphoreTemplate,
|
||||
type SemaphoreTemplatesResponse,
|
||||
} from "../api/client";
|
||||
import { formatDateTime } from "../utils/date";
|
||||
|
||||
function semaphoreStatusBadge(template: SemaphoreTemplate) {
|
||||
const status = template.lastTask?.status;
|
||||
if (!status) return <span className="badge bg-secondary-lt text-secondary">Never run</span>;
|
||||
switch (status) {
|
||||
case "success":
|
||||
return <span className="badge bg-green-lt text-green">Success</span>;
|
||||
case "error":
|
||||
return <span className="badge bg-red-lt text-red">Failed</span>;
|
||||
case "stopped":
|
||||
return <span className="badge bg-secondary-lt text-secondary">Stopped</span>;
|
||||
case "rejected":
|
||||
return <span className="badge bg-secondary-lt text-secondary">Rejected</span>;
|
||||
case "waiting":
|
||||
case "starting":
|
||||
case "waiting_confirmation":
|
||||
case "confirmed":
|
||||
return <span className="badge bg-yellow-lt text-yellow">Queued</span>;
|
||||
case "running":
|
||||
case "stopping":
|
||||
return <span className="badge bg-blue-lt text-blue">Running</span>;
|
||||
default:
|
||||
return <span className="badge bg-secondary-lt text-secondary">{status}</span>;
|
||||
}
|
||||
}
|
||||
|
||||
export default function Semaphore({ user }: { user: CurrentUser }) {
|
||||
const canEdit = user.role === "admin" || user.role === "operator";
|
||||
|
||||
const [integrations, setIntegrations] = useState<IntegrationSummary[] | null>(null);
|
||||
const [selectedId, setSelectedId] = useState<number | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
const [data, setData] = useState<SemaphoreTemplatesResponse | null>(null);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [runningTemplate, setRunningTemplate] = useState<number | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
api.integrations
|
||||
.list()
|
||||
.then((res) => {
|
||||
const semaphoreIntegrations = res.integrations.filter((i) => i.type === "semaphore");
|
||||
setIntegrations(semaphoreIntegrations);
|
||||
if (!selectedId && semaphoreIntegrations.length > 0) setSelectedId(semaphoreIntegrations[0].id);
|
||||
})
|
||||
.catch((err) => setError(err instanceof Error ? err.message : String(err)));
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
|
||||
const selected = integrations?.find((i) => i.id === selectedId) ?? null;
|
||||
|
||||
function loadTemplates(id: number) {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
api.integrations.semaphore
|
||||
.templates(id)
|
||||
.then((res) => setData(res))
|
||||
.catch((err) => setError(err instanceof Error ? err.message : String(err)))
|
||||
.finally(() => setLoading(false));
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (selected?.enabled) {
|
||||
loadTemplates(selected.id);
|
||||
} else {
|
||||
setData(null);
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [selectedId]);
|
||||
|
||||
async function runTemplate(t: SemaphoreTemplate) {
|
||||
if (!selectedId) return;
|
||||
if (!confirm(`Run "${t.name}" now?`)) return;
|
||||
setRunningTemplate(t.id);
|
||||
setError(null);
|
||||
try {
|
||||
await api.integrations.semaphore.run(selectedId, t.projectId, t.id);
|
||||
loadTemplates(selectedId);
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : String(err));
|
||||
} finally {
|
||||
setRunningTemplate(null);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<h2 className="page-title mb-3">Semaphore</h2>
|
||||
{error && <div className="alert alert-danger">{error}</div>}
|
||||
|
||||
{integrations?.length === 0 ? (
|
||||
<div className="card">
|
||||
<div className="card-body text-secondary">
|
||||
No Semaphore integration configured yet.{" "}
|
||||
<Link to="/integrations">Add one under Integrations</Link>.
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
{integrations && integrations.length > 1 && (
|
||||
<div className="mb-3" style={{ maxWidth: 320 }}>
|
||||
<select
|
||||
className="form-select"
|
||||
value={selectedId ?? ""}
|
||||
onChange={(e) => setSelectedId(Number(e.target.value))}
|
||||
>
|
||||
{integrations.map((i) => (
|
||||
<option key={i.id} value={i.id} disabled={!i.enabled}>
|
||||
{i.name}
|
||||
{!i.enabled ? " — disabled" : ""}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{selected && !selected.enabled ? (
|
||||
<div className="card">
|
||||
<div className="card-body text-secondary">
|
||||
"{selected.name}" is disabled. Enable it under Integrations → Manage integrations to see its
|
||||
templates.
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className="card">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">
|
||||
Templates
|
||||
{data && data.summary.failing > 0 && (
|
||||
<span className="text-red fw-normal ms-2">{data.summary.failing} failing</span>
|
||||
)}
|
||||
</h3>
|
||||
<div className="card-actions">
|
||||
<button
|
||||
className="btn btn-sm btn-outline-secondary"
|
||||
onClick={() => selected && loadTemplates(selected.id)}
|
||||
disabled={loading}
|
||||
>
|
||||
{loading ? "Refreshing…" : "Refresh"}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="table-responsive">
|
||||
<table className="table table-vcenter card-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Template</th>
|
||||
<th>Project</th>
|
||||
<th>Last run</th>
|
||||
<th>Status</th>
|
||||
{canEdit && <th className="w-1">Actions</th>}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{data?.templates.map((t) => (
|
||||
<tr key={`${t.projectId}:${t.id}`}>
|
||||
<td>{t.name}</td>
|
||||
<td className="text-secondary">{t.projectName}</td>
|
||||
<td className="text-secondary">
|
||||
{t.lastTask
|
||||
? formatDateTime(new Date(t.lastTask.end ?? t.lastTask.start ?? t.lastTask.created ?? ""))
|
||||
: "—"}
|
||||
</td>
|
||||
<td>{semaphoreStatusBadge(t)}</td>
|
||||
{canEdit && (
|
||||
<td>
|
||||
<button
|
||||
className="btn btn-sm btn-primary"
|
||||
onClick={() => runTemplate(t)}
|
||||
disabled={runningTemplate === t.id}
|
||||
>
|
||||
{runningTemplate === t.id ? "Starting…" : "Run"}
|
||||
</button>
|
||||
</td>
|
||||
)}
|
||||
</tr>
|
||||
))}
|
||||
{data?.templates.length === 0 && (
|
||||
<tr>
|
||||
<td colSpan={canEdit ? 5 : 4} className="text-secondary text-center">
|
||||
No templates found across any project.
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user