hive dashboard: an agent's name links to its terminal in the swarm UI
This commit is contained in:
parent
ccac38995d
commit
8ca6317356
1 changed files with 97 additions and 15 deletions
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;
|
||||
}
|
||||
Loading…
Reference in a new issue