Skip to content

Commit 9fe5b71

Browse files
chore!: fix workspace apps response (#17700)
Fix WorkspaceApp response type to better reflect the schema from https://registry.terraform.io/providers/coder/coder/latest/docs/resources/app.
1 parent d146115 commit 9fe5b71

File tree

9 files changed

+22
-33
lines changed

9 files changed

+22
-33
lines changed

codersdk/workspaceapps.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ type WorkspaceApp struct {
6060
ID uuid.UUID `json:"id" format:"uuid"`
6161
// URL is the address being proxied to inside the workspace.
6262
// If external is specified, this will be opened on the client.
63-
URL string `json:"url"`
63+
URL string `json:"url,omitempty"`
6464
// External specifies whether the URL should be opened externally on
6565
// the client or not.
6666
External bool `json:"external"`
6767
// Slug is a unique identifier within the agent.
6868
Slug string `json:"slug"`
6969
// DisplayName is a friendly name for the app.
70-
DisplayName string `json:"display_name"`
70+
DisplayName string `json:"display_name,omitempty"`
7171
Command string `json:"command,omitempty"`
7272
// Icon is a relative path or external URL that specifies
7373
// an icon to be displayed in the dashboard.
@@ -81,7 +81,7 @@ type WorkspaceApp struct {
8181
SubdomainName string `json:"subdomain_name,omitempty"`
8282
SharingLevel WorkspaceAppSharingLevel `json:"sharing_level" enums:"owner,authenticated,public"`
8383
// Healthcheck specifies the configuration for checking app health.
84-
Healthcheck Healthcheck `json:"healthcheck"`
84+
Healthcheck Healthcheck `json:"healthcheck,omitempty"`
8585
Health WorkspaceAppHealth `json:"health"`
8686
Hidden bool `json:"hidden"`
8787
OpenIn WorkspaceAppOpenIn `json:"open_in"`

site/src/api/typesGenerated.ts

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

site/src/modules/resources/AgentRow.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,9 @@ describe.each<{
150150

151151
for (const app of props.agent.apps) {
152152
if (app.hidden) {
153-
expect(screen.queryByText(app.display_name)).toBeNull();
153+
expect(screen.queryByText(app.display_name as string)).toBeNull();
154154
} else {
155-
expect(screen.getByText(app.display_name)).toBeVisible();
155+
expect(screen.getByText(app.display_name as string)).toBeVisible();
156156
}
157157
}
158158
});

site/src/modules/resources/AgentRowPreview.test.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,10 @@ describe("AgentRowPreviewApps", () => {
9191
"<AgentRowPreview agent={$testName} /> displays appropriately",
9292
({ workspaceAgent }) => {
9393
renderComponent(<AgentRowPreview agent={workspaceAgent} />);
94-
for (const module of workspaceAgent.apps) {
95-
expect(screen.getByText(module.display_name)).toBeInTheDocument();
94+
for (const app of workspaceAgent.apps) {
95+
expect(
96+
screen.getByText(app.display_name as string),
97+
).toBeInTheDocument();
9698
}
9799

98100
for (const app of workspaceAgent.display_apps) {

site/src/modules/resources/AgentRowPreview.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export const AgentRowPreview: FC<AgentRowPreviewProps> = ({
3131
>
3232
<Stack direction="row" alignItems="baseline">
3333
<div css={styles.agentStatusWrapper}>
34-
<div css={styles.agentStatusPreview}></div>
34+
<div css={styles.agentStatusPreview} />
3535
</div>
3636
<Stack
3737
alignItems="baseline"

site/src/modules/resources/AppLink/AppLink.tsx

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,15 @@ export const AppLink: FC<AppLinkProps> = ({ app, workspace, agent }) => {
4343
const appsHost = proxy.preferredWildcardHostname;
4444
const [fetchingSessionToken, setFetchingSessionToken] = useState(false);
4545
const [iconError, setIconError] = useState(false);
46-
4746
const theme = useTheme();
4847
const username = workspace.owner_name;
49-
50-
let appSlug = app.slug;
51-
let appDisplayName = app.display_name;
52-
if (!appSlug) {
53-
appSlug = appDisplayName;
54-
}
55-
if (!appDisplayName) {
56-
appDisplayName = appSlug;
57-
}
48+
const displayName = app.display_name || app.slug;
5849

5950
const href = createAppLinkHref(
6051
window.location.protocol,
6152
preferredPathBase,
6253
appsHost,
63-
appSlug,
54+
app.slug,
6455
username,
6556
workspace,
6657
agent,
@@ -118,7 +109,7 @@ export const AppLink: FC<AppLinkProps> = ({ app, workspace, agent }) => {
118109
// This is an external URI like "vscode://", so
119110
// it needs to be opened with the browser protocol handler.
120111
const shouldOpenAppExternally =
121-
app.external && !app.url.startsWith("http");
112+
app.external && app.url?.startsWith("http");
122113

123114
if (shouldOpenAppExternally) {
124115
// This is a magic undocumented string that is replaced
@@ -140,9 +131,7 @@ export const AppLink: FC<AppLinkProps> = ({ app, workspace, agent }) => {
140131
// an error message will be displayed.
141132
const openAppExternallyFailedTimeout = 500;
142133
const openAppExternallyFailed = setTimeout(() => {
143-
displayError(
144-
`${app.display_name !== "" ? app.display_name : app.slug} must be installed first.`,
145-
);
134+
displayError(`${displayName} must be installed first.`);
146135
}, openAppExternallyFailedTimeout);
147136
window.addEventListener("blur", () => {
148137
clearTimeout(openAppExternallyFailed);
@@ -156,7 +145,7 @@ export const AppLink: FC<AppLinkProps> = ({ app, workspace, agent }) => {
156145
case "slim-window": {
157146
window.open(
158147
href,
159-
Language.appTitle(appDisplayName, generateRandomString(12)),
148+
Language.appTitle(displayName, generateRandomString(12)),
160149
"width=900,height=600",
161150
);
162151
return;
@@ -169,7 +158,7 @@ export const AppLink: FC<AppLinkProps> = ({ app, workspace, agent }) => {
169158
}}
170159
>
171160
{icon}
172-
{appDisplayName}
161+
{displayName}
173162
{canShare && <ShareIcon app={app} />}
174163
</a>
175164
</AgentButton>

site/src/modules/workspaces/WorkspaceAppStatus/WorkspaceAppStatus.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,11 @@ export const WorkspaceAppStatus = ({
124124

125125
let appHref: string | undefined;
126126
if (app && agent) {
127-
const appSlug = app.slug || app.display_name;
128127
appHref = createAppLinkHref(
129128
window.location.protocol,
130129
preferredPathBase,
131130
appsHost,
132-
appSlug,
131+
app.slug,
133132
workspace.owner_name,
134133
workspace,
135134
agent,

site/src/pages/WorkspacePage/AppStatuses.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,11 @@ export const AppStatuses: FC<AppStatusesProps> = ({
198198
const agent = agents.find((agent) => agent.id === status.agent_id);
199199

200200
if (currentApp && agent) {
201-
const appSlug = currentApp.slug || currentApp.display_name;
202201
appHref = createAppLinkHref(
203202
window.location.protocol,
204203
preferredPathBase,
205204
appsHost,
206-
appSlug,
205+
currentApp.slug,
207206
workspace.owner_name,
208207
workspace,
209208
agent,

site/src/utils/apps.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const createAppLinkHref = (
1111
app: TypesGen.WorkspaceApp,
1212
): string => {
1313
if (app.external) {
14-
return app.url;
14+
return app.url as string;
1515
}
1616

1717
// The backend redirects if the trailing slash isn't included, so we add it

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy