Skip to content

refactor(site): move workspace schedule controls to its own component #11281

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 2 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 0 additions & 10 deletions site/src/pages/WorkspacePage/Workspace.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,6 @@ type Story = StoryObj<typeof Workspace>;

export const Running: Story = {
args: {
scheduleProps: {
onDeadlineMinus: () => {
// do nothing, this is just for storybook
},
onDeadlinePlus: () => {
// do nothing, this is just for storybook
},
maxDeadlineDecrease: 0,
maxDeadlineIncrease: 24,
},
workspace: Mocks.MockWorkspace,
handleStart: action("start"),
handleStop: action("stop"),
Expand Down
11 changes: 0 additions & 11 deletions site/src/pages/WorkspacePage/Workspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@ export type WorkspaceError =
export type WorkspaceErrors = Partial<Record<WorkspaceError, unknown>>;

export interface WorkspaceProps {
scheduleProps: {
onDeadlinePlus: (hours: number) => void;
onDeadlineMinus: (hours: number) => void;
maxDeadlineIncrease: number;
maxDeadlineDecrease: number;
};
handleStart: (buildParameters?: TypesGen.WorkspaceBuildParameter[]) => void;
handleStop: () => void;
handleRestart: (buildParameters?: TypesGen.WorkspaceBuildParameter[]) => void;
Expand Down Expand Up @@ -81,7 +75,6 @@ export interface WorkspaceProps {
* Workspace is the top-level component for viewing an individual workspace
*/
export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({
scheduleProps,
handleStart,
handleStop,
handleRestart,
Expand Down Expand Up @@ -186,10 +179,6 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({
workspace={workspace}
handleUpdate={handleUpdate}
canUpdateWorkspace={canUpdateWorkspace}
maxDeadlineDecrease={scheduleProps.maxDeadlineDecrease}
maxDeadlineIncrease={scheduleProps.maxDeadlineIncrease}
onDeadlineMinus={scheduleProps.onDeadlineMinus}
onDeadlinePlus={scheduleProps.onDeadlinePlus}
/>

{canUpdateWorkspace && (
Expand Down
40 changes: 1 addition & 39 deletions site/src/pages/WorkspacePage/WorkspaceReadyPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@ import { useFeatureVisibility } from "hooks/useFeatureVisibility";
import { FC, useEffect, useState } from "react";
import { Helmet } from "react-helmet-async";
import { useNavigate } from "react-router-dom";
import {
getDeadline,
getMaxDeadline,
getMaxDeadlineChange,
getMinDeadline,
} from "utils/schedule";
import { Workspace } from "./Workspace";
import { pageTitle } from "utils/page";
import { hasJobError } from "utils/workspace";
Expand All @@ -29,16 +23,14 @@ import { useWorkspaceBuildLogs } from "hooks/useWorkspaceBuildLogs";
import {
activate,
changeVersion,
decreaseDeadline,
deleteWorkspace,
increaseDeadline,
updateWorkspace,
stopWorkspace,
startWorkspace,
cancelBuild,
} from "api/queries/workspaces";
import { getErrorMessage } from "api/errors";
import { displaySuccess, displayError } from "components/GlobalSnackbar/utils";
import { displayError } from "components/GlobalSnackbar/utils";
import { deploymentConfig, deploymentSSHConfig } from "api/queries/deployment";
import { WorkspacePermissions } from "./permissions";
import { workspaceResolveAutostart } from "api/queries/workspaceQuota";
Expand Down Expand Up @@ -101,27 +93,6 @@ export const WorkspaceReadyPage = ({
mutationFn: restartWorkspace,
});

// Schedule controls
const deadline = getDeadline(workspace);
const onDeadlineChangeSuccess = () => {
displaySuccess("Updated workspace shutdown time.");
};
const onDeadlineChangeFails = (error: unknown) => {
displayError(
getErrorMessage(error, "Failed to update workspace shutdown time."),
);
};
const decreaseMutation = useMutation({
...decreaseDeadline(workspace),
onSuccess: onDeadlineChangeSuccess,
onError: onDeadlineChangeFails,
});
const increaseMutation = useMutation({
...increaseDeadline(workspace),
onSuccess: onDeadlineChangeSuccess,
onError: onDeadlineChangeFails,
});

// Auto start
const canAutostartResponse = useQuery(
workspaceResolveAutostart(workspace.id),
Expand Down Expand Up @@ -227,15 +198,6 @@ export const WorkspaceReadyPage = ({
</Helmet>

<Workspace
scheduleProps={{
onDeadlineMinus: decreaseMutation.mutate,
onDeadlinePlus: increaseMutation.mutate,
maxDeadlineDecrease: getMaxDeadlineChange(deadline, getMinDeadline()),
maxDeadlineIncrease: getMaxDeadlineChange(
getMaxDeadline(workspace),
deadline,
),
}}
isUpdating={updateWorkspaceMutation.isLoading}
isRestarting={isRestarting}
workspace={workspace}
Expand Down
Loading