Skip to content

fix: make workspace buttons less confusing when errors happen #10609

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

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
refactor: remove needless types
  • Loading branch information
Parkreiner committed Nov 8, 2023
commit e39dc2dff150becfa493edf19ee32b73eb9419f8
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
UpdateButton,
ActivateButton,
} from "./Buttons";
import { ButtonMapping, actionsByWorkspaceStatus } from "./constants";
import { type ButtonType, actionsByWorkspaceStatus } from "./constants";

import Divider from "@mui/material/Divider";
import DuplicateIcon from "@mui/icons-material/FileCopyOutlined";
Expand Down Expand Up @@ -63,7 +63,7 @@ export const WorkspaceActions: FC<WorkspaceActionsProps> = ({
useWorkspaceDuplication(workspace);

// A mapping of button type to their corresponding React components
const buttonMapping: ButtonMapping = {
const buttonMapping: Record<ButtonType, ReactNode> = {
update: <UpdateButton handleAction={handleUpdate} />,
updating: <UpdateButton loading handleAction={handleUpdate} />,
start: <StartButton workspace={workspace} handleAction={handleStart} />,
Expand Down
11 changes: 3 additions & 8 deletions site/src/pages/WorkspacePage/WorkspaceActions/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { type Workspace, type WorkspaceStatus } from "api/typesGenerated";
import { type ReactNode } from "react";
import { workspaceUpdatePolicy } from "utils/workspace";

/**
Expand Down Expand Up @@ -29,10 +28,6 @@ const buttonTypes = [
*/
export type ButtonType = (typeof buttonTypes)[number];

export type ButtonMapping = {
[key in ButtonType]: ReactNode;
};

interface WorkspaceAbilities {
actions: ButtonType[];
canCancel: boolean;
Expand Down Expand Up @@ -99,15 +94,15 @@ const statusToActions: Record<WorkspaceStatus, WorkspaceAbilities> = {
canCancel: false,
canAcceptJobs: true,
},

// in the case of an error
failed: {
actions: ["start", "stop"],
canCancel: false,
canAcceptJobs: true,
},
/**
* disabled states
*/

// Disabled states
canceling: {
actions: ["canceling"],
canCancel: false,
Expand Down