Skip to content

Commit e2e56d7

Browse files
refactor(site): move workspace schedule controls to its own component (coder#11281)
1 parent bfc5889 commit e2e56d7

File tree

5 files changed

+403
-401
lines changed

5 files changed

+403
-401
lines changed

site/src/pages/WorkspacePage/Workspace.stories.tsx

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,6 @@ type Story = StoryObj<typeof Workspace>;
6666

6767
export const Running: Story = {
6868
args: {
69-
scheduleProps: {
70-
onDeadlineMinus: () => {
71-
// do nothing, this is just for storybook
72-
},
73-
onDeadlinePlus: () => {
74-
// do nothing, this is just for storybook
75-
},
76-
maxDeadlineDecrease: 0,
77-
maxDeadlineIncrease: 24,
78-
},
7969
workspace: Mocks.MockWorkspace,
8070
handleStart: action("start"),
8171
handleStop: action("stop"),

site/src/pages/WorkspacePage/Workspace.tsx

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,6 @@ export type WorkspaceError =
3737
export type WorkspaceErrors = Partial<Record<WorkspaceError, unknown>>;
3838

3939
export interface WorkspaceProps {
40-
scheduleProps: {
41-
onDeadlinePlus: (hours: number) => void;
42-
onDeadlineMinus: (hours: number) => void;
43-
maxDeadlineIncrease: number;
44-
maxDeadlineDecrease: number;
45-
};
4640
handleStart: (buildParameters?: TypesGen.WorkspaceBuildParameter[]) => void;
4741
handleStop: () => void;
4842
handleRestart: (buildParameters?: TypesGen.WorkspaceBuildParameter[]) => void;
@@ -81,7 +75,6 @@ export interface WorkspaceProps {
8175
* Workspace is the top-level component for viewing an individual workspace
8276
*/
8377
export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({
84-
scheduleProps,
8578
handleStart,
8679
handleStop,
8780
handleRestart,
@@ -186,10 +179,6 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({
186179
workspace={workspace}
187180
handleUpdate={handleUpdate}
188181
canUpdateWorkspace={canUpdateWorkspace}
189-
maxDeadlineDecrease={scheduleProps.maxDeadlineDecrease}
190-
maxDeadlineIncrease={scheduleProps.maxDeadlineIncrease}
191-
onDeadlineMinus={scheduleProps.onDeadlineMinus}
192-
onDeadlinePlus={scheduleProps.onDeadlinePlus}
193182
/>
194183

195184
{canUpdateWorkspace && (

site/src/pages/WorkspacePage/WorkspaceReadyPage.tsx

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@ import { useFeatureVisibility } from "hooks/useFeatureVisibility";
33
import { FC, useEffect, useState } from "react";
44
import { Helmet } from "react-helmet-async";
55
import { useNavigate } from "react-router-dom";
6-
import {
7-
getDeadline,
8-
getMaxDeadline,
9-
getMaxDeadlineChange,
10-
getMinDeadline,
11-
} from "utils/schedule";
126
import { Workspace } from "./Workspace";
137
import { pageTitle } from "utils/page";
148
import { hasJobError } from "utils/workspace";
@@ -29,16 +23,14 @@ import { useWorkspaceBuildLogs } from "hooks/useWorkspaceBuildLogs";
2923
import {
3024
activate,
3125
changeVersion,
32-
decreaseDeadline,
3326
deleteWorkspace,
34-
increaseDeadline,
3527
updateWorkspace,
3628
stopWorkspace,
3729
startWorkspace,
3830
cancelBuild,
3931
} from "api/queries/workspaces";
4032
import { getErrorMessage } from "api/errors";
41-
import { displaySuccess, displayError } from "components/GlobalSnackbar/utils";
33+
import { displayError } from "components/GlobalSnackbar/utils";
4234
import { deploymentConfig, deploymentSSHConfig } from "api/queries/deployment";
4335
import { WorkspacePermissions } from "./permissions";
4436
import { workspaceResolveAutostart } from "api/queries/workspaceQuota";
@@ -101,27 +93,6 @@ export const WorkspaceReadyPage = ({
10193
mutationFn: restartWorkspace,
10294
});
10395

104-
// Schedule controls
105-
const deadline = getDeadline(workspace);
106-
const onDeadlineChangeSuccess = () => {
107-
displaySuccess("Updated workspace shutdown time.");
108-
};
109-
const onDeadlineChangeFails = (error: unknown) => {
110-
displayError(
111-
getErrorMessage(error, "Failed to update workspace shutdown time."),
112-
);
113-
};
114-
const decreaseMutation = useMutation({
115-
...decreaseDeadline(workspace),
116-
onSuccess: onDeadlineChangeSuccess,
117-
onError: onDeadlineChangeFails,
118-
});
119-
const increaseMutation = useMutation({
120-
...increaseDeadline(workspace),
121-
onSuccess: onDeadlineChangeSuccess,
122-
onError: onDeadlineChangeFails,
123-
});
124-
12596
// Auto start
12697
const canAutostartResponse = useQuery(
12798
workspaceResolveAutostart(workspace.id),
@@ -227,15 +198,6 @@ export const WorkspaceReadyPage = ({
227198
</Helmet>
228199

229200
<Workspace
230-
scheduleProps={{
231-
onDeadlineMinus: decreaseMutation.mutate,
232-
onDeadlinePlus: increaseMutation.mutate,
233-
maxDeadlineDecrease: getMaxDeadlineChange(deadline, getMinDeadline()),
234-
maxDeadlineIncrease: getMaxDeadlineChange(
235-
getMaxDeadline(workspace),
236-
deadline,
237-
),
238-
}}
239201
isUpdating={updateWorkspaceMutation.isLoading}
240202
isRestarting={isRestarting}
241203
workspace={workspace}

0 commit comments

Comments
 (0)