8000 [pull] main from coder:main by pull[bot] · Pull Request #152 · Klomgor/coder · GitHub
[go: up one dir, main page]

Skip to content

[pull] main from coder:main #152

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 9 commits into from
Jun 30, 2025
Prev Previous commit
Next Next commit
fix: display error message on delete workspace error (coder#18654)
resolves coder/preview#155

When deleting a workspace, show an error dialog if deleting the
workspace is not possible.

![Screenshot 2025-06-28 at 10 06
47](https://github.com/user-attachments/assets/650bfb54-6ed9-4f41-a410-1333afeee0a4)
  • Loading branch information
jaaydenh authored Jun 30, 2025
commit ad6773360cac2f090c0f2ffe8ff72993a0e959a0
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ interface WorkspaceErrorDialogProps {
workspaceOwner: string;
workspaceName: string;
templateVersionId: string;
isDeleting: boolean;
}

export const WorkspaceErrorDialog: FC<WorkspaceErrorDialogProps> = ({
Expand All @@ -29,6 +30,7 @@ export const WorkspaceErrorDialog: FC<WorkspaceErrorDialogProps> = ({
workspaceOwner,
workspaceName,
templateVersionId,
isDeleting,
}) => {
const navigate = useNavigate();

Expand All @@ -52,7 +54,9 @@ export const WorkspaceErrorDialog: FC<WorkspaceErrorDialogProps> = ({
<Dialog open={open} onOpenChange={(isOpen) => !isOpen && onClose()}>
<DialogContent variant="destructive">
<DialogHeader>
<DialogTitle>Error building workspace</DialogTitle>
<DialogTitle>
Error {isDeleting ? "deleting" : "building"} workspace
</DialogTitle>
<DialogDescription className="flex flex-row gap-4">
<strong className="text-content-primary">Message</strong>{" "}
<span>{getErrorMessage(error, "Failed to build workspace.")}</span>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { MissingBuildParameters } from "api/api";
import { isApiError } from "api/errors";
import { type ApiError, getErrorMessage } from "api/errors";
import {
changeVersion,
deleteWorkspace,
Expand All @@ -13,6 +15,7 @@ import {
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "components/DropdownMenu/DropdownMenu";
import { displayError } from "components/GlobalSnackbar/utils";
import {
CopyIcon,
DownloadIcon,
Expand All @@ -24,6 +27,7 @@ import {
import { type FC, useEffect, useState } from "react";
import { useMutation, useQuery, useQueryClient } from "react-query";
import { Link as RouterLink } from "react-router-dom";
import { WorkspaceErrorDialog } from "../ErrorDialog/WorkspaceErrorDialog";
import { ChangeWorkspaceVersionDialog } from "./ChangeWorkspaceVersionDialog";
import { DownloadLogsDialog } from "./DownloadLogsDialog";
import { UpdateBuildParametersDialog } from "./UpdateBuildParametersDialog";
Expand All @@ -42,6 +46,11 @@ export const WorkspaceMoreActions: FC<WorkspaceMoreActionsProps> = ({
}) => {
const queryClient = useQueryClient();

const [workspaceErrorDialog, setWorkspaceErrorDialog] = useState<{
open: boolean;
error?: ApiError;
}>({ open: false });

// Permissions
const { data: permissions } = useQuery(workspacePermissions(workspace));

Expand All @@ -58,11 +67,25 @@ export const WorkspaceMoreActions: FC<WorkspaceMoreActionsProps> = ({
),
);

const handleError = (error: unknown) => {
if (isApiError(error) && error.code === "ERR_BAD_REQUEST") {
setWorkspaceErrorDialog({
open: true,
error: error,
});
} else {
displayError(getErrorMessage(error, "Failed to delete workspace."));
}
};

// Delete
const [isConfirmingDelete, setIsConfirmingDelete] = useState(false);
const deleteWorkspaceMutation = useMutation(
deleteWorkspace(workspace, queryClient),
);
const deleteWorkspaceMutation = useMutation({
...deleteWorkspace(workspace, queryClient),
onError: (error: unknown) => {
handleError(error);
},
});

// Duplicate
const { duplicateWorkspace, isDuplicationReady } =
Expand Down Expand Up @@ -212,6 +235,17 @@ export const WorkspaceMoreActions: FC<WorkspaceMoreActionsProps> = ({
setIsConfirmingDelete(false);
}}
/>

<WorkspaceErrorDialog
open={workspaceErrorDialog.open}
error={workspaceErrorDialog.error}
onClose={() => setWorkspaceErrorDialog({ open: false })}
showDetail={workspace.template_use_classic_parameter_flow}
workspaceOwner={workspace.owner_name}
workspaceName={workspace.name}
templateVersionId={workspace.latest_build.template_version_id}
isDeleting={true}
/>
</>
);
};
1 change: 1 addition & 0 deletions site/src/pages/WorkspacePage/WorkspaceReadyPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ export const WorkspaceReadyPage: FC<WorkspaceReadyPageProps> = ({
workspaceOwner={workspace.owner_name}
workspaceName={workspace.name}
templateVersionId={workspace.latest_build.template_version_id}
isDeleting={false}
/>
</>
);
Expand Down
0