Skip to content

Commit 201b0b1

Browse files
chore: simplify AgentRow interface (coder#18087)
1 parent 8387dd2 commit 201b0b1

16 files changed

+167
-406
lines changed

site/src/api/queries/deployment.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { API } from "api/api";
2+
import { disabledRefetchOptions } from "./util";
23

34
export const deploymentConfigQueryKey = ["deployment", "config"];
45

@@ -26,6 +27,7 @@ export const deploymentStats = () => {
2627

2728
export const deploymentSSHConfig = () => {
2829
return {
30+
...disabledRefetchOptions,
2931
queryKey: ["deployment", "sshConfig"],
3032
queryFn: API.getDeploymentSSHConfig,
3133
};

site/src/modules/resources/AgentMetadata.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,24 +42,24 @@ export const AgentMetadataView: FC<AgentMetadataViewProps> = ({ metadata }) => {
4242

4343
interface AgentMetadataProps {
4444
agent: WorkspaceAgent;
45-
storybookMetadata?: WorkspaceAgentMetadata[];
45+
initialMetadata?: WorkspaceAgentMetadata[];
4646
}
4747

4848
const maxSocketErrorRetryCount = 3;
4949

5050
export const AgentMetadata: FC<AgentMetadataProps> = ({
5151
agent,
52-
storybookMetadata,
52+
initialMetadata,
5353
}) => {
54-
const [activeMetadata, setActiveMetadata] = useState(storybookMetadata);
54+
const [activeMetadata, setActiveMetadata] = useState(initialMetadata);
5555
useEffect(() => {
5656
// This is an unfortunate pitfall with this component's testing setup,
57-
// but even though we use the value of storybookMetadata as the initial
57+
// but even though we use the value of initialMetadata as the initial
5858
// value of the activeMetadata, we cannot put activeMetadata itself into
5959
// the dependency array. If we did, we would destroy and rebuild each
6060
// connection every single time a new message comes in from the socket,
6161
// because the socket has to be wired up to the state setter
62-
if (storybookMetadata !== undefined) {
62+
if (initialMetadata !== undefined) {
6363
return;
6464
}
6565

@@ -118,7 +118,7 @@ export const AgentMetadata: FC<AgentMetadataProps> = ({
118118
window.clearTimeout(timeoutId);
119119
activeSocket?.close();
120120
};
121-
}, [agent.id, storybookMetadata]);
121+
}, [agent.id, initialMetadata]);
122122

123123
if (activeMetadata === undefined) {
124124
return (

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

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import type { Meta, StoryObj } from "@storybook/react";
2+
import { spyOn } from "@storybook/test";
3+
import { API } from "api/api";
24
import { getPreferredProxy } from "contexts/ProxyContext";
35
import { chromatic } from "testHelpers/chromatic";
46
import * as M from "testHelpers/entities";
@@ -95,8 +97,7 @@ const meta: Meta<typeof AgentRow> = {
9597
logs_length: logs.length,
9698
},
9799
workspace: M.MockWorkspace,
98-
showApps: true,
99-
storybookAgentMetadata: defaultAgentMetadata,
100+
initialMetadata: defaultAgentMetadata,
100101
},
101102
decorators: [withProxyProvider(), withDashboardProvider, withWebSocket],
102103
parameters: {
@@ -121,24 +122,6 @@ type Story = StoryObj<typeof AgentRow>;
121122

122123
export const Example: Story = {};
123124

124-
export const HideSSHButton: Story = {
125-
args: {
126-
hideSSHButton: true,
127-
},
128-
};
129-
130-
export const HideVSCodeDesktopButton: Story = {
131-
args: {
132-
hideVSCodeDesktopButton: true,
133-
},
134-
};
135-
136-
export const NotShowingApps: Story = {
137-
args: {
138-
showApps: false,
139-
},
140-
};
141-
142125
export const BunchOfApps: Story = {
143126
args: {
144127
agent: {
@@ -155,14 +138,13 @@ export const BunchOfApps: Story = {
155138
],
156139
},
157140
workspace: M.MockWorkspace,
158-
showApps: true,
159141
},
160142
};
161143

162144
export const Connecting: Story = {
163145
args: {
164146
agent: M.MockWorkspaceAgentConnecting,
165-
storybookAgentMetadata: [],
147+
initialMetadata: [],
166148
},
167149
};
168150

@@ -190,7 +172,7 @@ export const Started: Story = {
190172
export const StartedNoMetadata: Story = {
191173
args: {
192174
...Started.args,
193-
storybookAgentMetadata: [],
175+
initialMetadata: [],
194176
},
195177
};
196178

@@ -243,20 +225,30 @@ export const ShowingPortForward: Story = {
243225
};
244226

245227
export const Outdated: Story = {
228+
beforeEach: () => {
229+
spyOn(API, "getBuildInfo").mockResolvedValue({
230+
...M.MockBuildInfo,
231+
version: "v99.999.9999+c1cdf14",
232+
agent_api_version: "1.0",
233+
});
234+
},
246235
args: {
247236
agent: M.MockWorkspaceAgentOutdated,
248237
workspace: M.MockWorkspace,
249-
serverVersion: "v99.999.9999+c1cdf14",
250-
serverAPIVersion: "1.0",
251238
},
252239
};
253240

254241
export const Deprecated: Story = {
242+
beforeEach: () => {
243+
spyOn(API, "getBuildInfo").mockResolvedValue({
244+
...M.MockBuildInfo,
245+
version: "v99.999.9999+c1cdf14",
246+
agent_api_version: "2.0",
247+
});
248+
},
255249
args: {
256250
agent: M.MockWorkspaceAgentDeprecated,
257251
workspace: M.MockWorkspace,
258-
serverVersion: "v99.999.9999+c1cdf14",
259-
serverAPIVersion: "2.0",
260252
},
261253
};
262254

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

Lines changed: 0 additions & 159 deletions
This file was deleted.

0 commit comments

Comments
 (0)