feat: Introduce job and service categorization for components, enhancing routing and display logic across the application
This commit is contained in:
@@ -26,7 +26,7 @@ export function ComponentCard({ component, health }: ComponentCardProps) {
|
||||
<div className="bg-[var(--card)] border border-[var(--border)] rounded-lg p-5">
|
||||
<div className="flex items-start justify-between mb-2">
|
||||
<Link
|
||||
to={`/component/${component.id}`}
|
||||
to={`/services/${component.id}`}
|
||||
className="text-base font-semibold hover:text-[var(--primary)] transition-colors"
|
||||
>
|
||||
{component.id}
|
||||
|
||||
@@ -1,34 +1,25 @@
|
||||
import { useMemo, useState } from "react"
|
||||
import { Link } from "react-router-dom"
|
||||
import { ArrowDown, ArrowUp, ArrowUpDown, Download, Play, RefreshCw, Square, Trash2 } from "lucide-react"
|
||||
import type { ComponentSummary, HealthStatus } from "@/types"
|
||||
import { useServiceAction, useToolAction } from "@/services/api/hooks"
|
||||
import { HealthBadge } from "./HealthBadge"
|
||||
import { ArrowDown, ArrowUp, ArrowUpDown, Plug, Unplug } from "lucide-react"
|
||||
import type { ComponentSummary } from "@/types"
|
||||
import { useToolAction } from "@/services/api/hooks"
|
||||
import { BehaviorBadge } from "./BehaviorBadge"
|
||||
import { StackBadge } from "./StackBadge"
|
||||
|
||||
interface ComponentTableProps {
|
||||
components: ComponentSummary[]
|
||||
statuses: HealthStatus[]
|
||||
}
|
||||
|
||||
type SortKey = "id" | "stack" | "behavior" | "status"
|
||||
type SortDir = "asc" | "desc"
|
||||
|
||||
function statusRank(s: HealthStatus | undefined, installed: boolean | null): number {
|
||||
if (s) {
|
||||
if (s.status === "down") return 0
|
||||
if (s.status === "up") return 3
|
||||
return 2
|
||||
}
|
||||
if (installed === false) return 1
|
||||
if (installed === true) return 3
|
||||
function installedRank(installed: boolean | null): number {
|
||||
if (installed === false) return 0
|
||||
if (installed === true) return 1
|
||||
return 2
|
||||
}
|
||||
|
||||
export function ComponentTable({ components, statuses }: ComponentTableProps) {
|
||||
const statusMap = useMemo(() => new Map(statuses.map((s) => [s.id, s])), [statuses])
|
||||
|
||||
export function ComponentTable({ components }: ComponentTableProps) {
|
||||
const [search, setSearch] = useState("")
|
||||
const [sortKey, setSortKey] = useState<SortKey>("id")
|
||||
const [sortDir, setSortDir] = useState<SortDir>("asc")
|
||||
@@ -63,12 +54,12 @@ export function ComponentTable({ components, statuses }: ComponentTableProps) {
|
||||
case "behavior":
|
||||
return dir * (a.behavior ?? "").localeCompare(b.behavior ?? "")
|
||||
case "status":
|
||||
return dir * (statusRank(statusMap.get(a.id), a.installed) - statusRank(statusMap.get(b.id), b.installed))
|
||||
return dir * (installedRank(a.installed) - installedRank(b.installed))
|
||||
default:
|
||||
return 0
|
||||
}
|
||||
})
|
||||
}, [filtered, sortKey, sortDir, statusMap])
|
||||
}, [filtered, sortKey, sortDir])
|
||||
|
||||
return (
|
||||
<div>
|
||||
@@ -97,7 +88,6 @@ export function ComponentTable({ components, statuses }: ComponentTableProps) {
|
||||
<ComponentRow
|
||||
key={comp.id}
|
||||
component={comp}
|
||||
health={statusMap.get(comp.id)}
|
||||
/>
|
||||
))}
|
||||
{sorted.length === 0 && (
|
||||
@@ -158,22 +148,17 @@ function InstalledBadge({ installed }: { installed: boolean }) {
|
||||
|
||||
function ComponentRow({
|
||||
component,
|
||||
health,
|
||||
}: {
|
||||
component: ComponentSummary
|
||||
health?: HealthStatus
|
||||
}) {
|
||||
const hasHttp = component.port != null
|
||||
const isTool = component.installed !== null
|
||||
const { mutate: serviceAction, isPending: servicePending } = useServiceAction()
|
||||
const { mutate: toolAction, isPending: toolPending } = useToolAction()
|
||||
const isDown = health?.status === "down"
|
||||
|
||||
return (
|
||||
<tr className="border-b border-[var(--border)] last:border-b-0 hover:bg-[var(--card)]/50 transition-colors">
|
||||
<td className="px-3 py-2.5">
|
||||
<Link
|
||||
to={`/component/${component.id}`}
|
||||
to={`/components/${component.id}`}
|
||||
className="font-medium hover:text-[var(--primary)] transition-colors"
|
||||
>
|
||||
{component.id}
|
||||
@@ -191,49 +176,14 @@ function ComponentRow({
|
||||
<BehaviorBadge behavior={component.behavior} />
|
||||
</td>
|
||||
<td className="px-3 py-2.5">
|
||||
{health ? (
|
||||
<HealthBadge status={health.status} latency={health.latency_ms} />
|
||||
) : hasHttp ? (
|
||||
<HealthBadge status="unknown" />
|
||||
) : isTool ? (
|
||||
{isTool ? (
|
||||
<InstalledBadge installed={component.installed!} />
|
||||
) : (
|
||||
<span className="text-[var(--muted)]">—</span>
|
||||
)}
|
||||
</td>
|
||||
<td className="px-3 py-2.5">
|
||||
{component.managed ? (
|
||||
<div className="flex items-center gap-1">
|
||||
{isDown && (
|
||||
<button
|
||||
onClick={() => serviceAction({ name: component.id, action: "start" })}
|
||||
disabled={servicePending}
|
||||
className="p-1 rounded hover:bg-green-800/30 text-green-400 transition-colors disabled:opacity-40"
|
||||
title="Start"
|
||||
>
|
||||
<Play size={14} />
|
||||
</button>
|
||||
)}
|
||||
<button
|
||||
onClick={() => serviceAction({ name: component.id, action: "restart" })}
|
||||
disabled={servicePending}
|
||||
className="p-1 rounded hover:bg-blue-800/30 text-blue-400 transition-colors disabled:opacity-40"
|
||||
title="Restart"
|
||||
>
|
||||
<RefreshCw size={14} />
|
||||
</button>
|
||||
{!isDown && (
|
||||
<button
|
||||
onClick={() => serviceAction({ name: component.id, action: "stop" })}
|
||||
disabled={servicePending}
|
||||
className="p-1 rounded hover:bg-red-800/30 text-red-400 transition-colors disabled:opacity-40"
|
||||
title="Stop"
|
||||
>
|
||||
<Square size={14} />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
) : isTool ? (
|
||||
{isTool ? (
|
||||
<div className="flex items-center gap-1">
|
||||
{component.installed ? (
|
||||
<button
|
||||
@@ -242,7 +192,7 @@ function ComponentRow({
|
||||
className="p-1 rounded hover:bg-red-800/30 text-red-400 transition-colors disabled:opacity-40"
|
||||
title="Uninstall from PATH"
|
||||
>
|
||||
<Trash2 size={14} />
|
||||
<Unplug size={14} />
|
||||
</button>
|
||||
) : (
|
||||
<button
|
||||
@@ -251,7 +201,7 @@ function ComponentRow({
|
||||
className="p-1 rounded hover:bg-green-800/30 text-green-400 transition-colors disabled:opacity-40"
|
||||
title="Install to PATH"
|
||||
>
|
||||
<Download size={14} />
|
||||
<Plug size={14} />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -46,7 +46,7 @@ function ScheduledRow({ job, health }: { job: ComponentSummary; health?: HealthS
|
||||
<tr className="border-b border-[var(--border)] last:border-b-0 hover:bg-[var(--card)]/50 transition-colors">
|
||||
<td className="px-3 py-2.5">
|
||||
<Link
|
||||
to={`/component/${job.id}`}
|
||||
to={`/jobs/${job.id}`}
|
||||
className="font-medium hover:text-[var(--primary)] transition-colors"
|
||||
>
|
||||
{job.id}
|
||||
|
||||
72
app/src/components/detail/ConfigPanel.tsx
Normal file
72
app/src/components/detail/ConfigPanel.tsx
Normal file
@@ -0,0 +1,72 @@
|
||||
import { useState } from "react"
|
||||
import { useNavigate } from "react-router-dom"
|
||||
import { useQueryClient } from "@tanstack/react-query"
|
||||
import { Check } from "lucide-react"
|
||||
import { apiClient } from "@/services/api/client"
|
||||
import type { ComponentDetail } from "@/types"
|
||||
import { ComponentFields } from "@/components/ComponentFields"
|
||||
|
||||
interface ConfigPanelProps {
|
||||
component: ComponentDetail
|
||||
configSection: "services" | "jobs" | "components"
|
||||
onRefetch: () => void
|
||||
}
|
||||
|
||||
export function ConfigPanel({ component, configSection, onRefetch }: ConfigPanelProps) {
|
||||
const navigate = useNavigate()
|
||||
const qc = useQueryClient()
|
||||
const [message, setMessage] = useState<{ type: "ok" | "error"; text: string } | null>(null)
|
||||
|
||||
const handleSave = async (compName: string, config: Record<string, unknown>) => {
|
||||
setMessage(null)
|
||||
try {
|
||||
await apiClient.put(`/config/${configSection}/${compName}`, { config })
|
||||
setMessage({ type: "ok", text: "Saved to castle.yaml" })
|
||||
onRefetch()
|
||||
qc.invalidateQueries({ queryKey: ["components"] })
|
||||
} catch (e: unknown) {
|
||||
const msg = e instanceof Error ? e.message : String(e)
|
||||
setMessage({ type: "error", text: msg })
|
||||
}
|
||||
}
|
||||
|
||||
const handleDelete = async (compName: string) => {
|
||||
try {
|
||||
await apiClient.delete(`/config/${configSection}/${compName}`)
|
||||
qc.invalidateQueries({ queryKey: ["components"] })
|
||||
navigate("/")
|
||||
} catch (e: unknown) {
|
||||
const msg = e instanceof Error ? e.message : String(e)
|
||||
setMessage({ type: "error", text: msg })
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
{message && (
|
||||
<div
|
||||
className={`mb-4 px-3 py-2 rounded text-sm ${
|
||||
message.type === "ok"
|
||||
? "bg-green-900/30 text-green-300 border border-green-800"
|
||||
: "bg-red-900/30 text-red-300 border border-red-800"
|
||||
}`}
|
||||
>
|
||||
<span className="flex items-center gap-1.5">
|
||||
{message.type === "ok" && <Check size={14} />}
|
||||
{message.text}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
<div className="bg-[var(--card)] border border-[var(--border)] rounded-lg p-5 mb-6">
|
||||
<h2 className="text-sm font-semibold text-[var(--muted)] uppercase tracking-wider mb-4">
|
||||
Configuration
|
||||
</h2>
|
||||
<ComponentFields
|
||||
component={component}
|
||||
onSave={handleSave}
|
||||
onDelete={handleDelete}
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
||||
37
app/src/components/detail/DetailHeader.tsx
Normal file
37
app/src/components/detail/DetailHeader.tsx
Normal file
@@ -0,0 +1,37 @@
|
||||
import { Link } from "react-router-dom"
|
||||
import { ArrowLeft } from "lucide-react"
|
||||
import { BehaviorBadge } from "@/components/BehaviorBadge"
|
||||
import { StackBadge } from "@/components/StackBadge"
|
||||
|
||||
interface DetailHeaderProps {
|
||||
backTo: string
|
||||
backLabel: string
|
||||
name: string
|
||||
behavior?: string | null
|
||||
stack?: string | null
|
||||
source?: string | null
|
||||
children?: React.ReactNode
|
||||
}
|
||||
|
||||
export function DetailHeader({ backTo, backLabel, name, behavior, stack, source, children }: DetailHeaderProps) {
|
||||
return (
|
||||
<>
|
||||
<Link to={backTo} className="text-[var(--primary)] hover:underline flex items-center gap-1 mb-6">
|
||||
<ArrowLeft size={16} /> {backLabel}
|
||||
</Link>
|
||||
|
||||
<div className="flex items-start justify-between mb-4">
|
||||
<h1 className="text-2xl font-bold">{name}</h1>
|
||||
{children}
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-3 mb-6">
|
||||
<BehaviorBadge behavior={behavior ?? null} />
|
||||
<StackBadge stack={stack ?? null} />
|
||||
{source && (
|
||||
<span className="text-sm text-[var(--muted)] font-mono">{source}</span>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
||||
46
app/src/components/detail/ServiceControls.tsx
Normal file
46
app/src/components/detail/ServiceControls.tsx
Normal file
@@ -0,0 +1,46 @@
|
||||
import { Play, RefreshCw, Square } from "lucide-react"
|
||||
import { useServiceAction } from "@/services/api/hooks"
|
||||
import type { HealthStatus } from "@/types"
|
||||
|
||||
interface ServiceControlsProps {
|
||||
name: string
|
||||
health?: HealthStatus
|
||||
}
|
||||
|
||||
export function ServiceControls({ name, health }: ServiceControlsProps) {
|
||||
const { mutate, isPending } = useServiceAction()
|
||||
const isDown = health?.status === "down"
|
||||
|
||||
return (
|
||||
<div className="flex items-center gap-1">
|
||||
{isDown && (
|
||||
<button
|
||||
onClick={() => mutate({ name, action: "start" })}
|
||||
disabled={isPending}
|
||||
className="p-1.5 rounded hover:bg-green-800/30 text-green-400 transition-colors disabled:opacity-40"
|
||||
title="Start"
|
||||
>
|
||||
<Play size={16} />
|
||||
</button>
|
||||
)}
|
||||
<button
|
||||
onClick={() => mutate({ name, action: "restart" })}
|
||||
disabled={isPending}
|
||||
className="p-1.5 rounded hover:bg-blue-800/30 text-blue-400 transition-colors disabled:opacity-40"
|
||||
title="Restart"
|
||||
>
|
||||
<RefreshCw size={16} />
|
||||
</button>
|
||||
{!isDown && (
|
||||
<button
|
||||
onClick={() => mutate({ name, action: "stop" })}
|
||||
disabled={isPending}
|
||||
className="p-1.5 rounded hover:bg-red-800/30 text-red-400 transition-colors disabled:opacity-40"
|
||||
title="Stop"
|
||||
>
|
||||
<Square size={16} />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
61
app/src/components/detail/SystemdPanel.tsx
Normal file
61
app/src/components/detail/SystemdPanel.tsx
Normal file
@@ -0,0 +1,61 @@
|
||||
import { useState } from "react"
|
||||
import { useSystemdUnit } from "@/services/api/hooks"
|
||||
import type { SystemdInfo } from "@/types"
|
||||
|
||||
interface SystemdPanelProps {
|
||||
name: string
|
||||
systemd: SystemdInfo
|
||||
}
|
||||
|
||||
export function SystemdPanel({ name, systemd }: SystemdPanelProps) {
|
||||
const [showUnit, setShowUnit] = useState(false)
|
||||
const { data: unitData } = useSystemdUnit(name, showUnit)
|
||||
|
||||
return (
|
||||
<div className="bg-[var(--card)] border border-[var(--border)] rounded-lg p-5 mb-6">
|
||||
<div className="flex items-center justify-between mb-1">
|
||||
<h2 className="text-sm font-semibold text-[var(--muted)] uppercase tracking-wider">
|
||||
Systemd
|
||||
</h2>
|
||||
<button
|
||||
onClick={() => setShowUnit((v) => !v)}
|
||||
className="text-xs text-[var(--primary)] hover:underline"
|
||||
>
|
||||
{showUnit ? "Hide unit file" : "View unit file"}
|
||||
</button>
|
||||
</div>
|
||||
<div className="grid grid-cols-2 gap-x-6 gap-y-2 text-sm mt-3">
|
||||
<span className="text-[var(--muted)]">Unit</span>
|
||||
<span className="font-mono">{systemd.unit_name}</span>
|
||||
<span className="text-[var(--muted)]">Path</span>
|
||||
<span className="font-mono">{systemd.unit_path}</span>
|
||||
{systemd.timer && (
|
||||
<>
|
||||
<span className="text-[var(--muted)]">Timer</span>
|
||||
<span>Active</span>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
{showUnit && unitData && (
|
||||
<div className="mt-4 space-y-3">
|
||||
<div>
|
||||
<span className="text-xs text-[var(--muted)] block mb-1">{systemd.unit_name}</span>
|
||||
<pre className="text-sm whitespace-pre-wrap bg-[var(--background)] rounded p-3 border border-[var(--border)] font-mono overflow-x-auto">
|
||||
{unitData.service}
|
||||
</pre>
|
||||
</div>
|
||||
{unitData.timer && (
|
||||
<div>
|
||||
<span className="text-xs text-[var(--muted)] block mb-1">
|
||||
{systemd.unit_name.replace(".service", ".timer")}
|
||||
</span>
|
||||
<pre className="text-sm whitespace-pre-wrap bg-[var(--background)] rounded p-3 border border-[var(--border)] font-mono overflow-x-auto">
|
||||
{unitData.timer}
|
||||
</pre>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user