8000 refactor(site): Group app and agent actions together by BrunoQuaresma · Pull Request #7267 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

refactor(site): Group app and agent actions together #7267

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Combine buttons
  • Loading branch information
BrunoQuaresma committed Apr 24, 2023
commit 3c6e6ff4a2b715109cca3fe0fe5569560e486789
25 changes: 3 additions & 22 deletions site/src/components/AppLink/AppLink.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Button from "@material-ui/core/Button"
import CircularProgress from "@material-ui/core/CircularProgress"
import Link from "@material-ui/core/Link"
import { makeStyles } from "@material-ui/core/styles"
import Tooltip from "@material-ui/core/Tooltip"
import ErrorOutlineIcon from "@material-ui/icons/ErrorOutline"
import { PrimaryAgentButton } from "components/Resources/AgentButton"
import { FC } from "react"
import { combineClasses } from "utils/combineClasses"
import * as TypesGen from "../../api/typesGenerated"
Expand Down Expand Up @@ -83,16 +83,15 @@ export const AppLink: FC<AppLinkProps> = ({
const isPrivateApp = app.sharing_level === "owner"

const button = (
<Button
<PrimaryAgentButton
startIcon={icon}
endIcon={isPrivateApp ? undefined : <ShareIcon app={app} />}
className={styles.button}
disabled={!canClick}
>
<span className={combineClasses({ [styles.appName]: !isPrivateApp })}>
{appDisplayName}
</span>
</Button>
</PrimaryAgentButton>
)

return (
Expand Down Expand Up @@ -132,24 +131,6 @@ const useStyles = makeStyles((theme) => ({
textDecoration: "none !important",
},

button: {
whiteSpace: "nowrap",
backgroundColor: theme.palette.background.default,
padding: theme.spacing(0, 3),
height: 44,
borderRadius: 6,

"&:hover": {
backgroundColor: `${theme.palette.background.paper} !important`,
},

"& .MuiButton-startIcon": {
width: 16,
height: 16,
marginRight: theme.spacing(1.5),
},
},

unhealthyIcon: {
color: theme.palette.warning.light,
},
Expand Down
16 changes: 3 additions & 13 deletions site/src/components/PortForwardButton/PortForwardButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
import { Maybe } from "components/Conditionals/Maybe"
import { useMachine } from "@xstate/react"
import { portForwardMachine } from "xServices/portForward/portForwardXService"
import { SecondaryAgentButton } from "components/Resources/AgentButton"

export interface PortForwardButtonProps {
host: string
Expand Down Expand Up @@ -147,17 +148,14 @@ export const PortForwardButton: React.FC<PortForwardButtonProps> = (props) => {

return (
<>
<Button
variant="outlined"
className={styles.button}
size="small"
<SecondaryAgentButton
ref={anchorRef}
onClick={() => {
setIsOpen(true)
}}
>
Port forward
</Button>
</SecondaryAgentButton>
<Popover
classes={{ paper: styles.popoverPaper }}
id={id}
Expand Down Expand Up @@ -208,12 +206,4 @@ const useStyles = makeStyles((theme) => ({
form: {
margin: theme.spacing(1.5, 0, 0),
},

button: {
fontSize: 12,
fontWeight: 500,
height: theme.spacing(4),
minHeight: theme.spacing(4),
borderRadius: 4,
},
}))
68 changes: 68 additions & 0 deletions site/src/components/Resources/AgentButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { makeStyles } from "@material-ui/core/styles"
import Button, { ButtonProps } from "@material-ui/core/Button"
import { FC } from "react"
import { combineClasses } from "utils/combineClasses"

export const PrimaryAgentButton: FC<ButtonProps> = ({
className,
...props
}) => {
const styles = useStyles()

return (
<Button
className={combineClasses([styles.primaryButton, className])}
{...props}
/>
)
}

export const SecondaryAgentButton: FC<ButtonProps> = ({
className,
...props
}) => {
const styles = useStyles()

return (
<Button
variant="outlined"
className={combineClasses([styles.secondaryButton, className])}
{...props}
/>
)
}

const useStyles = makeStyles((theme) => ({
primaryButton: {
whiteSpace: "nowrap",
backgroundColor: theme.palette.background.default,
height: 36,
minHeight: 36,
borderRadius: 4,
fontWeight: 500,
fontSize: 14,

"&:hover": {
backgroundColor: `${theme.palette.background.paper} !important`,
},

"& .MuiButton-startIcon": {
width: 12,
height: 12,
marginRight: theme.spacing(1.5),

"& svg": {
width: "100%",
height: "100%",
},
},
},

secondaryButton: {
fontSize: 14,
fontWeight: 500,
height: 36,
minHeight: 36,
borderRadius: 4,
},
}))
79 changes: 25 additions & 54 deletions site/src/components/Resources/AgentRow.tsx
< 9E88 td class="blob-code blob-code-deletion js-file-line"> <>
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,29 @@ export const AgentRow: FC<AgentRowProps> = ({
</div>

{agent.status === "connected" && (
<div className={styles.agentDefaultActions}>
<div className={styles.agentButtons}>
{shouldDisplayApps && (
<>
{!hideVSCodeDesktopButton && (
<VSCodeDesktopButton
userName={workspace.owner_name}
workspaceName={workspace.name}
agentName={agent.name}
folderPath={agent.expanded_directory}
/>
)}
{agent.apps.map((app) => (
<AppLink
key={app.slug}
appsHost={applicationsHost}
app={app}
agent={agent}
workspace={workspace}
/>
))}
</>
)}

<TerminalLink
workspaceName={workspace.name}
agentName={agent.name}
Expand All @@ -244,7 +266,7 @@ export const AgentRow: FC<AgentRowProps> = ({
)}

{agent.status === "connecting" && (
<div className={styles.agentDefaultActions}>
<div className={styles.agentButtons}>
<Skeleton
width={80}
height={32}
Expand All @@ -263,49 +285,6 @@ export const AgentRow: FC<AgentRowProps> = ({

<AgentMetadata storybookMetadata={storybookAgentMetadata} agent={agent} />

{shouldDisplayApps && (
<div className={styles.apps}>
{agent.status === "connected" && (
{!hideVSCodeDesktopButton && (
<VSCodeDesktopButton
userName={workspace.owner_name}
workspaceName={workspace.name}
agentName={agent.name}
folderPath={agent.expanded_directory}
/>
)}
{agent.apps.map((app) => (
<AppLink
key={app.slug}
appsHost={applicationsHost}
app={app}
agent={agent}
workspace={workspace}
/>
))}
</>
)}

{agent.status === "connecting" && (
<>
<Skeleton
width={80}
height={36}
variant="rect"
className={styles.buttonSkeleton}
/>
<Skeleton
width={110}
height={36}
variant="rect"
className={styles.buttonSkeleton}
/>
</>
)}
</div>
)}

{hasStartupFeatures && (
<div className={styles.logsPanel}>
{showStartupLogs && (
Expand Down Expand Up @@ -473,7 +452,7 @@ const useStyles = makeStyles((theme) => ({
padding: theme.spacing(2, 4),
},

agentDefaultActions: {
agentButtons: {
display: "flex",
gap: theme.spacing(1),
marginLeft: "auto",
Expand Down Expand Up @@ -532,14 +511,6 @@ const useStyles = makeStyles((theme) => ({
},
},

apps: {
display: "flex",
flexWrap: "wrap",
gap: theme.spacing(1.5),
padding: theme.spacing(4),
borderTop: `1px solid ${theme.palette.divider}`,
},

logsPanel: {
borderTop: `1px solid ${theme.palette.divider}`,
},
Expand Down
17 changes: 3 additions & 14 deletions site/src/components/SSHButton/SSHButton.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Button from "@material-ui/core/Button"
import Popover from "@material-ui/core/Popover"
import { makeStyles } from "@material-ui/core/styles"
import { SecondaryAgentButton } from "components/Resources/AgentButton"
import { useRef, useState } from "react"
import { CodeExample } from "../CodeExample/CodeExample"
import { Stack } from "../Stack/Stack"
Expand Down Expand Up @@ -34,17 +34,14 @@ export const SSHButton: React.FC<React.PropsWithChildren<SSHButtonProps>> = ({

return (
<>
<Button
className={styles.button}
variant="outlined"
size="small"
<SecondaryAgentButton
ref={anchorRef}
onClick={() => {
setIsOpen(true)
}}
>
Connect SSH
</Button>
</SecondaryAgentButton>
<Popover
classes={{ paper: styles.popoverPaper }}
id={id}
Expand Down Expand Up @@ -126,12 +123,4 @@ const useStyles = makeStyles((theme) => ({
textHelper: {
fontWeight: 400,
},

button: {
fontSize: 12,
fontWeight: 500,
height: theme.spacing(4),
minHeight: theme.spacing(4),
borderRadius: 4,
},
}))
31 changes: 8 additions & 23 deletions site/src/components/TerminalLink/TerminalLink.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import Button from "@material-ui/core/Button"
import { makeStyles } from "@material-ui/core/styles"
import Link from "@material-ui/core/Link"
import { SecondaryAgentButton } from "components/Resources/AgentButton"
import { FC } from "react"
import * as TypesGen from "../../api/typesGenerated"
import { combineClasses } from "../../utils/combineClasses"
import { generateRandomString } from "../../utils/random"

export const Language = {
Expand All @@ -14,7 +13,6 @@ export interface TerminalLinkProps {
agentName?: TypesGen.WorkspaceAgent["name"]
userName?: TypesGen.User["username"]
workspaceName: TypesGen.Workspace["name"]
className?: string
}

/**
Expand All @@ -28,20 +26,15 @@ export const TerminalLink: FC<React.PropsWithChildren<TerminalLinkProps>> = ({
agentName,
userName = "me",
workspaceName,
className = "",
}) => {
const styles = useStyles()
const href = `/@${userName}/${workspaceName}${
agentName ? `.${agentName}` : ""
}/terminal`

return (
<Button
<Link
underline="none"
href={href}
component="a"
size="small"
variant="outlined"
className={combineClasses([styles.button, className])}
target="_blank"
onClick={(event) => {
event.preventDefault()
Expand All @@ -52,17 +45,9 @@ export const TerminalLink: FC<React.PropsWithChildren<TerminalLinkProps>> = ({
)
}}
>
{Language.linkText}
</Button>
<SecondaryAgentButton size="small" variant="outlined">
{Language.linkText}
</SecondaryAgentButton>
</Link>
)
}

const useStyles = makeStyles((theme) => ({
button: {
fontSize: 12,
fontWeight: 500,
height: theme.spacing(4),
minHeight: theme.spacing(4),
borderRadius: 4,
},
}))
Loading
0