Skip to content

feat(site): add stop and start batch actions #10565

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
Nov 8, 2023
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
Prev Previous commit
Next Next commit
Add base
  • Loading branch information
BrunoQuaresma committed Nov 7, 2023
commit 8994d1b67d1080386d2a931a1928ef9147825717
4 changes: 2 additions & 2 deletions site/src/components/MoreMenu/MoreMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ const useMoreMenuContext = () => {
return ctx;
};

export const MoreMenuTrigger = (props: HTMLProps<HTMLButtonElement>) => {
export const MoreMenuTrigger = ({ children, ...props }: HTMLProps<HTMLButtonElement>) => {
const menu = useMoreMenuContext();

return cloneElement(props.children as ReactElement, {
return cloneElement(children as ReactElement, {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this type-safe? My worry is that it looks like there's nothing restricting the type of children at the type level, so if someone accidentally passes in a string or a primitive as a prop, they would get a more cryptic runtime error

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I swear I tried my best to get a correct type for this without success :(

"aria-haspopup": "true",
...props,
ref: menu.triggerRef,
Expand Down
2 changes: 2 additions & 0 deletions site/src/pages/WorkspacesPage/WorkspacesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ const WorkspacesPage: FC = () => {
onDeleteAll={() => {
setIsDeletingAll(true);
}}
onStartAll={() => {}}
onStopAll={() => {}}
/>

<BatchDeleteConfirmation
Expand Down
109 changes: 106 additions & 3 deletions site/src/pages/WorkspacesPage/WorkspacesPageView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@ import Button from "@mui/material/Button";
import DeleteOutlined from "@mui/icons-material/DeleteOutlined";
import { WorkspacesButton } from "./WorkspacesButton";
import { UseQueryResult } from "react-query";
import StopOutlined from "@mui/icons-material/StopOutlined";
import PlayArrowOutlined from "@mui/icons-material/PlayArrowOutlined";
import {
MoreMenu,
MoreMenuContent,
MoreMenuItem,
MoreMenuTrigger,
} from "components/MoreMenu/MoreMenu";
import {
ArrowDropDown,
ArrowDropDownOutlined,
KeyboardArrowDownOutlined,
} from "@mui/icons-material";
import { Divider } from "@mui/material";

export const Language = {
pageTitle: "Workspaces",
Expand All @@ -46,6 +60,8 @@ export interface WorkspacesPageViewProps {
onUpdateWorkspace: (workspace: Workspace) => void;
onCheckChange: (checkedWorkspaces: Workspace[]) => void;
onDeleteAll: () => void;
onStartAll: () => void;
onStopAll: () => void;
canCheckWorkspaces: boolean;
templatesFetchStatus: TemplateQuery["status"];
templates: TemplateQuery["data"];
Expand All @@ -65,6 +81,8 @@ export const WorkspacesPageView = ({
checkedWorkspaces,
onCheckChange,
onDeleteAll,
onStopAll,
onStartAll,
canCheckWorkspaces,
templates,
templatesFetchStatus,
Expand Down Expand Up @@ -128,15 +146,100 @@ export const WorkspacesPageView = ({
{workspaces?.length === 1 ? "workspace" : "workspaces"}
</Box>

<Box sx={{ marginLeft: "auto" }}>
<MoreMenu>
<MoreMenuTrigger>
<Button
variant="text"
size="small"
css={{ borderRadius: 9999, marginLeft: "auto" }}
endIcon={<KeyboardArrowDownOutlined />}
>
Actions
</Button>
</MoreMenuTrigger>
<MoreMenuContent>
<MoreMenuItem
disabled={
!checkedWorkspaces?.every(
(w) => w.latest_build.status === "stopped",
)
}
>
<PlayArrowOutlined /> Start
</MoreMenuItem>
<MoreMenuItem
disabled={
!checkedWorkspaces?.every(
(w) => w.latest_build.status === "running",
)
}
>
<StopOutlined /> Stop
</MoreMenuItem>
<Divider />
<MoreMenuItem danger onClick={onDeleteAll}>
<DeleteOutlined /> Delete
</MoreMenuItem>
</MoreMenuContent>
</MoreMenu>
{/* <div
css={{
marginLeft: "auto",
display: "flex",
gap: 8,
alignItems: "center",
}}
>
<Button
disabled={
!workspaces?.every((w) => w.latest_build.status === "stopped")
}
variant="text"
size="small"
// Needs some manual adjustment to align with the delete button icon
startIcon={
<PlayArrowOutlined css={{ width: 16, height: 16 }} />
}
onClick={onStartAll}
>
Start
</Button>
<div
css={(theme) => ({
width: 1,
height: 12,
backgroundColor: theme.palette.divider,
})}
/>
<Button
variant="text"
disabled={
!workspaces?.every((w) => w.latest_build.status === "running")
}
size="small"
// Needs some manual adjustment to align with the delete button icon
startIcon={<StopOutlined css={{ width: 16, height: 16 }} />}
onClick={onStopAll}
>
Stop
</Button>
<div
css={(theme) => ({
width: 1,
height: 12,
backgroundColor: theme.palette.divider,
})}
/>
<Button
variant="text"
size="small"
startIcon={<DeleteOutlined />}
onClick={onDeleteAll}
color="error"
>
Delete selected
Delete
</Button>
</Box>
</div> */}
</>
) : (
<PaginationStatus
Expand Down
4 changes: 2 additions & 2 deletions site/src/theme/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,8 @@ dark = createTheme(dark, {
root: {
// It should be the same as the menu padding
"& .MuiDivider-root": {
marginTop: 4,
marginBottom: 4,
marginTop: `4px !important`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this solving a bug, or is this more just a precaution?
I'm just worried about !important introducing specificity wars if any components ever need to override this

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solving an issue. In this case, MUI is doing a very long chain to apply this style and I was not able to figure out how to make that happen here so I just used !important even not proud of that 😞

marginBottom: `4px !important`,
},
},
},
Expand Down