Skip to content

feat: batch workspace updates #11583

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 14 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
feat: batch workspace updates
  • Loading branch information
aslilac committed Jan 11, 2024
commit 07cdbc47c3e66fa9c42985c2f8eff63eb2600e31
20 changes: 18 additions & 2 deletions site/src/pages/WorkspacesPage/BatchActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import "dayjs/plugin/relativeTime";
import { type Interpolation, type Theme } from "@emotion/react";
import { type FC, type ReactNode, useState } from "react";
import { useMutation } from "react-query";
import { deleteWorkspace, startWorkspace, stopWorkspace } from "api/api";
import {
deleteWorkspace,
startWorkspace,
stopWorkspace,
updateWorkspace,
} from "api/api";
import type { Workspace } from "api/typesGenerated";
import { ConfirmDialog } from "components/Dialogs/ConfirmDialog/ConfirmDialog";
import { displayError } from "components/GlobalSnackbar/utils";
Expand Down Expand Up @@ -50,14 +55,25 @@ export function useBatchActions(options: UseBatchActionsProps) {
},
onSuccess,
onError: () => {
displayError("Failed to delete workspaces");
displayError("Failed to delete some workspaces");
},
});

const updateAllMutation = useMutation({
mutationFn: async (workspaces: Workspace[]) => {
return Promise.all(workspaces.map((w) => updateWorkspace(w)));
},
onSuccess,
onError: () => {
displayError("Failed to update some workspaces");
},
});

return {
startAll: startAllMutation.mutateAsync,
stopAll: stopAllMutation.mutateAsync,
deleteAll: deleteAllMutation.mutateAsync,
updateAll: updateAllMutation.mutateAsync,
isLoading:
startAllMutation.isLoading ||
stopAllMutation.isLoading ||
Expand Down
1 change: 1 addition & 0 deletions site/src/pages/WorkspacesPage/WorkspacesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ const WorkspacesPage: FC = () => {
onDeleteAll={() => {
setIsConfirmingDeleteAll(true);
}}
onUpdateAll={() => batchActions.updateAll(checkedWorkspaces)}
onStartAll={() => batchActions.startAll(checkedWorkspaces)}
onStopAll={() => batchActions.stopAll(checkedWorkspaces)}
/>
Expand Down
6 changes: 6 additions & 0 deletions site/src/pages/WorkspacesPage/WorkspacesPageView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { WorkspacesButton } from "./WorkspacesButton";
import { UseQueryResult } from "react-query";
import StopOutlined from "@mui/icons-material/StopOutlined";
import PlayArrowOutlined from "@mui/icons-material/PlayArrowOutlined";
import CloudQueue from "@mui/icons-material/CloudQueue";
import {
MoreMenu,
MoreMenuContent,
Expand Down Expand Up @@ -51,6 +52,7 @@ export interface WorkspacesPageViewProps {
onCheckChange: (checkedWorkspaces: Workspace[]) => void;
isRunningBatchAction: boolean;
onDeleteAll: () => void;
onUpdateAll: () => void;
onStartAll: () => void;
onStopAll: () => void;
canCheckWorkspaces: boolean;
Expand All @@ -71,6 +73,7 @@ export const WorkspacesPageView = ({
checkedWorkspaces,
onCheckChange,
onDeleteAll,
onUpdateAll,
onStopAll,
onStartAll,
isRunningBatchAction,
Expand Down Expand Up @@ -150,6 +153,9 @@ export const WorkspacesPageView = ({
<StopOutlined /> Stop
</MoreMenuItem>
<Divider />
<MoreMenuItem onClick={onUpdateAll}>
<CloudQueue /> Update&hellip;
</MoreMenuItem>
<MoreMenuItem danger onClick={onDeleteAll}>
<DeleteOutlined /> Delete&hellip;
</MoreMenuItem>
Expand Down
2 changes: 1 addition & 1 deletion site/src/theme/light/mui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const muiTheme = createTheme({
mode: "light",
primary: {
main: tw.sky[600],
contrastText: tw.sky[50],
contrastText: tw.sky[950],
light: tw.sky[400],
dark: tw.sky[500],
},
Expand Down