Watch
0
0
Fork
You've already forked hyperhive
0
hyperhive/frontend/packages/dashboard/src/agent-page.js

26 lines
1 KiB
JavaScript

// 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;
}