- Notifications
You must be signed in to change notification settings - Fork1k
feat: add remove task button into the tasks list#20036
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { MockTasks, MockWorkspace } from "testHelpers/entities"; | ||
import { withGlobalSnackbar } from "testHelpers/storybook"; | ||
import type { Meta, StoryObj } from "@storybook/react-vite"; | ||
import { API } from "api/api"; | ||
import { expect, spyOn, userEvent, waitFor, within } from "storybook/test"; | ||
import { TaskDeleteDialog } from "./TaskDeleteDialog"; | ||
const meta: Meta<typeof TaskDeleteDialog> = { | ||
title: "modules/tasks/TaskDeleteDialog", | ||
component: TaskDeleteDialog, | ||
decorators: [withGlobalSnackbar], | ||
}; | ||
export default meta; | ||
type Story = StoryObj<typeof TaskDeleteDialog>; | ||
export const DeleteTaskSuccess: Story = { | ||
decorators: [withGlobalSnackbar], | ||
args: { | ||
open: true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Do we also need to pass in CollaboratorAuthor
| ||
task: { prompt: "My Task", workspace: MockWorkspace }, | ||
onClose: () => {}, | ||
}, | ||
parameters: { | ||
chromatic: { | ||
disableSnapshot: false, | ||
}, | ||
}, | ||
beforeEach: () => { | ||
spyOn(API.experimental, "deleteTask").mockResolvedValue(); | ||
}, | ||
play: async ({ canvasElement, step }) => { | ||
const body = within(canvasElement.ownerDocument.body); | ||
await step("Confirm delete", async () => { | ||
const confirmButton = await body.findByRole("button", { | ||
name: /delete/i, | ||
}); | ||
await userEvent.click(confirmButton); | ||
await step("Confirm delete", async () => { | ||
await waitFor(() => { | ||
expect(API.experimental.deleteTask).toHaveBeenCalledWith( | ||
MockTasks[0].workspace.owner_name, | ||
MockTasks[0].workspace.id, | ||
); | ||
}); | ||
}); | ||
}); | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { API } from "api/api"; | ||
import { getErrorDetail, getErrorMessage } from "api/errors"; | ||
import { ConfirmDialog } from "components/Dialogs/ConfirmDialog/ConfirmDialog"; | ||
import { displayError, displaySuccess } from "components/GlobalSnackbar/utils"; | ||
import type { FC } from "react"; | ||
import { QueryClient, useMutation } from "react-query"; | ||
import type { Task } from "../tasks"; | ||
type TaskDeleteDialogProps = { | ||
open: boolean; | ||
task: Task; | ||
onClose: () => void; | ||
onSuccess?: () => void; | ||
}; | ||
export const TaskDeleteDialog: FC<TaskDeleteDialogProps> = ({ | ||
task, | ||
onSuccess, | ||
...props | ||
}) => { | ||
const queryClient = new QueryClient(); | ||
const deleteTaskMutation = useMutation({ | ||
mutationFn: () => | ||
API.experimental.deleteTask(task.workspace.owner_name, task.workspace.id), | ||
onSuccess: async () => { | ||
await queryClient.invalidateQueries({ queryKey: ["tasks"] }); | ||
}, | ||
}); | ||
return ( | ||
<ConfirmDialog | ||
{...props} | ||
type="delete" | ||
confirmLoading={deleteTaskMutation.isPending} | ||
title="Delete task" | ||
onConfirm={async () => { | ||
try { | ||
await deleteTaskMutation.mutateAsync(); | ||
displaySuccess("Task deleted successfully"); | ||
onSuccess?.(); | ||
} catch (error) { | ||
displayError( | ||
getErrorMessage(error, "Failed to delete task"), | ||
getErrorDetail(error), | ||
); | ||
} finally { | ||
props.onClose(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Just curious if there is a reason There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I might be misunderstanding, but No big deal though, just wondered if there was a reason for it or was just random. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. You're right, my bad. | ||
} | ||
}} | ||
description={ | ||
<p> | ||
This action is irreversible and removes all workspace resources and | ||
data. | ||
</p> | ||
} | ||
/> | ||
); | ||
}; |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.