2022-08-12 18:22:45 +00:00
|
|
|
import clsx from 'clsx';
|
2022-06-23 07:25:56 +00:00
|
|
|
import { useState } from 'react';
|
|
|
|
import { createPortal } from 'react-dom';
|
|
|
|
|
2022-10-23 06:53:25 +00:00
|
|
|
import { EnvironmentId } from '@/react/portainer/environments/types';
|
2022-06-23 07:25:56 +00:00
|
|
|
import { useAnalytics } from '@/angulartics.matomo/analytics-services';
|
|
|
|
|
|
|
|
import { Button } from '@@/buttons';
|
2022-08-12 18:22:45 +00:00
|
|
|
import { Icon } from '@@/Icon';
|
2022-06-23 07:25:56 +00:00
|
|
|
|
|
|
|
import { KubeCtlShell } from './KubectlShell';
|
|
|
|
import styles from './KubectlShellButton.module.css';
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
environmentId: EnvironmentId;
|
|
|
|
}
|
|
|
|
export function KubectlShellButton({ environmentId }: Props) {
|
|
|
|
const [open, setOpen] = useState(false);
|
|
|
|
const { trackEvent } = useAnalytics();
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Button
|
|
|
|
color="primary"
|
2022-08-12 18:22:45 +00:00
|
|
|
size="small"
|
2022-06-23 07:25:56 +00:00
|
|
|
disabled={open}
|
|
|
|
data-cy="k8sSidebar-shellButton"
|
|
|
|
onClick={() => handleOpen()}
|
2022-08-12 18:22:45 +00:00
|
|
|
className={clsx(styles.root, '!flex')}
|
2022-06-23 07:25:56 +00:00
|
|
|
>
|
2022-08-12 18:22:45 +00:00
|
|
|
<Icon icon="terminal" feather className="vertical-center" size="md" />{' '}
|
|
|
|
kubectl shell
|
2022-06-23 07:25:56 +00:00
|
|
|
</Button>
|
|
|
|
|
|
|
|
{open &&
|
|
|
|
createPortal(
|
|
|
|
<KubeCtlShell
|
|
|
|
environmentId={environmentId}
|
|
|
|
onClose={() => setOpen(false)}
|
|
|
|
/>,
|
|
|
|
document.body
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
|
|
|
|
function handleOpen() {
|
|
|
|
setOpen(true);
|
|
|
|
|
|
|
|
trackEvent('kubernetes-kubectl-shell', { category: 'kubernetes' });
|
|
|
|
}
|
|
|
|
}
|