Skip to content

Commit 1dacdd9

Browse files
committed
Add left bar to the sidebar
1 parent ec87d6b commit 1dacdd9

File tree

2 files changed

+68
-6
lines changed

2 files changed

+68
-6
lines changed

site/src/components/FullPageLayout/Sidebar.tsx

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Interpolation, Theme, useTheme } from "@mui/material/styles";
2-
import { HTMLAttributes } from "react";
2+
import { ComponentProps, HTMLAttributes } from "react";
33
import { Link, LinkProps } from "react-router-dom";
4+
import { TopbarIconButton } from "./Topbar";
45

56
export const Sidebar = (props: HTMLAttributes<HTMLDivElement>) => {
67
const theme = useTheme();
@@ -47,6 +48,35 @@ export const SidebarCaption = (props: HTMLAttributes<HTMLSpanElement>) => {
4748
);
4849
};
4950

51+
export const SidebarIconButton = (
52+
props: { isActive: boolean } & ComponentProps<typeof TopbarIconButton>,
53+
) => {
54+
const theme = useTheme();
55+
56+
return (
57+
<TopbarIconButton
58+
css={[
59+
{ opacity: 0.75, "&:hover": { opacity: 1 } },
60+
props.isActive && {
61+
opacity: 1,
62+
position: "relative",
63+
"&::before": {
64+
content: '""',
65+
position: "absolute",
66+
left: 0,
67+
top: 0,
68+
bottom: 0,
69+
width: 2,
70+
backgroundColor: theme.palette.primary.main,
71+
height: "100%",
72+
},
73+
},
74+
]}
75+
{...props}
76+
/>
77+
);
78+
};
79+
5080
const styles = {
5181
sidebarItem: (theme: Theme) => ({
5282
fontSize: 13,

site/src/pages/WorkspacePage/Workspace.tsx

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { type Interpolation, type Theme } from "@emotion/react";
22
import Button from "@mui/material/Button";
33
import AlertTitle from "@mui/material/AlertTitle";
44
import { type FC, useEffect, useState } from "react";
5-
import { useNavigate } from "react-router-dom";
5+
import { useNavigate, useSearchParams } from "react-router-dom";
66
import dayjs from "dayjs";
77
import type * as TypesGen from "api/typesGenerated";
88
import { Alert, AlertDetail } from "components/Alert/Alert";
@@ -21,6 +21,9 @@ import { WorkspaceTopbar } from "./WorkspaceTopbar";
2121
import { HistorySidebar } from "./HistorySidebar";
2222
import { dashboardContentBottomPadding, navHeight } from "theme/constants";
2323
import { bannerHeight } from "components/Dashboard/DeploymentBanner/DeploymentBannerView";
24+
import HistoryOutlined from "@mui/icons-material/HistoryOutlined";
25+
import { useTheme } from "@mui/material/styles";
26+
import { SidebarIconButton } from "components/FullPageLayout/Sidebar";
2427

2528
export type WorkspaceError =
2629
| "getBuildsError"
@@ -94,6 +97,9 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({
9497
}) => {
9598
const navigate = useNavigate();
9699
const { saveLocal, getLocal } = useLocalStorage();
100+
const theme = useTheme();
101+
102+
const [searchParams, setSearchParams] = useSearchParams();
97103

98104
const [showAlertPendingInQueue, setShowAlertPendingInQueue] = useState(false);
99105

@@ -148,8 +154,8 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({
148154
flex: 1,
149155
display: "grid",
150156
gridTemplate: `
151-
"topbar topbar" auto
152-
"sidebar content" 1fr / auto 1fr
157+
"topbar topbar topbar" auto
158+
"leftbar sidebar content" 1fr / auto auto 1fr
153159
`,
154160
maxHeight: `calc(100vh - ${navHeight + bannerHeight}px)`,
155161
marginBottom: `-${dashboardContentBottomPadding}px`,
@@ -175,6 +181,34 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({
175181
canUpdateWorkspace={canUpdateWorkspace}
176182
/>
177183

184+
<div
185+
css={{
186+
gridArea: "leftbar",
187+
height: "100%",
188+
overflowY: "auto",
189+
borderRight: `1px solid ${theme.palette.divider}`,
190+
}}
191+
>
192+
<SidebarIconButton
193+
isActive={searchParams.get("sidebar") === "history"}
194+
onClick={() => {
195+
const sidebarOption = searchParams.get("sidebar");
196+
if (sidebarOption === "history") {
197+
searchParams.delete("sidebar");
198+
} else {
199+
searchParams.set("sidebar", "history");
200+
}
201+
setSearchParams(searchParams);
202+
}}
203+
>
204+
<HistoryOutlined />
205+
</SidebarIconButton>
206+
</div>
207+
208+
{searchParams.get("sidebar") === "history" && (
209+
<HistorySidebar workspace={workspace} />
210+
)}
211+
178212
<div css={styles.content}>
179213
<div css={styles.dotBackground}>
180214
<Stack direction="column" css={styles.firstColumnSpacer} spacing={4}>
@@ -331,8 +365,6 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({
331365
</Stack>
332366
</div>
333367
</div>
334-
335-
<HistorySidebar workspace={workspace} />
336368
</div>
337369
);
338370
};

0 commit comments

Comments
 (0)