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 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
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
8000
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
6 changes: 3 additions & 3 deletions site/src/modules/resources/AgentRow.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const meta: Meta<typeof AgentRow> = {
},
workspace: M.MockWorkspace,
showApps: true,
storybookAgentMetadata: defaultAgentMetadata,
initialMetadata: defaultAgentMetadata,
},
decorators: [withProxyProvider(), withDashboardProvider, withWebSocket],
parameters: {
Expand Down Expand Up @@ -162,7 +162,7 @@ export const BunchOfApps: Story = {
export const Connecting: Story = {
args: {
agent: M.MockWorkspaceAgentConnecting,
storybookAgentMetadata: [],
initialMetadata: [],
},
};

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

Expand Down
80 changes: 27 additions & 53 deletions site/src/modules/resources/AgentRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,47 +42,34 @@ import { AgentSSHButton } from "./SSHButton/SSHButton";
import { TerminalLink } from "./TerminalLink/TerminalLink";
import { VSCodeDesktopButton } from "./VSCodeDesktopButton/VSCodeDesktopButton";
import { useAgentLogs } from "./useAgentLogs";
import { useFeatureVisibility } from "modules/dashboard/useFeatureVisibility";

export interface AgentRowProps {
agent: WorkspaceAgent;
workspace: Workspace;
showApps: boolean;
showBuiltinApps?: boolean;
sshPrefix?: string;
hideSSHButton?: boolean;
hideVSCodeDesktopButton?: boolean;
serverVersion: string;
serverAPIVersion: string;
onUpdateAgent: () => void;
template: Template;
storybookAgentMetadata?: WorkspaceAgentMetadata[];
initialMetadata?: WorkspaceAgentMetadata[];
onUpdateAgent: () => void;
}

export const AgentRow: FC<AgentRowProps> = ({
agent,
workspace,
template,
showApps,
showBuiltinApps = true,
hideSSHButton,
hideVSCodeDesktopButton,
serverVersion,
serverAPIVersion,
onUpdateAgent,
storybookAgentMetadata,
sshPrefix,
initialMetadata,
}) => {
// Apps visibility
const { browser_only } = useFeatureVisibility();
const visibleApps = agent.apps.filter((app) => !app.hidden);
const hasAppsToDisplay = !hideVSCodeDesktopButton || visibleApps.length > 0;
const hasAppsToDisplay = !browser_only && visibleApps.length > 0;
const shouldDisplayApps =
showApps &&
((agent.status === "connected" && hasAppsToDisplay) ||
agent.status === "connecting");
(agent.status === "connected" && hasAppsToDisplay) ||
agent.status === "connecting";
const hasVSCodeApp =
agent.display_apps.includes("vscode") ||
agent.display_apps.includes("vscode_insiders");
const showVSCode = hasVSCodeApp && !hideVSCodeDesktopButton;
const showVSCode = hasVSCodeApp && !browser_only;

const hasStartupFeatures = Boolean(agent.logs_length);
const { proxy } = useProxy();
Expand Down Expand Up @@ -184,12 +171,7 @@ export const AgentRow: FC<AgentRowProps> = ({
</div>
{agent.status 6D40 === "connected" && (
<>
<AgentVersion
agent={agent}
serverVersion={serverVersion}
serverAPIVersion={serverAPIVersion}
onUpdate={onUpdateAgent}
/>
<AgentVersion agent={agent} onUpdate={onUpdateAgent} />
<AgentLatency agent={agent} />
</>
)}
Expand All @@ -201,28 +183,23 @@ export const AgentRow: FC<AgentRowProps> = ({
)}
</div>

{showBuiltinApps && (
<div css={{ display: "flex" }}>
{!hideSSHButton && agent.display_apps.includes("ssh_helper") && (
<AgentSSHButton
workspaceName={workspace.name}
agentName={agent.name}
sshPrefix={sshPrefix}
<div css={{ display: "flex" }}>
{!browser_only && agent.display_apps.includes("ssh_helper") && (
<AgentSSHButton
workspaceName={workspace.name}
agentName={agent.name}
/>
)}
{proxy.preferredWildcardHostname !== "" &&
agent.display_apps.includes("port_forwarding_helper") && (
<PortForwardButton
host={proxy.preferredWildcardHostname}
workspace={workspace}
agent={agent}
template={template}
/>
)}
{proxy.preferredWildcardHostname !== "" &&
agent.display_apps.includes("port_forwarding_helper") && (
<PortForwardButton
host={proxy.preferredWildcardHostname}
workspaceName={workspace.name}
agent={agent}
username={workspace.owner_name}
workspaceID={workspace.id}
template={template}
/>
)}
</div>
)}
</div>
</header>

<div css={styles.content}>
Expand Down Expand Up @@ -257,7 +234,7 @@ export const AgentRow: FC<AgentRowProps> = ({
</>
)}

{showBuiltinApps && agent.display_apps.includes("web_terminal") && (
{agent.display_apps.includes("web_terminal") && (
<TerminalLink
workspaceName={workspace.name}
agentName={agent.name}
Expand Down Expand Up @@ -300,10 +277,7 @@ export const AgentRow: FC<AgentRowProps> = ({
</section>
)}

<AgentMetadata
storybookMetadata={storybookAgentMetadata}
agent={agent}
/>
<AgentMetadata initialMetadata={initialMetadata} agent={agent} />
</div>

{hasStartupFeatures && (
Expand Down
19 changes: 10 additions & 9 deletions site/src/modules/resources/AgentVersion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,26 @@ import type { WorkspaceAgent } from "api/typesGenerated";
import type { FC } from "react";
import { agentVersionStatus, getDisplayVersionStatus } from "utils/workspace";
import { AgentOutdatedTooltip } from "./AgentOutdatedTooltip";
import { buildInfo } from "api/queries/buildInfo";
import { useEmbeddedMetadata } from "hooks/useEmbeddedMetadata";
import { useQuery } from "react-query";

interface AgentVersionProps {
agent: WorkspaceAgent;
serverVersion: string;
serverAPIVersion: string;
onUpdate: () => void;
}

export const AgentVersion: FC<AgentVersionProps> = ({
agent,
serverVersion,
serverAPIVersion,
onUpdate,
}) => {
export const AgentVersion: FC<AgentVersionProps> = ({ agent, onUpdate }) => {
const { metadata } = useEmbeddedMetadata();
const { data: build } = useQuery(buildInfo(metadata["build-info"]));
const serverVersion = build?.version ?? "";
const apiServerVersion = build?.agent_api_version ?? "";

const { status } = getDisplayVersionStatus(
agent.version,
serverVersion,
agent.api_version,
serverAPIVersion,
apiServerVersion,
);

if (status === agentVersionStatus.Updated) {
Expand Down
Loading
Loading
0