Skip to content

Commit 38a8d62

Browse files
committed
Apply review comments
1 parent 6d33649 commit 38a8d62

File tree

3 files changed

+6
-13
lines changed

3 files changed

+6
-13
lines changed

site/src/api/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ export const watchWorkspaceAgentLogs = (
225225
) => {
226226
const searchParams = new URLSearchParams({
227227
follow: "true",
228-
after: params?.after ? params?.after.toString() : "",
228+
after: params?.after?.toString() ?? "",
229229
});
230230

231231
/**

site/src/modules/resources/useAgentLogs.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ import { useEffect, useState } from "react";
66
export function useAgentLogs(
77
agent: WorkspaceAgent,
88
enabled: boolean,
9-
): readonly WorkspaceAgentLog[] | undefined {
10-
const [logs, setLogs] = useState<WorkspaceAgentLog[]>();
9+
): readonly WorkspaceAgentLog[] {
10+
const [logs, setLogs] = useState<WorkspaceAgentLog[]>([]);
1111

1212
useEffect(() => {
1313
if (!enabled) {
1414
// Clean up the logs when the agent is not enabled. So it can receive logs
1515
// from the beginning without duplicating the logs.
16-
setLogs(undefined);
16+
setLogs([]);
1717
return;
1818
}
1919

@@ -26,9 +26,7 @@ export function useAgentLogs(
2626
console.warn("Error parsing agent log: ", e.parseError);
2727
return;
2828
}
29-
setLogs((logs) =>
30-
logs ? [...logs, ...e.parsedMessage] : [...e.parsedMessage],
31-
);
29+
setLogs((logs) => [...logs, ...e.parsedMessage]);
3230
});
3331

3432
socket.addEventListener("error", (e) => {

site/src/pages/WorkspacePage/WorkspacePage.test.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,7 @@ const renderWorkspacePage = async (
5151
jest
5252
.spyOn(API, "getDeploymentConfig")
5353
.mockResolvedValueOnce(MockDeploymentConfig);
54-
jest.spyOn(apiModule, "watchWorkspaceAgentLogs").mockImplementation(
55-
() =>
56-
new OneWayWebSocket({
57-
apiRoute: "",
58-
}),
59-
);
54+
jest.spyOn(apiModule, "watchWorkspaceAgentLogs");
6055

6156
renderWithAuth(<WorkspacePage />, {
6257
...options,

0 commit comments

Comments
 (0)