Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
11 changes: 6 additions & 5 deletions site/src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ const buttonVariants = cva(
text-sm font-semibold font-medium cursor-pointer no-underline
focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-content-link
disabled:pointer-events-none disabled:text-content-disabled
[&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg]:p-0.5`,
[&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg]:p-0.5
[&_img]:pointer-events-none [&_img]:shrink-0 [&_img]:p-0.5`,
{
variants: {
variant: {
Expand All @@ -28,11 +29,11 @@ const buttonVariants = cva(
},

size: {
lg: "min-w-20 h-10 px-3 py-2 [&_svg]:size-icon-lg",
sm: "min-w-20 h-8 px-2 py-1.5 text-xs [&_svg]:size-icon-sm",
lg: "min-w-20 h-10 px-3 py-2 [&_svg]:size-icon-lg [&_img]:size-icon-lg",
sm: "min-w-20 h-8 px-2 py-1.5 text-xs [&_svg]:size-icon-sm [&_img]:size-icon-sm",
xs: "min-w-8 py-1 px-2 text-2xs rounded-md",
icon: "size-8 px-1.5 [&_svg]:size-icon-sm",
"icon-lg": "size-10 px-2 [&_svg]:size-icon-lg",
icon: "size-8 px-1.5 [&_svg]:size-icon-sm [&_img]:size-icon-sm",
"icon-lg": "size-10 px-2 [&_svg]:size-icon-lg [&_img]:size-icon-lg",
},
},
defaultVariants: {
Expand Down
8 changes: 4 additions & 4 deletions site/src/components/ExternalImage/ExternalImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import { getExternalImageStylesFromUrl } from "theme/externalImages";
export const ExternalImage = forwardRef<
HTMLImageElement,
ImgHTMLAttributes<HTMLImageElement>
>((attrs, ref) => {
>((props, ref) => {
const theme = useTheme();

return (
// biome-ignore lint/a11y/useAltText: no reasonable alt to provide
// biome-ignore lint/a11y/useAltText: alt should be passed in as a prop
<img
ref={ref}
css={getExternalImageStylesFromUrl(theme.externalImages, attrs.src)}
{...attrs}
css={getExternalImageStylesFromUrl(theme.externalImages, props.src)}
{...props}
/>
);
});
27 changes: 2 additions & 25 deletions site/src/modules/resources/AgentButton.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,8 @@
import Button, { type ButtonProps } from "@mui/material/Button";
import { Button, type ButtonProps } from "components/Button/Button";
import { forwardRef } from "react";

export const AgentButton = forwardRef<HTMLButtonElement, ButtonProps>(
(props, ref) => {
const { children, ...buttonProps } = props;

return (
<Button
{...buttonProps}
color="neutral"
size="xlarge"
variant="contained"
ref={ref}
css={(theme) => ({
padding: "12px 20px",
color: theme.palette.text.primary,
// Making them smaller since those icons don't have a padding around them
"& .MuiButton-startIcon, & .MuiButton-endIcon": {
width: 16,
height: 16,

"& svg, & img": { width: "100%", height: "100%" },
},
})}
>
{children}
</Button>
);
return <Button variant="outline" ref={ref} {...props} />;
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is purpose of keeping AgentButton around instead of removing it and using Button directly?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good question.

Since we want to have the TerminalLink, AppLink, VSCode buttons, etc. visually consistent, and be sure they are always looking the same, I just decided to keep the AgentButton. Of course, we could just set the variant in all these components, but since they are many (around 5 or 6 I guess) it would be easy to forget to update one of them when changing some of the styles (maybe it is not a problem since we have tests).

I'm going to refactor the apps logic very soon, so If I see it is just ok to remove the AgentButton, I will do.

);
38 changes: 20 additions & 18 deletions site/src/modules/resources/AgentDevcontainerCard.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import Link from "@mui/material/Link";
import Tooltip from "@mui/material/Tooltip";
import type {
Workspace,
WorkspaceAgent,
WorkspaceAgentContainer,
} from "api/typesGenerated";
import {
Tooltip,
TooltipContent,
TooltipProvider,
TooltipTrigger,
} from "components/Tooltip/Tooltip";
import { ExternalLinkIcon } from "lucide-react";
import type { FC } from "react";
import { portForwardURL } from "utils/portForward";
Expand Down Expand Up @@ -74,29 +78,27 @@ export const AgentDevcontainerCard: FC<AgentDevcontainerCardProps> = ({
const linkDest = hasHostBind
? portForwardURL(
wildcardHostname,
port.host_port!,
port.host_port,
agent.name,
workspace.name,
workspace.owner_name,
location.protocol === "https" ? "https" : "http",
)
: "";
return (
<Tooltip key={portLabel} title={helperText}>
<span>
<Link
key={portLabel}
color="inherit"
component={AgentButton}
underline="none"
startIcon={<ExternalLinkIcon className="size-icon-sm" />}
disabled={!hasHostBind}
href={linkDest}
>
{portLabel}
</Link>
</span>
</Tooltip>
<TooltipProvider key={portLabel}>
<Tooltip>
<TooltipTrigger>
<AgentButton disabled={!hasHostBind} asChild>
<a href={linkDest}>
<ExternalLinkIcon />
{portLabel}
</a>
</AgentButton>
</TooltipTrigger>
<TooltipContent>{helperText}</TooltipContent>
</Tooltip>
</TooltipProvider>
);
})}
</div>
Expand Down
48 changes: 29 additions & 19 deletions site/src/modules/resources/AppLink/AppLink.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { useTheme } from "@emotion/react";
import ErrorOutlineIcon from "@mui/icons-material/ErrorOutline";
import CircularProgress from "@mui/material/CircularProgress";
import Link from "@mui/material/Link";
import Tooltip from "@mui/material/Tooltip";
import { API } from "api/api";
import type * as TypesGen from "api/typesGenerated";
import { displayError } from "components/GlobalSnackbar/utils";
import {
Tooltip,
TooltipContent,
TooltipProvider,
TooltipTrigger,
} from "components/Tooltip/Tooltip";
import { useProxy } from "contexts/ProxyContext";
import { type FC, type MouseEvent, useState } from "react";
import { type FC, useState } from "react";
import { createAppLinkHref } from "utils/apps";
import { generateRandomString } from "utils/random";
import { AgentButton } from "../AgentButton";
Expand Down Expand Up @@ -112,22 +116,13 @@ export const AppLink: FC<AppLinkProps> = ({ app, workspace, agent }) => {
canClick = false;
}

const isPrivateApp = app.sharing_level === "owner";
const canShare = app.sharing_level !== "owner";

return (
<Tooltip title={primaryTooltip}>
<Link
color="inherit"
component={AgentButton}
startIcon={icon}
endIcon={isPrivateApp ? undefined : <ShareIcon app={app} />}
disabled={!canClick}
const button = (
<AgentButton disabled={!canClick} asChild>
<a
href={href}
css={{
pointerEvents: canClick ? undefined : "none",
textDecoration: "none !important",
}}
onClick={async (event: MouseEvent<HTMLElement>) => {
onClick={async (event) => {
if (!canClick) {
return;
}
Expand Down Expand Up @@ -187,8 +182,23 @@ export const AppLink: FC<AppLinkProps> = ({ app, workspace, agent }) => {
}
}}
>
{icon}
{appDisplayName}
</Link>
</Tooltip>
{canShare && <ShareIcon app={app} />}
</a>
</AgentButton>
);

if (primaryTooltip) {
return (
<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>{button}</TooltipTrigger>
<TooltipContent>{primaryTooltip}</TooltipContent>
</Tooltip>
</TooltipProvider>
);
}

return button;
};
35 changes: 16 additions & 19 deletions site/src/modules/resources/TerminalLink/TerminalLink.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import Link from "@mui/material/Link";
import { TerminalIcon } from "components/Icons/TerminalIcon";
import type { FC, MouseEvent } from "react";
import { generateRandomString } from "utils/random";
Expand Down Expand Up @@ -39,23 +38,21 @@ export const TerminalLink: FC<TerminalLinkProps> = ({
}/terminal?${params.toString()}`;

return (
<Link
underline="none"
color="inherit"
component={AgentButton}
startIcon={<TerminalIcon />}
href={href}
onClick={(event: MouseEvent<HTMLElement>) => {
event.preventDefault();
window.open(
href,
Language.terminalTitle(generateRandomString(12)),
"width=900,height=600",
);
}}
data-testid="terminal"
>
{DisplayAppNameMap.web_terminal}
</Link>
<AgentButton asChild>
<a
href={href}
onClick={(event: MouseEvent<HTMLElement>) => {
event.preventDefault();
window.open(
href,
Language.terminalTitle(generateRandomString(12)),
"width=900,height=600",
);
}}
>
<TerminalIcon />
{DisplayAppNameMap.web_terminal}
</a>
</AgentButton>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ export const VSCodeDesktopButton: FC<VSCodeDesktopButtonProps> = (props) => {
aria-expanded={isVariantMenuOpen ? "true" : undefined}
aria-label="select VSCode variant"
aria-haspopup="menu"
disableRipple
onClick={() => {
setIsVariantMenuOpen(true);
}}
Expand Down Expand Up @@ -115,7 +114,6 @@ const VSCodeButton: FC<VSCodeDesktopButtonProps> = ({

return (
<AgentButton
startIcon={<VSCodeIcon />}
disabled={loading}
onClick={() => {
setLoading(true);
Expand Down Expand Up @@ -145,6 +143,7 @@ const VSCodeButton: FC<VSCodeDesktopButtonProps> = ({
});
}}
>
<VSCodeIcon />
{DisplayAppNameMap.vscode}
</AgentButton>
);
Expand All @@ -160,7 +159,6 @@ const VSCodeInsidersButton: FC<VSCodeDesktopButtonProps> = ({

return (
<AgentButton
startIcon={<VSCodeInsidersIcon />}
disabled={loading}
onClick={() => {
setLoading(true);
Expand Down Expand Up @@ -189,6 +187,7 @@ const VSCodeInsidersButton: FC<VSCodeDesktopButtonProps> = ({
});
}}
>
<VSCodeInsidersIcon />
{DisplayAppNameMap.vscode_insiders}
</AgentButton>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ export const VSCodeDevContainerButton: FC<VSCodeDevContainerButtonProps> = (
aria-expanded={isVariantMenuOpen ? "true" : undefined}
aria-label="select VSCode variant"
aria-haspopup="menu"
disableRipple
onClick={() => {
setIsVariantMenuOpen(true);
}}
Expand Down Expand Up @@ -119,7 +118,6 @@ const VSCodeButton: FC<VSCodeDevContainerButtonProps> = ({

return (
<AgentButton
startIcon={<VSCodeIcon />}
disabled={loading}
onClick={() => {
setLoading(true);
Expand Down Expand Up @@ -147,6 +145,7 @@ const VSCodeButton: FC<VSCodeDevContainerButtonProps> = ({
});
}}
>
<VSCodeIcon />
{DisplayAppNameMap.vscode}
</AgentButton>
);
Expand All @@ -163,7 +162,6 @@ const VSCodeInsidersButton: FC<VSCodeDevContainerButtonProps> = ({

return (
<AgentButton
startIcon={<VSCodeInsidersIcon />}
disabled={loading}
onClick={() => {
setLoading(true);
Expand Down Expand Up @@ -191,6 +189,7 @@ const VSCodeInsidersButton: FC<VSCodeDevContainerButtonProps> = ({
});
}}
>
<VSCodeInsidersIcon />
{DisplayAppNameMap.vscode_insiders}
</AgentButton>
);
Expand Down
2 changes: 0 additions & 2 deletions site/src/theme/externalImages.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import type { CSSObject } from "@emotion/react";

type ExternalImageMode = keyof ExternalImageModeStyles;

export interface ExternalImageModeStyles {
/**
* monochrome icons will be flattened to a neutral, theme-appropriate color.
Expand Down
Loading