Skip to content

feat: add stop workspace button with confirmation dialog #18372

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
37 changes: 36 additions & 1 deletion site/src/pages/WorkspacesPage/WorkspacesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { Avatar } from "components/Avatar/Avatar";
import { AvatarData } from "components/Avatar/AvatarData";
import { AvatarDataSkeleton } from "components/Avatar/AvatarDataSkeleton";
import { Button } from "components/Button/Button";
import { ConfirmDialog } from "components/Dialogs/ConfirmDialog/ConfirmDialog";
import { ExternalImage } from "components/ExternalImage/ExternalImage";
import { VSCodeIcon } from "components/Icons/VSCodeIcon";
import { VSCodeInsidersIcon } from "components/Icons/VSCodeInsidersIcon";
Expand Down Expand Up @@ -49,6 +50,7 @@ import {
BanIcon,
PlayIcon,
RefreshCcwIcon,
SquareIcon,
SquareTerminalIcon,
} from "lucide-react";
import {
Expand All @@ -74,6 +76,7 @@ import {
type PropsWithChildren,
type ReactNode,
useMemo,
useState,
} from "react";
import { useMutation, useQuery, useQueryClient } from "react-query";
import { useNavigate } from "react-router-dom";
Expand Down Expand Up @@ -491,6 +494,9 @@ const WorkspaceActionsCell: FC<WorkspaceActionsCellProps> = ({
onError: onActionError,
});

// State for stop confirmation dialog
const [isStopConfirmOpen, setIsStopConfirmOpen] = useState(false);

const isRetrying =
startWorkspaceMutation.isPending ||
stopWorkspaceMutation.isPending ||
Expand Down Expand Up @@ -535,6 +541,16 @@ const WorkspaceActionsCell: FC<WorkspaceActionsCellProps> = ({
</PrimaryAction>
)}

{abilities.actions.includes("stop") && (
<PrimaryAction
onClick={() => setIsStopConfirmOpen(true)}
isLoading={stopWorkspaceMutation.isPending}
label="Stop workspace"
>
<SquareIcon />
</PrimaryAction>
)}

{abilities.actions.includes("updateAndStart") && (
<>
<PrimaryAction
Expand Down Expand Up @@ -573,6 +589,20 @@ const WorkspaceActionsCell: FC<WorkspaceActionsCellProps> = ({
disabled={!abilities.canAcceptJobs}
/>
</div>

{/* Stop workspace confirmation dialog */}
<ConfirmDialog
open={isStopConfirmOpen}
title="Stop workspace"
description={`Are you sure you want to stop the workspace "${workspace.name}"? This will terminate all running processes and disconnect any active sessions.`}
confirmText="Stop"
onClose={() => setIsStopConfirmOpen(false)}
onConfirm={() => {
stopWorkspaceMutation.mutate({});
setIsStopConfirmOpen(false);
}}
type="delete"
/>
</TableCell>
);
};
Expand All @@ -593,7 +623,12 @@ const PrimaryAction: FC<PrimaryActionProps> = ({
<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>
<Button variant="outline" size="icon-lg" onClick={onClick}>
<Button
variant="outline"
size="icon-lg"
onClick={onClick}
disabled={isLoading}
>
<Spinner loading={isLoading}>{children}</Spinner>
<span className="sr-only">{label}</span>
</Button>
Expand Down
Loading