Skip to content

Commit 295f8f7

Browse files
committed
Refactor agent buttons and links
1 parent b0f773d commit 295f8f7

File tree

3 files changed

+58
-66
lines changed

3 files changed

+58
-66
lines changed

site/src/components/Resources/AgentButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ export const AgentButton = forwardRef<HTMLButtonElement, ButtonProps>(
88

99
return (
1010
<Button
11-
color="neutral"
1211
{...buttonProps}
12+
color="neutral"
1313
size="large"
1414
variant="contained"
1515
ref={ref}

site/src/components/Resources/AppLink/AppLink.tsx

Lines changed: 52 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -93,75 +93,65 @@ export const AppLink: FC<AppLinkProps> = ({ app, workspace, agent }) => {
9393

9494
const isPrivateApp = app.sharing_level === "owner";
9595

96-
const button = (
97-
<AgentButton
98-
startIcon={icon}
99-
endIcon={isPrivateApp ? undefined : <ShareIcon app={app} />}
100-
disabled={!canClick}
101-
>
102-
<span
103-
css={
104-
!isPrivateApp && {
105-
marginRight: 8,
106-
}
107-
}
108-
>
109-
{appDisplayName}
110-
</span>
111-
</AgentButton>
112-
);
113-
11496
return (
11597
<Tooltip title={primaryTooltip}>
116-
<span>
117-
<Link
118-
href={href}
119-
target="_blank"
120-
css={{
121-
pointerEvents: canClick ? undefined : "none",
122-
textDecoration: "none !important",
123-
}}
124-
onClick={
125-
canClick
126-
? async (event) => {
127-
event.preventDefault();
128-
// This is an external URI like "vscode://", so
129-
// it needs to be opened with the browser protocol handler.
130-
if (app.external && !app.url.startsWith("http")) {
131-
// If the protocol is external the browser does not
132-
// redirect the user from the page.
98+
<Link
99+
color="inherit"
100+
component={AgentButton}
101+
startIcon={icon}
102+
endIcon={isPrivateApp ? undefined : <ShareIcon app={app} />}
103+
disabled={!canClick}
104+
href={href}
105+
target="_blank"
106+
css={{
107+
pointerEvents: canClick ? undefined : "none",
108+
textDecoration: "none !important",
109+
}}
110+
onClick={
111+
canClick
112+
? async (event) => {
113+
event.preventDefault();
114+
// This is an external URI like "vscode://", so
115+
// it needs to be opened with the browser protocol handler.
116+
if (app.external && !app.url.startsWith("http")) {
117+
// If the protocol is external the browser does not
118+
// redirect the user from the page.
133119

134-
// This is a magic undocumented string that is replaced
135-
// with a brand-new session token from the backend.
136-
// This only exists for external URLs, and should only
137-
// be used internally, and is highly subject to break.
138-
const magicTokenString = "$SESSION_TOKEN";
139-
const hasMagicToken = href.indexOf(magicTokenString);
140-
let url = href;
141-
if (hasMagicToken !== -1) {
142-
setFetchingSessionToken(true);
143-
const key = await getApiKey();
144-
url = href.replaceAll(magicTokenString, key.key);
145-
setFetchingSessionToken(false);
146-
}
147-
window.location.href = url;
148-
} else {
149-
window.open(
150-
href,
151-
Language.appTitle(
152-
appDisplayName,
153-
generateRandomString(12),
154-
),
155-
"width=900,height=600",
156-
);
120+
// This is a magic undocumented string that is replaced
121+
// with a brand-new session token from the backend.
122+
// This only exists for external URLs, and should only
123+
// be used internally, and is highly subject to break.
124+
const magicTokenString = "$SESSION_TOKEN";
125+
const hasMagicToken = href.indexOf(magicTokenString);
126+
let url = href;
127+
if (hasMagicToken !== -1) {
128+
setFetchingSessionToken(true);
129+
const key = await getApiKey();
130+
url = href.replaceAll(magicTokenString, key.key);
131+
setFetchingSessionToken(false);
157132
}
133+
window.location.href = url;
134+
} else {
135+
window.open(
136+
href,
137+
Language.appTitle(appDisplayName, generateRandomString(12)),
138+
"width=900,height=600",
139+
);
158140
}
159-
: undefined
141+
}
142+
: undefined
143+
}
144+
>
145+
<span
146+
css={
147+
!isPrivateApp && {
148+
marginRight: 8,
149+
}
160150
}
161151
>
162-
{button}
163-
</Link>
164-
</span>
152+
{appDisplayName}
153+
</span>
154+
</Link>
165155
</Tooltip>
166156
);
167157
};

site/src/components/Resources/TerminalLink/TerminalLink.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ export const TerminalLink: FC<React.PropsWithChildren<TerminalLinkProps>> = ({
3535

3636
return (
3737
<Link
38+
underline="none"
39+
color="inherit"
40+
component={AgentButton}
41+
startIcon={<TerminalIcon />}
3842
href={href}
3943
target="_blank"
4044
onClick={(event) => {
@@ -47,9 +51,7 @@ export const TerminalLink: FC<React.PropsWithChildren<TerminalLinkProps>> = ({
4751
}}
4852
data-testid="terminal"
4953
>
50-
<AgentButton startIcon={<TerminalIcon />}>
51-
{DisplayAppNameMap["web_terminal"]}
52-
</AgentButton>
54+
{DisplayAppNameMap["web_terminal"]}
5355
</Link>
5456
);
5557
};

0 commit comments

Comments
 (0)