Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite96d69b

Browse files
feat: delete task from sidebar (#20023)
This adds a way to delete a task from the sidebar. Once this PR ismerged, I’ll also add the option to the table list.https://github.com/user-attachments/assets/75d714ef-afe1-4d9c-b907-1eab3a59f26bRight now, after deleting a task, the data still shows—that’s a separateissue related to how task data is loaded in the FE. A proper tasksendpoint is now available, and that should be addressed as part of[https://github.com/coder/internal/issues/904](https://github.com/coder/internal/issues/904).Related to#19525
1 parentbf021e6 commite96d69b

File tree

4 files changed

+274
-110
lines changed

4 files changed

+274
-110
lines changed

‎site/src/api/api.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2728,6 +2728,10 @@ class ExperimentalApiMethods {
27282728
prompt:prompts.prompts[workspace.latest_build.id],
27292729
}));
27302730
};
2731+
2732+
deleteTask=async(user:string,id:string):Promise<void>=>{
2733+
awaitthis.axios.delete(`/api/experimental/tasks/${user}/${id}`);
2734+
};
27312735
}
27322736

27332737
// This is a hard coded CSRF token/cookie pair for local development. In prod,

‎site/src/components/DropdownMenu/DropdownMenu.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const DropdownMenu = DropdownMenuPrimitive.Root;
2020

2121
exportconstDropdownMenuTrigger=DropdownMenuPrimitive.Trigger;
2222

23-
const_DropdownMenuGroup=DropdownMenuPrimitive.Group;
23+
exportconstDropdownMenuGroup=DropdownMenuPrimitive.Group;
2424

2525
const_DropdownMenuPortal=DropdownMenuPrimitive.Portal;
2626

‎site/src/modules/tasks/TasksSidebar/TasksSidebar.stories.tsx‎

Lines changed: 95 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import{MockTasks,MockUserOwner,mockApiError}from"testHelpers/entities";
2-
import{withAuthProvider}from"testHelpers/storybook";
2+
import{withAuthProvider,withGlobalSnackbar}from"testHelpers/storybook";
33
importtype{Meta,StoryObj}from"@storybook/react-vite";
44
import{API}from"api/api";
55
import{MockUsers}from"pages/UsersPage/storybookData/users";
6-
import{spyOn,userEvent,within}from"storybook/test";
6+
import{expect,spyOn,userEvent,waitFor,within}from"storybook/test";
77
import{reactRouterParameters}from"storybook-addon-remix-react-router";
88
import{TasksSidebar}from"./TasksSidebar";
99

@@ -17,6 +17,18 @@ const meta: Meta<typeof TasksSidebar> = {
1717
permissions:{
1818
viewAllUsers:true,
1919
},
20+
reactRouter:reactRouterParameters({
21+
location:{
22+
path:`/tasks/${MockTasks[0].workspace.name}`,
23+
pathParams:{
24+
workspace:MockTasks[0].workspace.name,
25+
},
26+
},
27+
routing:[
28+
{path:"/tasks/:workspace",useStoryElement:true},
29+
{path:"/tasks",element:<div>Tasks Index Page</div>},
30+
],
31+
}),
2032
},
2133
beforeEach:()=>{
2234
spyOn(API,"getUsers").mockResolvedValue({
@@ -49,16 +61,6 @@ export const Loaded: Story = {
4961
beforeEach:()=>{
5062
spyOn(API.experimental,"getTasks").mockResolvedValue(MockTasks);
5163
},
52-
parameters:{
53-
reactRouter:reactRouterParameters({
54-
location:{
55-
pathParams:{
56-
workspace:MockTasks[0].workspace.name,
57-
},
58-
},
59-
routing:{path:"/tasks/:workspace"},
60-
}),
61-
},
6264
};
6365

6466
exportconstEmpty:Story={
@@ -71,19 +73,90 @@ export const Closed: Story = {
7173
beforeEach:()=>{
7274
spyOn(API.experimental,"getTasks").mockResolvedValue(MockTasks);
7375
},
74-
parameters:{
75-
reactRouter:reactRouterParameters({
76-
location:{
77-
pathParams:{
78-
workspace:MockTasks[0].workspace.name,
79-
},
80-
},
81-
routing:{path:"/tasks/:workspace"},
82-
}),
83-
},
8476
play:async({ canvasElement})=>{
8577
constcanvas=within(canvasElement);
8678
constbutton=canvas.getByRole("button",{name:/closesidebar/i});
8779
awaituserEvent.click(button);
8880
},
8981
};
82+
83+
exportconstOpenOptionsMenu:Story={
84+
beforeEach:()=>{
85+
spyOn(API.experimental,"getTasks").mockResolvedValue(MockTasks);
86+
},
87+
play:async({ canvasElement})=>{
88+
constcanvas=within(canvasElement);
89+
constoptionButtons=awaitcanvas.findAllByRole("button",{
90+
name:/taskoptions/i,
91+
});
92+
awaituserEvent.click(optionButtons[0]);
93+
},
94+
};
95+
96+
exportconstDeleteTaskDialog:Story={
97+
beforeEach:()=>{
98+
spyOn(API.experimental,"getTasks").mockResolvedValue(MockTasks);
99+
},
100+
play:async({ canvasElement, step})=>{
101+
awaitstep("Open menu",async()=>{
102+
constcanvas=within(canvasElement);
103+
constoptionButtons=awaitcanvas.findAllByRole("button",{
104+
name:/taskoptions/i,
105+
});
106+
awaituserEvent.click(optionButtons[0]);
107+
});
108+
awaitstep("Open delete dialog",async()=>{
109+
constbody=within(canvasElement.ownerDocument.body);
110+
constdeleteButton=awaitbody.findByRole("menuitem",{
111+
name:/delete/i,
112+
});
113+
awaituserEvent.click(deleteButton);
114+
});
115+
},
116+
};
117+
118+
exportconstDeleteTaskSuccess:Story={
119+
decorators:[withGlobalSnackbar],
120+
parameters:{
121+
chromatic:{
122+
disableSnapshot:false,
123+
},
124+
},
125+
beforeEach:()=>{
126+
spyOn(API.experimental,"getTasks").mockResolvedValue(MockTasks);
127+
spyOn(API.experimental,"deleteTask").mockResolvedValue();
128+
},
129+
play:async({ canvasElement, step})=>{
130+
constbody=within(canvasElement.ownerDocument.body);
131+
constcanvas=within(canvasElement);
132+
133+
awaitstep("Open menu",async()=>{
134+
constoptionButtons=awaitcanvas.findAllByRole("button",{
135+
name:/taskoptions/i,
136+
});
137+
awaituserEvent.click(optionButtons[0]);
138+
});
139+
140+
awaitstep("Open delete dialog",async()=>{
141+
constdeleteButton=awaitbody.findByRole("menuitem",{
142+
name:/delete/i,
143+
});
144+
awaituserEvent.click(deleteButton);
145+
});
146+
147+
awaitstep("Confirm delete",async()=>{
148+
constconfirmButton=awaitbody.findByRole("button",{
149+
name:/delete/i,
150+
});
151+
awaituserEvent.click(confirmButton);
152+
awaitstep("Confirm delete",async()=>{
153+
awaitwaitFor(()=>{
154+
expect(API.experimental.deleteTask).toHaveBeenCalledWith(
155+
MockTasks[0].workspace.owner_name,
156+
MockTasks[0].workspace.id,
157+
);
158+
});
159+
});
160+
});
161+
},
162+
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp