Skip to content

fix: display explicit 'retry' button(s) when a workspace fails #10720

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 16 commits into from
Nov 22, 2023
Merged
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
merge main
  • Loading branch information
Parkreiner committed Nov 22, 2023
commit 44f86d54acc37e46573fb7ccc821027dbda7387d
12 changes: 8 additions & 4 deletions site/src/pages/WorkspacePage/WorkspaceActions/Buttons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { type FC } from "react";
import type { Workspace, WorkspaceBuildParameter } from "api/typesGenerated";
import { BuildParametersPopover } from "./BuildParametersPopover";

import Tooltip from "@mui/material/Tooltip";
import Button from "@mui/material/Button";
import LoadingButton from "@mui/lab/LoadingButton";
import ButtonGroup from "@mui/material/ButtonGroup";
Expand Down Expand Up @@ -65,7 +66,7 @@ export const StartButton: FC<
<ButtonGroup
variant="outlined"
sx={{
// Workaround to make the border transitions smmothly on button groups
// Workaround to make the border transitions smoothly on button groups
"& > button:hover + button": {
borderLeft: "1px solid #FFF",
},
Expand Down Expand Up @@ -123,7 +124,7 @@ export const RestartButton: FC<
<ButtonGroup
variant="outlined"
sx={{
// Workaround to make the border transitions smmothly on button groups
// Workaround to make the border transitions smoothly on button groups
"& > button:hover + button": {
borderLeft: "1px solid #FFF",
},
Expand Down Expand Up @@ -191,7 +192,10 @@ type DebugButtonProps = Omit<WorkspaceActionProps, "loading"> & {
debug?: boolean;
};

export function RetryButton({ handleAction, debug = false }: DebugButtonProps) {
export const RetryButton = ({
handleAction,
debug = false,
}: DebugButtonProps) => {
return (
<Button
startIcon={debug ? <RetryDebugIcon /> : <RetryIcon />}
Expand All @@ -200,4 +204,4 @@ export function RetryButton({ handleAction, debug = false }: DebugButtonProps) {
Retry{debug && " (Debug)"}
</Button>
);
}
};
67 changes: 54 additions & 13 deletions site/src/pages/WorkspacePage/WorkspaceActions/WorkspaceActions.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { type FC, type ReactNode, Fragment } from "react";
import { Workspace, WorkspaceBuildParameter } from "api/typesGenerated";
import { useWorkspaceDuplication } from "pages/CreateWorkspacePage/useWorkspaceDuplication";

import { workspaceUpdatePolicy } from "utils/workspace";
import { type ButtonType, actionsByWorkspaceStatus } from "./constants";

import {
ActionLoadingButton,
CancelButton,
Expand All @@ -12,7 +16,6 @@ import {
ActivateButton,
RetryButton,
} from "./Buttons";
import { type ButtonType, actionsByWorkspaceStatus } from "./constants";

import Divider from "@mui/material/Divider";
import DuplicateIcon from "@mui/icons-material/FileCopyOutlined";
Expand All @@ -27,7 +30,6 @@ import {
MoreMenuTrigger,
ThreeDotsButton,
} from "components/MoreMenu/MoreMenu";
import { workspaceUpdatePolicy } from "utils/workspace";

export interface WorkspaceActionsProps {
workspace: Workspace;
Expand Down Expand Up @@ -70,18 +72,48 @@ export const WorkspaceActions: FC<WorkspaceActionsProps> = ({
const { duplicateWorkspace, isDuplicationReady } =
useWorkspaceDuplication(workspace);

// A mapping of button type to their corresponding React components
const { actions, canCancel, canAcceptJobs } = actionsByWorkspaceStatus(
workspace,
canRetryDebug,
);

const disabled =
workspaceUpdatePolicy(workspace, canChangeVersions) === "always" &&
workspace.outdated;

const tooltipText = getTooltipText(workspace, disabled);
const canBeUpdated = workspace.outdated && canAcceptJobs;

// A mapping of button type to the corresponding React component
const buttonMapping: Record<ButtonType, ReactNode> = {
update: <UpdateButton handleAction={handleUpdate} />,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lot of diffs, but only two major things changed:

  • Enums got factored out, cleaning up how the properties were defined
  • retry and retryDebug properties got added

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that enum was my complication; thanks for fixing :)

updating: <UpdateButton loading handleAction={handleUpdate} />,
start: <StartButton workspace={workspace} handleAction={handleStart} />,
start: (
<StartButton
workspace={workspace}
handleAction={handleStart}
disabled={disabled}
tooltipText={tooltipText}
/>
),
starting: (
<StartButton loading workspace={workspace} handleAction={handleStart} />
<StartButton
loading
workspace={workspace}
handleAction={handleStart}
disabled={disabled}
tooltipText={tooltipText}
/>
),
stop: <StopButton handleAction={handleStop} />,
stopping: <StopButton loading handleAction={handleStop} />,
restart: (
<RestartButton workspace={workspace} handleAction={handleRestart} />
<RestartButton
workspace={workspace}
handleAction={handleRestart}
disabled={disabled}
tooltipText={tooltipText}
/>
),
restarting: (
<RestartButton
Expand All @@ -102,13 +134,6 @@ export const WorkspaceActions: FC<WorkspaceActionsProps> = ({
retryDebug: <RetryButton debug handleAction={handleRetryDebug} />,
};

const { actions, canCancel, canAcceptJobs } = actionsByWorkspaceStatus(
workspace,
{ canChangeVersions, canRetryDebug },
);

const canBeUpdated = workspace.outdated && canAcceptJobs;

return (
<div
css={{ display: "flex", alignItems: "center", gap: 12 }}
Expand Down Expand Up @@ -173,3 +198,19 @@ export const WorkspaceActions: FC<WorkspaceActionsProps> = ({
</div>
);
};

function getTooltipText(workspace: Workspace, disabled: boolean): string {
if (!disabled) {
return "";
}

if (workspace.template_require_active_version) {
return "This template requires automatic updates";
}

if (workspace.automatic_updates === "always") {
return "You have enabled automatic updates for this workspace";
}

return "";
}
32 changes: 2 additions & 30 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 { workspaceUpdatePolicy } from "utils/workspace";

/**
* An iterable of all button types supported by the workspace actions UI
Expand Down Expand Up @@ -40,14 +39,9 @@ type WorkspaceAbilities = {
canAcceptJobs: boolean;
};

type UserInfo = Readonly<{
canChangeVersions: boolean;
canRetryDebug: boolean;
}>;

export const actionsByWorkspaceStatus = (
workspace: Workspace,
userInfo: UserInfo,
canRetryDebug: boolean,
): WorkspaceAbilities => {
if (workspace.dormant_at) {
return {
Expand All @@ -58,29 +52,7 @@ export const actionsByWorkspaceStatus = (
}

const status = workspace.latest_build.status;
const mustUpdate =
workspace.outdated &&
workspaceUpdatePolicy(workspace, userInfo.canChangeVersions) === "always";

if (mustUpdate) {
if (status === "running") {
return {
actions: ["stop"],
canCancel: false,
canAcceptJobs: true,
};
}

if (status === "stopped") {
return {
actions: [],
canCancel: false,
canAcceptJobs: true,
};
}
}

if (status === "failed" && userInfo.canRetryDebug) {
if (status === "failed" && canRetryDebug) {
return {
...statusToActions.failed,
actions: ["retry", "retryDebug"],
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.