8000 chore: simplify AgentRow interface by BrunoQuaresma · Pull Request #18087 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

chore: simplify AgentRow interface #18087

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 9 commits into from
May 29, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions site/src/api/queries/deployment.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { API } from "api/api";
import { disabledRefetchOptions } from "./util";

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

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

export const deploymentSSHConfig = () => {
return {
...disabledRefetchOptions,
queryKey: ["deployment", "sshConfig"],
queryFn: API.getDeploymentSSHConfig,
};
Expand Down
12 changes: 6 additions & 6 deletions site/src/modules/resources/AgentMetadata.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,24 @@ export const AgentMetadataView: FC<AgentMetadataViewProps> = ({ metadata }) => {

interface AgentMetadataProps {
agent: WorkspaceAgent;
storybookMetadata?: WorkspaceAgentMetadata[];
initialMetadata?: WorkspaceAgentMetadata[];
}

const maxSocketErrorRetryCount = 3;

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

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

if (activeMetadata === undefined) {
return (
Expand Down
46 changes: 19 additions & 27 deletions site/src/modules/resources/AgentRow.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import type { Meta, StoryObj } from "@storybook/react";
import { spyOn } from "@storybook/test";
import { API } from "api/api";
import { getPreferredProxy } from "contexts/ProxyContext";
import { chromatic } from "testHelpers/chromatic";
import * as M from "testHelpers/entities";
Expand Down Expand Up @@ -95,8 +97,7 @@ const meta: Meta<typeof AgentRow> = {
logs_length: logs.length,
},
workspace: M.MockWorkspace,
showApps: true,
storybookAgentMetadata: defaultAgentMetadata,
initialMetadata: defaultAgentMetadata,
},
decorators: [withProxyProvider(), withDashboardProvider, withWebSocket],
parameters: {
Expand All @@ -121,24 +122,6 @@ type Story = StoryObj<typeof AgentRow>;

export const Example: Story = {};

export const HideSSHButton: Story = {
args: {
hideSSHButton: true,
},
};

export const HideVSCodeDesktopButton: Story = {
args: {
hideVSCodeDesktopButton: true,
},
};

export const NotShowingApps: Story = {
args: {
showApps: false,
},
};

export const BunchOfApps: Story = {
args: {
agent: {
Expand All @@ -155,14 +138,13 @@ export const BunchOfApps: Story = {
],
},
workspace: M.MockWorkspace,
showApps: true,
},
};

export const Connecting: Story = {
args: {
agent: M.MockWorkspaceAgentConnecting,
storybookAgentMetadata: [],
initialMetadata: [],
},
};

Expand Down Expand Up @@ -190,7 +172,7 @@ export const Started: Story = {
export const StartedNoMetadata: Story = {
args: {
...Started.args,
storybookAgentMetadata: [],
initialMetadata: [],
},
};

Expand Down Expand Up @@ -243,20 +225,30 @@ export const ShowingPortForward: Story = {
};

export const Outdated: Story = {
beforeEach: () => {
spyOn(API, "getBuildInfo").mockResolvedValue({
...M.MockBuildInfo,
version: "v99.999.9999+c1cdf14",
agent_api_version: "1.0",
});
},
args: {
agent: M.MockWorkspaceAgentOutdated,
workspace: M.MockWorkspace,
serverVersion: "v99.999.9999+c1cdf14",
serverAPIVersion: "1.0",
},
};

export const Deprecated: Story = {
beforeEach: () => {
spyOn(API, "getBuildInfo").mockResolvedValue({
...M.MockBuildInfo,
version: "v99.999.9999+c1cdf14",
agent_api_version: "2.0",
});
},
args: {
agent: M.MockWorkspaceAgentDeprecated,
workspace: M.MockWorkspace,
serverVersion: "v99.999.9999+c1cdf14",
serverAPIVersion: "2.0",
},
};

Expand Down
159 changes: 0 additions & 159 deletions site/src/modules/resources/AgentRow.test.tsx

This file was deleted.

Loading
Loading
0