import { useState } from 'react'; import { useEnvironmentId } from '@/react/hooks/useEnvironmentId'; import { baseHref } from '@/portainer/helpers/pathHelper'; import { terminalClose } from '@/portainer/services/terminal-window'; import { EnvironmentId } from '@/react/portainer/environments/types'; import { Alert } from '@@/Alert'; import { Button } from '@@/buttons'; import { Terminal, LINUX_SHELL_INIT_COMMANDS } from '@@/Terminal/Terminal'; import type { ShellState } from '@@/Terminal/Terminal'; export function KubectlShellView() { const environmentId = useEnvironmentId(); const [shellState, setShellState] = useState('idle'); return (
{shellState === 'connecting' && (
Loading Terminal...
)} {shellState === 'disconnected' && (
)}
); function onStateChange(state: ShellState) { if (state === 'disconnected') { terminalClose(); } setShellState(state); } function buildUrl(environmentId: EnvironmentId) { const params = { endpointId: environmentId, }; const wsProtocol = window.location.protocol === 'https:' ? 'wss://' : 'ws://'; const path = `${baseHref()}api/websocket/kubernetes-shell`; const base = path.startsWith('http') ? path.replace(/^https?:\/\//i, '') : window.location.host + path; const queryParams = Object.entries(params) .map(([k, v]) => `${k}=${v}`) .join('&'); return `${wsProtocol}${base}?${queryParams}`; } }