Skip to content

Commit 68e5a51

Browse files
feat(site): display builds logs by default (#11597)
1 parent ec166cf commit 68e5a51

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

site/src/hooks/useWorkspaceBuildLogs.ts

+13-7
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
import { watchBuildLogsByBuildId } from "api/api";
22
import { ProvisionerJobLog } from "api/typesGenerated";
33
import { displayError } from "components/GlobalSnackbar/utils";
4-
import { useState, useEffect } from "react";
4+
import { useState, useEffect, useRef } from "react";
55

6-
// buildId is optional because sometimes the build is not loaded yet
7-
export const useWorkspaceBuildLogs = (buildId?: string) => {
6+
export const useWorkspaceBuildLogs = (
7+
// buildId is optional because sometimes the build is not loaded yet
8+
buildId: string | undefined,
9+
enabled: boolean = true,
10+
) => {
811
const [logs, setLogs] = useState<ProvisionerJobLog[]>();
12+
const socket = useRef<WebSocket>();
13+
914
useEffect(() => {
10-
if (!buildId) {
15+
if (!buildId || !enabled) {
16+
socket.current?.close();
1117
return;
1218
}
1319

1420
// Every time this hook is called reset the values
1521
setLogs(undefined);
1622

17-
const socket = watchBuildLogsByBuildId(buildId, {
23+
socket.current = watchBuildLogsByBuildId(buildId, {
1824
// Retrieve all the logs
1925
after: -1,
2026
onMessage: (log) => {
@@ -31,9 +37,9 @@ export const useWorkspaceBuildLogs = (buildId?: string) => {
3137
});
3238

3339
return () => {
34-
socket.close();
40+
socket.current?.close();
3541
};
36-
}, [buildId]);
42+
}, [buildId, enabled]);
3743

3844
return logs;
3945
};

site/src/pages/WorkspacePage/WorkspaceReadyPage.tsx

+5-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { Helmet } from "react-helmet-async";
55
import { useNavigate } from "react-router-dom";
66
import { Workspace } from "./Workspace";
77
import { pageTitle } from "utils/page";
8-
import { hasJobError } from "utils/workspace";
98
import { UpdateBuildParametersDialog } from "./UpdateBuildParametersDialog";
109
import { ChangeVersionDialog } from "./ChangeVersionDialog";
1110
import { useMutation, useQuery, useQueryClient } from "react-query";
@@ -67,12 +66,11 @@ export const WorkspaceReadyPage = ({
6766
});
6867

6968
// Build logs
70-
const buildLogs = useWorkspaceBuildLogs(workspace.latest_build.id);
71-
const shouldDisplayBuildLogs =
72-
hasJobError(workspace) ||
73-
["canceling", "deleting", "pending", "starting", "stopping"].includes(
74-
workspace.latest_build.status,
75-
);
69+
const shouldDisplayBuildLogs = workspace.latest_build.status !== "running";
70+
const buildLogs = useWorkspaceBuildLogs(
71+
workspace.latest_build.id,
72+
shouldDisplayBuildLogs,
73+
);
7674

7775
// Restart
7876
const [confirmingRestart, setConfirmingRestart] = useState<{

0 commit comments

Comments
 (0)