MCPcopy Index your code
hub / github.com/coder/coder / useBatchActions

Function useBatchActions

site/src/pages/WorkspacesPage/batchActions.ts:28–141  ·  view source on GitHub ↗
(
	options: UseBatchActionsOptions,
)

Source from the content-addressed store, hash-verified

26}>;
27
28export function useBatchActions(
29 options: UseBatchActionsOptions,
30): UseBatchActionsResult {
31 const { onSuccess } = options;
32
33 const startAllMutation = useMutation({
34 mutationFn: (workspaces: readonly Workspace[]) => {
35 return Promise.all(
36 workspaces.map((w) =>
37 API.startWorkspace(w.id, w.latest_build.template_version_id),
38 ),
39 );
40 },
41 onSuccess,
42 onError: (error) => {
43 toast.error("Failed to start workspaces.", {
44 description: getErrorDetail(error),
45 });
46 },
47 });
48
49 const stopAllMutation = useMutation({
50 mutationFn: (workspaces: readonly Workspace[]) => {
51 return Promise.all(workspaces.map((w) => API.stopWorkspace(w.id)));
52 },
53 onSuccess,
54 onError: (error) => {
55 toast.error("Failed to stop workspaces.", {
56 description: getErrorDetail(error),
57 });
58 },
59 });
60
61 const deleteAllMutation = useMutation({
62 mutationFn: (workspaces: readonly Workspace[]) => {
63 return Promise.all(workspaces.map((w) => API.deleteWorkspace(w.id)));
64 },
65 onSuccess,
66 onError: (error) => {
67 toast.error("Failed to delete some workspaces.", {
68 description: getErrorDetail(error),
69 });
70 },
71 });
72
73 const updateAllMutation = useMutation({
74 mutationFn: (payload: UpdateAllPayload) => {
75 const { workspaces, isDynamicParametersEnabled } = payload;
76 return Promise.all(
77 workspaces
78 .filter((w) => w.outdated && !w.dormant_at)
79 .map((w) => API.updateWorkspace(w, [], isDynamicParametersEnabled)),
80 );
81 },
82 onSuccess,
83 onError: (error) => {
84 toast.error("Failed to update some workspaces.", {
85 description: getErrorDetail(error),

Callers 1

WorkspacesPageFunction · 0.90

Calls 7

getErrorDetailFunction · 0.90
allMethod · 0.80
startWorkspaceMethod · 0.80
filterMethod · 0.80
putFavoriteWorkspaceMethod · 0.80
deleteWorkspaceMethod · 0.65

Tested by

no test coverage detected