hive dashboard: an agent's name links to its terminal in the swarm UI
This commit is contained in:
parent
ccac38995d
commit
8ca6317356
4 changed files with 97 additions and 15 deletions
|
|
@ -176,6 +176,11 @@ falls back to the dimmed hyperhive mark (`/favicon.svg`). The card
|
||||||
body sits to the right with three stacked lines
|
body sits to the right with three stacked lines
|
||||||
(`assets/agents.js::renderContainers`).
|
(`assets/agents.js::renderContainers`).
|
||||||
|
|
||||||
|
The agent's name links to its terminal in the swarm UI
|
||||||
|
(`<swarm_public_url>/agents/<name>/terminal`), and the "needs login" badge to the
|
||||||
|
swarm UI's agent list, where the agent logs in again. The agent has no page of its
|
||||||
|
own, so a hive without a swarm domain shows both as plain text.
|
||||||
|
|
||||||
<!-- vale write-good.Passive = NO -->
|
<!-- vale write-good.Passive = NO -->
|
||||||
|
|
||||||
**Icon layout + load strategy:** the `<img>` is absolutely
|
**Icon layout + load strategy:** the `<img>` is absolutely
|
||||||
|
|
|
||||||
26
frontend/packages/dashboard/src/agent-page.js
Normal file
26
frontend/packages/dashboard/src/agent-page.js
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
// Where an agent's name in the container list leads: its terminal in the swarm
|
||||||
|
// UI. The agent has no page of its own to open, so a hive without a swarm
|
||||||
|
// domain (`swarm_public_url` unset in the dashboard state) has no link to give.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {{ swarm_public_url?: string | null } | null | undefined} state the dashboard state
|
||||||
|
* @param {string} name the agent's name
|
||||||
|
* @returns {string | null} the swarm UI URL of the agent's terminal, or null
|
||||||
|
*/
|
||||||
|
export function agentPageUrl(state, name) {
|
||||||
|
const base = state && state.swarm_public_url;
|
||||||
|
if (!base) return null;
|
||||||
|
return `${base.replace(/\/+$/, "")}/agents/${encodeURIComponent(name)}/terminal`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Where "needs login" leads: the swarm UI's agent list, where an agent is logged
|
||||||
|
* in again. Null with no swarm domain.
|
||||||
|
*
|
||||||
|
* @param {{ swarm_public_url?: string | null } | null | undefined} state
|
||||||
|
* @returns {string | null}
|
||||||
|
*/
|
||||||
|
export function loginPageUrl(state) {
|
||||||
|
const base = state && state.swarm_public_url;
|
||||||
|
return base ? `${base.replace(/\/+$/, "")}/agents` : null;
|
||||||
|
}
|
||||||
|
|
@ -9,6 +9,7 @@ import { el } from "@hive/shared/dom.js";
|
||||||
import { themedConfirm, themedToast } from "@hive/shared/modal.js";
|
import { themedConfirm, themedToast } from "@hive/shared/modal.js";
|
||||||
import { h, render } from "preact";
|
import { h, render } from "preact";
|
||||||
import { JobqRollup } from "@hive/shared/jobq-rollup.js";
|
import { JobqRollup } from "@hive/shared/jobq-rollup.js";
|
||||||
|
import { agentPageUrl, loginPageUrl } from "./agent-page.js";
|
||||||
import { containersState } from "./state.js";
|
import { containersState } from "./state.js";
|
||||||
import { closeAllMenus } from "@hive/shared/hive-menu.js";
|
import { closeAllMenus } from "@hive/shared/hive-menu.js";
|
||||||
import "./agent-menu/hive-agent-menu.js"; // registers <hive-agent-menu> — side-effect import
|
import "./agent-menu/hive-agent-menu.js"; // registers <hive-agent-menu> — side-effect import
|
||||||
|
|
@ -258,6 +259,9 @@ function containerRowFingerprint(
|
||||||
// fetch for stable rows.
|
// fetch for stable rows.
|
||||||
function buildContainerLi(c, opts) {
|
function buildContainerLi(c, opts) {
|
||||||
const { pending, opRunning, selected, url, containerBase, s } = opts;
|
const { pending, opRunning, selected, url, containerBase, s } = opts;
|
||||||
|
// The agent has no page of its own; its name leads to its terminal in the swarm UI.
|
||||||
|
const pageUrl = agentPageUrl(s, c.name);
|
||||||
|
const loginUrl = loginPageUrl(s);
|
||||||
// A single `pending-running` class covers any active transient
|
// A single `pending-running` class covers any active transient
|
||||||
// badge state (see the pending-badge derivation comment in
|
// badge state (see the pending-badge derivation comment in
|
||||||
// renderContainers).
|
// renderContainers).
|
||||||
|
|
@ -318,11 +322,13 @@ function buildContainerLi(c, opts) {
|
||||||
// -- identity -------------------------------------------------------
|
// -- identity -------------------------------------------------------
|
||||||
const head = el("div", { class: "head" });
|
const head = el("div", { class: "head" });
|
||||||
head.append(
|
head.append(
|
||||||
el(
|
pageUrl
|
||||||
|
? el(
|
||||||
"a",
|
"a",
|
||||||
{ class: "name", href: url, target: "_blank", rel: "noopener" },
|
{ class: "name", href: pageUrl, target: "_blank", rel: "noopener" },
|
||||||
c.name,
|
c.name,
|
||||||
),
|
)
|
||||||
|
: el("span", { class: "name" }, c.name),
|
||||||
);
|
);
|
||||||
// Icon-only nav strip — populated async from the agent's own
|
// Icon-only nav strip — populated async from the agent's own
|
||||||
// `GET /api/dashboard-state` (via gateway when enabled, direct
|
// `GET /api/dashboard-state` (via gateway when enabled, direct
|
||||||
|
|
@ -474,17 +480,20 @@ function buildContainerLi(c, opts) {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
} else if (c.needs_login) {
|
} else if (c.needs_login) {
|
||||||
|
// Logging in again is on the swarm UI; without one the badge only says so.
|
||||||
head.append(
|
head.append(
|
||||||
el(
|
loginUrl
|
||||||
|
? el(
|
||||||
"a",
|
"a",
|
||||||
{
|
{
|
||||||
class: "hive-pill-sm badge-warn",
|
class: "hive-pill-sm badge-warn",
|
||||||
href: url,
|
href: loginUrl,
|
||||||
target: "_blank",
|
target: "_blank",
|
||||||
rel: "noopener",
|
rel: "noopener",
|
||||||
},
|
},
|
||||||
"needs login →",
|
"needs login →",
|
||||||
),
|
)
|
||||||
|
: el("span", { class: "hive-pill-sm badge-warn" }, "needs login"),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (c.paused) {
|
if (c.paused) {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,42 @@
|
||||||
|
// Where the hive dashboard's agent rows lead. Run by `npm test`.
|
||||||
|
import assert from "node:assert/strict";
|
||||||
|
import { test } from "node:test";
|
||||||
|
import { agentPageUrl, loginPageUrl } from "../../dashboard/src/agent-page.js";
|
||||||
|
|
||||||
|
test("an agent's name leads to its terminal in the swarm UI", () => {
|
||||||
|
const state = { swarm_public_url: "https://swarm.example" };
|
||||||
|
assert.equal(
|
||||||
|
agentPageUrl(state, "iris"),
|
||||||
|
"https://swarm.example/agents/iris/terminal",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("a trailing slash on the swarm address makes no double slash", () => {
|
||||||
|
const state = { swarm_public_url: "https://swarm.example/" };
|
||||||
|
assert.equal(
|
||||||
|
agentPageUrl(state, "iris"),
|
||||||
|
"https://swarm.example/agents/iris/terminal",
|
||||||
|
);
|
||||||
|
assert.equal(loginPageUrl(state), "https://swarm.example/agents");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("a name is escaped into the path", () => {
|
||||||
|
const state = { swarm_public_url: "https://swarm.example" };
|
||||||
|
assert.equal(
|
||||||
|
agentPageUrl(state, "a b/c"),
|
||||||
|
"https://swarm.example/agents/a%20b%2Fc/terminal",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("a hive without a swarm domain has no page to link", () => {
|
||||||
|
for (const state of [
|
||||||
|
null,
|
||||||
|
undefined,
|
||||||
|
{},
|
||||||
|
{ swarm_public_url: null },
|
||||||
|
{ swarm_public_url: "" },
|
||||||
|
]) {
|
||||||
|
assert.equal(agentPageUrl(state, "iris"), null);
|
||||||
|
assert.equal(loginPageUrl(state), null);
|
||||||
|
}
|
||||||
|
});
|
||||||
Loading…
Reference in a new issue