-
Notifications
You must be signed in to change notification settings - Fork 902
feat(site): move resources into the sidebar #11456
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import { Interpolation, Theme } from "@emotion/react"; | ||
import Skeleton from "@mui/material/Skeleton"; | ||
import { useTheme } from "@mui/material/styles"; | ||
import { WorkspaceResource } from "api/typesGenerated"; | ||
import { | ||
Sidebar, | ||
SidebarCaption, | ||
SidebarItem, | ||
} from "components/FullPageLayout/Sidebar"; | ||
import { getResourceIconPath } from "utils/workspace"; | ||
|
||
type ResourcesSidebarProps = { | ||
failed: boolean; | ||
resources: WorkspaceResource[]; | ||
onChange: (resourceId: string) => void; | ||
selected: string; | ||
}; | ||
|
||
export const ResourcesSidebar = (props: ResourcesSidebarProps) => { | ||
const theme = useTheme(); | ||
const { failed, onChange, selected, resources } = props; | ||
|
||
return ( | ||
<Sidebar> | ||
<SidebarCaption>Resources</SidebarCaption> | ||
{failed && ( | ||
<p | ||
css={{ | ||
margin: 0, | ||
padding: "0 16px", | ||
fontSize: 13, | ||
color: theme.palette.text.secondary, | ||
lineHeight: "1.5", | ||
}} | ||
> | ||
Your workspace build failed, so the necessary resources couldn't | ||
be created. | ||
</p> | ||
)} | ||
{resources.length === 0 && | ||
!failed && | ||
Array.from({ length: 8 }, (_, i) => ( | ||
<SidebarItem key={i}> | ||
<ResourceSidebarItemSkeleton /> | ||
</SidebarItem> | ||
))} | ||
{resources.map((r) => ( | ||
<SidebarItem | ||
onClick={() => onChange(r.id)} | ||
isActive={r.id === selected} | ||
key={r.id} | ||
css={styles.root} | ||
> | ||
<div | ||
css={{ | ||
display: "flex", | ||
alignItems: "center", | ||
justifyContent: "center", | ||
lineHeight: 0, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you want a lineHeight of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think 1 🤔 but let me check. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahh in this case, it is an image wrapper so it is ok to use 0... I'm going to replace those wrappers - we have a few in the codebase - with the new @aslilac component |
||
width: 16, | ||
height: 16, | ||
padding: 2, | ||
}} | ||
> | ||
<img | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeap. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Empty alt has similar behavior to the presentation role.
|
||
css={{ width: "100%", height: "100%", objectFit: "contain" }} | ||
src={getResourceIconPath(r.type)} | ||
alt="" | ||
/> | ||
</div> | ||
<div | ||
css={{ display: "flex", flexDirection: "column", fontWeight: 500 }} | ||
> | ||
<span>{r.name}</span> | ||
<span css={{ fontSize: 12, color: theme.palette.text.secondary }}> | ||
{r.type} | ||
</span> | ||
</div> | ||
</SidebarItem> | ||
))} | ||
</Sidebar> | ||
); | ||
}; | ||
|
||
export const ResourceSidebarItemSkeleton = () => { | ||
return ( | ||
<div css={[styles.root, { pointerEvents: "none" }]}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is because it has the root style which applies a "hover" style. I just found it easier to set pointerEvents to none to remove that. Do you see better ways? |
||
<Skeleton variant="circular" width={16} height={16} /> | ||
<div> | ||
<Skeleton variant="text" width={94} height={16} /> | ||
<Skeleton | ||
variant="text" | ||
width={60} | ||
height={14} | ||
css={{ marginTop: 2 }} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
const styles = { | ||
root: { | ||
lineHeight: "1.5", | ||
display: "flex", | ||
alignItems: "center", | ||
gap: 12, | ||
}, | ||
} satisfies Record<string, Interpolation<Theme>>; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,16 +2,15 @@ import { type Interpolation, type Theme } from "@emotion/react"; | |
import Button from "@mui/material/Button"; | ||
import AlertTitle from "@mui/material/AlertTitle"; | ||
import { type FC, useEffect, useState } from "react"; | ||
import { useNavigate, useSearchParams } from "react-router-dom"; | ||
import { useNavigate } from "react-router-dom"; | ||
import dayjs from "dayjs"; | ||
import type * as TypesGen from "api/typesGenerated"; | ||
import { Alert, AlertDetail } from "components/Alert/Alert"; | ||
import { Resources } from "components/Resources/Resources"; | ||
import { Stack } from "components/Stack/Stack"; | ||
import { ErrorAlert } from "components/Alert/ErrorAlert"; | ||
import { DormantWorkspaceBanner } from "components/WorkspaceDeletion"; | ||
import { AgentRow } from "components/Resources/AgentRow"; | ||
import { useLocalStorage } from "hooks"; | ||
import { useLocalStorage, useTab } from "hooks"; | ||
import { | ||
ActiveTransition, | ||
WorkspaceBuildProgress, | ||
|
@@ -24,6 +23,9 @@ import { bannerHeight } from "components/Dashboard/DeploymentBanner/DeploymentBa | |
import HistoryOutlined from "@mui/icons-material/HistoryOutlined"; | ||
import { useTheme } from "@mui/material/styles"; | ||
import { SidebarIconButton } from "components/FullPageLayout/Sidebar"; | ||
import HubOutlined from "@mui/icons-material/HubOutlined"; | ||
import { ResourcesSidebar } from "./ResourcesSidebar"; | ||
import { ResourceCard } from "components/Resources/ResourceCard"; | ||
|
||
export type WorkspaceError = | ||
| "getBuildsError" | ||
|
@@ -45,7 +47,6 @@ export interface WorkspaceProps { | |
isUpdating: boolean; | ||
isRestarting: boolean; | ||
workspace: TypesGen.Workspace; | ||
resources?: TypesGen.WorkspaceResource[]; | ||
canUpdateWorkspace: boolean; | ||
updateMessage?: string; | ||
canChangeVersions: boolean; | ||
|
@@ -78,8 +79,6 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({ | |
workspace, | ||
isUpdating, | ||
isRestarting, | ||
resources, | ||
|
||
canUpdateWorkspace, | ||
updateMessage, | ||
canChangeVersions, | ||
|
@@ -99,8 +98,6 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({ | |
const { saveLocal, getLocal } = useLocalStorage(); | ||
const theme = useTheme(); | ||
|
||
const [searchParams, setSearchParams] = useSearchParams(); | ||
|
||
const [showAlertPendingInQueue, setShowAlertPendingInQueue] = useState(false); | ||
|
||
// 2023-11-15 - MES - This effect will be called every single render because | ||
|
@@ -148,6 +145,29 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({ | |
const transitionStats = | ||
template !== undefined ? ActiveTransition(template, workspace) : undefined; | ||
|
||
const sidebarOption = useTab("sidebar", ""); | ||
const setSidebarOption = (newOption: string) => { | ||
const { set, value } = sidebarOption; | ||
if (value === newOption) { | ||
set(""); | ||
} else { | ||
set(newOption); | ||
} | ||
}; | ||
|
||
const selectedResourceId = useTab("resources", ""); | ||
const resources = workspace.latest_build.resources.sort( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Accidental mutation here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if I got it 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, the I don't think the const resources = [...workspace.latest_build.resources].sort() |
||
(a, b) => countAgents(b) - countAgents(a), | ||
); | ||
const selectedResource = workspace.latest_build.resources.find( | ||
(r) => r.id === selectedResourceId.value, | ||
); | ||
useEffect(() => { | ||
if (resources.length > 0 && selectedResourceId.value === "") { | ||
selectedResourceId.set(resources[0].id); | ||
} | ||
}, [resources, selectedResourceId]); | ||
|
||
return ( | ||
<div | ||
css={{ | ||
|
@@ -187,25 +207,37 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({ | |
height: "100%", | ||
overflowY: "auto", | ||
borderRight: `1px solid ${theme.palette.divider}`, | ||
display: "flex", | ||
flexDirection: "column", | ||
}} | ||
> | ||
<SidebarIconButton | ||
isActive={searchParams.get("sidebar") === "history"} | ||
isActive={sidebarOption.value === "resources"} | ||
onClick={() => { | ||
const sidebarOption = searchParams.get("sidebar"); | ||
if (sidebarOption === "history") { | ||
searchParams.delete("sidebar"); | ||
} else { | ||
searchParams.set("sidebar", "history"); | ||
} | ||
setSearchParams(searchParams); | ||
setSidebarOption("resources"); | ||
}} | ||
> | ||
<HubOutlined /> | ||
</SidebarIconButton> | ||
<SidebarIconButton | ||
isActive={sidebarOption.value === "history"} | ||
onClick={() => { | ||
setSidebarOption("history"); | ||
}} | ||
> | ||
<HistoryOutlined /> | ||
</SidebarIconButton> | ||
</div> | ||
|
||
{searchParams.get("sidebar") === "history" && ( | ||
{sidebarOption.value === "resources" && ( | ||
<ResourcesSidebar | ||
failed={workspace.latest_build.status === "failed"} | ||
resources={resources} | ||
selected={selectedResourceId.value} | ||
onChange={selectedResourceId.set} | ||
/> | ||
)} | ||
{sidebarOption.value === "history" && ( | ||
<HistorySidebar workspace={workspace} /> | ||
)} | ||
|
||
|
@@ -342,9 +374,9 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({ | |
|
||
{buildLogs} | ||
|
||
{resources && resources.length > 0 && ( | ||
<Resources | ||
resources={resources} | ||
{selectedResource && ( | ||
<ResourceCard | ||
resource={selectedResource} | ||
agentRow={(agent) => ( | ||
<AgentRow | ||
key={agent.id} | ||
|
@@ -369,6 +401,10 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({ | |
); | ||
}; | ||
|
||
const countAgents = (resource: TypesGen.WorkspaceResource) => { | ||
return resource.agents ? resource.agents.length : 0; | ||
}; | ||
|
||
const styles = { | ||
content: { | ||
padding: 24, | ||
|
@@ -377,6 +413,7 @@ const styles = { | |
}, | ||
|
||
dotBackground: (theme) => ({ | ||
minHeight: "100%", | ||
padding: 24, | ||
"--d": "1px", | ||
background: ` | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this condition strictly for handling loading states?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.