|
| 1 | +import Button from "@material-ui/core/Button" |
| 2 | +import Popover from "@material-ui/core/Popover" |
| 3 | +import { makeStyles } from "@material-ui/core/styles" |
| 4 | +import CloudIcon from "@material-ui/icons/CloudOutlined" |
| 5 | +import { useRef, useState } from "react" |
| 6 | +import { CodeExample } from "../CodeExample/CodeExample" |
| 7 | +import { Stack } from "../Stack/Stack" |
| 8 | +import { HelpTooltipLink, HelpTooltipLinksGroup, HelpTooltipText } from "../Tooltips/HelpTooltip" |
| 9 | + |
| 10 | +export interface SSHButtonProps { |
| 11 | + workspaceName: string |
| 12 | + agentName: string |
| 13 | + defaultIsOpen?: boolean |
| 14 | +} |
| 15 | + |
| 16 | +export const SSHButton: React.FC<SSHButtonProps> = ({ |
| 17 | + workspaceName, |
| 18 | + agentName, |
| 19 | + defaultIsOpen = false, |
| 20 | +}) => { |
| 21 | + const anchorRef = useRef<HTMLButtonElement>(null) |
| 22 | + const [isOpen, setIsOpen] = useState(defaultIsOpen) |
| 23 | + const id = isOpen ? "schedule-popover" : undefined |
| 24 | + const styles = useStyles() |
| 25 | + |
| 26 | + const onClose = () => { |
| 27 | + setIsOpen(false) |
| 28 | + } |
| 29 | + |
| 30 | + return ( |
| 31 | + <> |
| 32 | + <Button |
| 33 | + startIcon={<CloudIcon />} |
| 34 | + size="small" |
| 35 | + ref={anchorRef} |
| 36 | + onClick={() => { |
| 37 | + setIsOpen(true) |
| 38 | + }} |
| 39 | + > |
| 40 | + SSH |
| 41 | + </Button> |
| 42 | + <Popover |
| 43 | + classes={{ paper: styles.popoverPaper }} |
| 44 | + id={id} |
| 45 | + open={isOpen} |
| 46 | + anchorEl={anchorRef.current} |
| 47 | + onClose={onClose} |
| 48 | + anchorOrigin={{ |
| 49 | + vertical: "bottom", |
| 50 | + horizontal: "left", |
| 51 | + }} |
| 52 | + transformOrigin={{ |
| 53 | + vertical: "top", |
| 54 | + horizontal: "left", |
| 55 | + }} |
| 56 | + > |
| 57 | + <HelpTooltipText>Run the following commands to connect with SSH:</HelpTooltipText> |
| 58 | + |
| 59 | + <Stack spacing={0.5} className={styles.codeExamples}> |
| 60 | + <div> |
| 61 | + <HelpTooltipText> |
| 62 | + <strong className={styles.codeExampleLabel}> |
| 63 | + Configure ssh{" "} |
| 64 | + <span className={styles.textHelper}> |
| 65 | + - only needs to be run once, or after managing workspaces |
| 66 | + </span> |
| 67 | + </strong> |
| 68 | + </HelpTooltipText> |
| 69 | + <CodeExample code="coder config-ssh" /> |
| 70 | + </div> |
| 71 | + |
| 72 | + <div> |
| 73 | + <HelpTooltipText> |
| 74 | + <strong className={styles.codeExampleLabel}>Connect to the agent</strong> |
| 75 | + </HelpTooltipText> |
| 76 | + <CodeExample code={`ssh coder.${workspaceName}.${agentName}`} /> |
| 77 | + </div> |
| 78 | + </Stack> |
| 79 | + |
| 80 | + <HelpTooltipLinksGroup> |
| 81 | + <HelpTooltipLink href="#">Install Coder CLI</HelpTooltipLink> |
| 82 | + <HelpTooltipLink href="#">Configuring VS Code</HelpTooltipLink> |
| 83 | + <HelpTooltipLink href="#">SSH configuration</HelpTooltipLink> |
| 84 | + </HelpTooltipLinksGroup> |
| 85 | + </Popover> |
| 86 | + </> |
| 87 | + ) |
| 88 | +} |
| 89 | + |
| 90 | +const useStyles = makeStyles((theme) => ({ |
| 91 | + popoverPaper: { |
| 92 | + padding: `${theme.spacing(2)}px ${theme.spacing(3)}px ${theme.spacing(3)}px`, |
| 93 | + width: theme.spacing(38), |
| 94 | + color: theme.palette.text.secondary, |
| 95 | + marginTop: theme.spacing(0.25), |
| 96 | + }, |
| 97 | + |
| 98 | + codeExamples: { |
| 99 | + marginTop: theme.spacing(1.5), |
| 100 | + }, |
| 101 | + |
| 102 | + codeExampleLabel: { |
| 103 | + fontSize: 12, |
| 104 | + }, |
| 105 | + |
| 106 | + textHelper: { |
| 107 | + fontWeight: 400, |
| 108 | + }, |
| 109 | +})) |
0 commit comments