2022-11-28 15:00:28 +13:00
|
|
|
import { Terminal } from 'lucide-react';
|
2023-10-09 19:23:12 +01:00
|
|
|
import clsx from 'clsx';
|
2025-07-25 15:24:32 +12:00
|
|
|
import { v4 as uuidv4 } from 'uuid';
|
2022-06-23 10:25:56 +03:00
|
|
|
|
2022-10-23 09:53:25 +03:00
|
|
|
import { EnvironmentId } from '@/react/portainer/environments/types';
|
2023-09-05 18:06:36 +02:00
|
|
|
import { useAnalytics } from '@/react/hooks/useAnalytics';
|
2025-07-25 15:24:32 +12:00
|
|
|
import { baseHref } from '@/portainer/helpers/pathHelper';
|
2022-06-23 10:25:56 +03:00
|
|
|
|
|
|
|
import { Button } from '@@/buttons';
|
2023-10-09 19:23:12 +01:00
|
|
|
|
2025-07-25 15:24:32 +12:00
|
|
|
import { useSidebarState } from '../useSidebarState';
|
|
|
|
import { SidebarTooltip } from '../SidebarItem/SidebarTooltip';
|
2022-06-23 10:25:56 +03:00
|
|
|
|
|
|
|
interface Props {
|
|
|
|
environmentId: EnvironmentId;
|
|
|
|
}
|
|
|
|
export function KubectlShellButton({ environmentId }: Props) {
|
2023-10-09 19:23:12 +01:00
|
|
|
const { isOpen: isSidebarOpen } = useSidebarState();
|
2022-06-23 10:25:56 +03:00
|
|
|
const { trackEvent } = useAnalytics();
|
2023-10-09 19:23:12 +01:00
|
|
|
|
|
|
|
const button = (
|
|
|
|
<Button
|
|
|
|
color="primary"
|
|
|
|
size="small"
|
|
|
|
data-cy="k8sSidebar-shellButton"
|
|
|
|
onClick={() => handleOpen()}
|
|
|
|
className={clsx('sidebar', !isSidebarOpen && '!p-1')}
|
|
|
|
icon={Terminal}
|
|
|
|
>
|
|
|
|
{isSidebarOpen ? 'kubectl shell' : ''}
|
|
|
|
</Button>
|
|
|
|
);
|
|
|
|
|
2022-06-23 10:25:56 +03:00
|
|
|
return (
|
|
|
|
<>
|
2023-10-09 19:23:12 +01:00
|
|
|
{!isSidebarOpen && (
|
|
|
|
<SidebarTooltip
|
|
|
|
content={
|
2024-04-11 12:11:38 +12:00
|
|
|
<span className="whitespace-nowrap text-sm">Kubectl Shell</span>
|
2023-10-09 19:23:12 +01:00
|
|
|
}
|
|
|
|
>
|
|
|
|
<span className="flex w-full justify-center">{button}</span>
|
|
|
|
</SidebarTooltip>
|
|
|
|
)}
|
|
|
|
{isSidebarOpen && button}
|
2022-06-23 10:25:56 +03:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
|
|
|
|
function handleOpen() {
|
2025-07-25 15:24:32 +12:00
|
|
|
const url = window.location.origin + baseHref();
|
|
|
|
window.open(
|
|
|
|
`${url}#!/${environmentId}/kubernetes/kubectl-shell`,
|
|
|
|
// give the window a unique name so that more than one can be opened
|
|
|
|
`kubectl-shell-${environmentId}-${uuidv4()}`,
|
|
|
|
'width=800,height=600'
|
|
|
|
);
|
2022-06-23 10:25:56 +03:00
|
|
|
|
|
|
|
trackEvent('kubernetes-kubectl-shell', { category: 'kubernetes' });
|
|
|
|
}
|
|
|
|
}
|