Skip to content

Commit 2fe1d45

Browse files
committed
🧹
1 parent 7c692d4 commit 2fe1d45

File tree

3 files changed

+30
-29
lines changed

3 files changed

+30
-29
lines changed

site/src/pages/WorkspacePage/WorkspacePage.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ export const WorkspacePage: FC = () => {
7777
}
7878
},
7979
);
80+
const getWorkspaceData = useEffectEvent(() => {
81+
if (!workspace) {
82+
throw new Error("Applying an update for a workspace that is undefined.");
83+
}
84+
85+
return queryClient.getQueryData(
86+
workspaceQueryOptions.queryKey,
87+
) as Workspace;
88+
});
8089
const workspaceId = workspace?.id;
8190
useEffect(() => {
8291
if (!workspaceId) {
@@ -95,11 +104,7 @@ export const WorkspacePage: FC = () => {
95104
// Merge with a fresh object `{}` as the base, because `merge` uses an in-place algorithm,
96105
// and would otherwise mutate the `queryClient`'s internal state.
97106
await updateWorkspaceData(
98-
merge(
99-
{},
100-
queryClient.getQueryData(workspaceQueryOptions.queryKey) as Workspace,
101-
newWorkspaceData,
102-
),
107+
merge({}, getWorkspaceData(), newWorkspaceData),
103108
);
104109
});
105110

@@ -110,7 +115,7 @@ export const WorkspacePage: FC = () => {
110115
return () => {
111116
eventSource.close();
112117
};
113-
}, [updateWorkspaceData, workspaceId]);
118+
}, [updateWorkspaceData, getWorkspaceData, workspaceId]);
114119

115120
// Page statuses
116121
const pageError =

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

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,35 @@
11
import { render, screen } from "@testing-library/react";
2-
import { type FC } from "react";
2+
import userEvent from "@testing-library/user-event";
33
import { QueryClient, QueryClientProvider } from "react-query";
44
import { RouterProvider, createMemoryRouter } from "react-router-dom";
5-
import userEvent from "@testing-library/user-event";
65
import dayjs from "dayjs";
76
import * as API from "api/api";
87
import { GlobalSnackbar } from "components/GlobalSnackbar/GlobalSnackbar";
98
import { ThemeProvider } from "contexts/ThemeProvider";
109
import { MockTemplate, MockWorkspace } from "testHelpers/entities";
10+
import { getWorkspaceActivityStatus } from "modules/workspaces/activity";
1111
import { WorkspaceScheduleControls } from "./WorkspaceScheduleControls";
1212

13-
const Wrapper: FC = () => {
14-
return (
15-
<WorkspaceScheduleControls
16-
workspace={MockWorkspace}
17-
template={MockTemplate}
18-
canUpdateSchedule
19-
/>
20-
);
21-
};
22-
2313
const BASE_DEADLINE = dayjs().add(3, "hour");
2414

2515
const renderScheduleControls = async () => {
2616
render(
2717
<ThemeProvider>
2818
<QueryClientProvider client={new QueryClient()}>
2919
<RouterProvider
30-
router={createMemoryRouter([{ path: "/", element: <Wrapper /> }])}
20+
router={createMemoryRouter([
21+
{
22+
path: "/",
23+
element: (
24+
<WorkspaceScheduleControls
25+
workspace={MockWorkspace}
26+
status={getWorkspaceActivityStatus(MockWorkspace)}
27+
template={MockTemplate}
28+
canUpdateSchedule
29+
/>
30+
),
31+
},
32+
])}
3133
/>
3234
</QueryClientProvider>
3335
<GlobalSnackbar />

site/src/utils/schedule.tsx

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,9 @@ import utc from "dayjs/plugin/utc";
99
import { type ReactNode } from "react";
1010
import { Link as RouterLink } from "react-router-dom";
1111
import type { Template, Workspace } from "api/typesGenerated";
12-
import {
13-
HelpTooltipText,
14-
HelpTooltipTitle,
15-
} from "components/HelpTooltip/HelpTooltip";
12+
import { HelpTooltipTitle } from "components/HelpTooltip/HelpTooltip";
13+
import type { WorkspaceActivityStatus } from "modules/workspaces/activity";
1614
import { isWorkspaceOn } from "./workspace";
17-
import {
18-
WorkspaceActivityStatus,
19-
getWorkspaceActivityStatus,
20-
} from "modules/workspaces/activity";
2115

2216
// REMARK: some plugins depend on utc, so it's listed first. Otherwise they're
2317
// sorted alphabetically.
@@ -133,7 +127,7 @@ export const autostopDisplay = (
133127
message: `Required to stop soon`,
134128
tooltip: (
135129
<>
136-
<HelpTooltipTitle>Upcoming autostop required</HelpTooltipTitle>
130+
<HelpTooltipTitle>Upcoming stop required</HelpTooltipTitle>
137131
This workspace will be required to stop by{" "}
138132
{dayjs(workspace.latest_build.max_deadline).format(
139133
"MMMM D [at] h:mm A",
@@ -154,7 +148,7 @@ export const autostopDisplay = (
154148
<>
155149
{" "}
156150
because this workspace has enabled autostop. You can disable
157-
autostop from this workspace's{" "}
151+
autostop from this workspace&apos;s{" "}
158152
<Link component={RouterLink} to="settings/schedule">
159153
schedule settings
160154
</Link>

0 commit comments

Comments
 (0)