Skip to content

refactor(site): Redesign the agent row #7226

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 8 commits into from
Apr 20, 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
Update agent row
  • Loading branch information
BrunoQuaresma committed Apr 20, 2023
commit 0d4561c20a0760a4e8ad0afc7acb418ba4076c8f
68 changes: 43 additions & 25 deletions site/src/components/Resources/AgentMetadata.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,21 @@ export interface AgentMetadataViewProps {
}

export const AgentMetadataView: FC<AgentMetadataViewProps> = ({ metadata }) => {
const styles = useStyles()
if (metadata.length === 0) {
return <></>
}
return (
<Stack alignItems="baseline" direction="row" spacing={6}>
{metadata.map((m) => {
if (m.description === undefined) {
throw new Error("Metadata item description is undefined")
}
return <MetadataItem key={m.description.key} item={m} />
})}
</Stack>
<div className={styles.root}>
<Stack alignItems="baseline" direction="row" spacing={6}>
{metadata.map((m) => {
if (m.description === undefined) {
throw new Error("Metadata item description is undefined")
}
return <MetadataItem key={m.description.key} item={m} />
})}
</Stack>
</div>
)
}

Expand All @@ -99,8 +102,8 @@ export const AgentMetadata: FC<{
const [metadata, setMetadata] = useState<
WorkspaceAgentMetadata[] | undefined
>(undefined)
const styles = useStyles()
const watchAgentMetadata = useContext(WatchAgentMetadataContext)
const styles = useStyles()

useEffect(() => {
if (storybookMetadata !== undefined) {
Expand Down Expand Up @@ -139,31 +142,46 @@ export const AgentMetadata: FC<{

if (metadata === undefined) {
return (
<Stack alignItems="baseline" direction="row" spacing={6}>
<div className={styles.metadata}>
<Skeleton width={40} height={12} variant="text" />
<Skeleton width={65} height={14} variant="text" />
</div>

<div className={styles.metadata}>
<Skeleton width={40} height={12} variant="text" />
<Skeleton width={65} height={14} variant="text" />
</div>

<div className={styles.metadata}>
<Skeleton width={40} height={12} variant="text" />
<Skeleton width={65} height={14} variant="text" />
</div>
</Stack>
<div className={styles.root}>
<AgentMetadataSkeleton />
</div>
)
}

return <AgentMetadataView metadata={metadata} />
}

export const AgentMetadataSkeleton: FC = () => {
const styles = useStyles()

return (
<Stack alignItems="baseline" direction="row" spacing={6}>
<div className={styles.metadata}>
<Skeleton width={40} height={12} variant="text" />
<Skeleton width={65} height={14} variant="text" />
</div>

<div className={styles.metadata}>
<Skeleton width={40} height={12} variant="text" />
<Skeleton width={65} height={14} variant="text" />
</div>

<div className={styles.metadata}>
<Skeleton width={40} height={12} variant="text" />
<Skeleton width={65} height={14} variant="text" />
</div>
</Stack>
)
}

// These are more or less copied from
// site/src/components/Resources/ResourceCard.tsx
const useStyles = makeStyles((theme) => ({
root: {
padding: theme.spacing(2.5, 4),
borderTop: `1px solid ${theme.palette.divider}`,
background: theme.palette.background.paper,
},
metadata: {
fontSize: 12,
lineHeight: "normal",
Expand Down
78 changes: 52 additions & 26 deletions site/src/components/Resources/AgentRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
useRef,
useState,
} from "react"
import { useTranslation } from "react-i18next"
import { Prism as SyntaxHighlighter } from "react-syntax-highlighter"
import { darcula } from "react-syntax-highlighter/dist/cjs/styles/prism"
import AutoSizer from "react-virtualized-auto-sizer"
Expand All @@ -41,8 +40,8 @@ import { Stack } from "../Stack/Stack"
import { TerminalLink } from "../TerminalLink/TerminalLink"
import { AgentLatency } from "./AgentLatency"
import { AgentMetadata } from "./AgentMetadata"
import { AgentStatus } from "./AgentStatus"
import { AgentVersion } from "./AgentVersion"
import { AgentStatus } from "./AgentStatus"

export interface AgentRowProps {
agent: WorkspaceAgent
Expand Down Expand Up @@ -72,7 +71,6 @@ export const AgentRow: FC<AgentRowProps> = ({
sshPrefix,
}) => {
const styles = useStyles()
const { t } = useTranslation("agent")
const [logsMachine, sendLogsEvent] = useMachine(workspaceAgentLogsMachine, {
context: { agentID: agent.id },
services: process.env.STORYBOOK
Expand All @@ -89,7 +87,11 @@ export const AgentRow: FC<AgentRowProps> = ({
const theme = useTheme()
const startupScriptAnchorRef = useRef<HTMLButtonElement>(null)
const [startupScriptOpen, setStartupScriptOpen] = useState(false)

const hasAppsToDisplay = !hideVSCodeDesktopButton || agent.apps.length > 0
const shouldDisplayApps =
showApps &&
((agent.status === "connected" && hasAppsToDisplay) ||
agent.status === "connecting")
const hasStartupFeatures =
Boolean(agent.startup_logs_length) ||
Boolean(logsMachine.context.startupLogs?.length)
Expand Down Expand Up @@ -173,6 +175,7 @@ export const AgentRow: FC<AgentRowProps> = ({
className={combineClasses([
styles.agentRow,
styles[`agentRow-${agent.status}`],
styles[`agentRow-lifecycle-${agent.lifecycle_state}`],
])}
>
<Stack
Expand All @@ -183,18 +186,14 @@ export const AgentRow: FC<AgentRowProps> = ({
>
<div className={styles.agentNameAndStatus}>
<Stack alignItems="center" direction="row" spacing={3}>
<AgentStatus agent={agent} />
<div className={styles.agentName}>{agent.name}</div>
<Stack
direction="row"
spacing={2}
alignItems="baseline"
className={styles.agentDescription}
>
{agent.status === "timeout" && (
<div className={styles.agentErrorMessage}>
{t("unableToConnect")}
</div>
)}
{agent.status === "connected" && (
<>
<span className={styles.agentOS}>
Expand Down Expand Up @@ -262,14 +261,9 @@ export const AgentRow: FC<AgentRowProps> = ({
)}
</Stack>

<div className={styles.agentMetadata}>
<AgentMetadata
storybookMetadata={storybookAgentMetadata}
agent={agent}
/>
</div>
<AgentMetadata storybookMetadata={storybookAgentMetadata} agent={agent} />

{showApps && (
{shouldDisplayApps && (
<div className={styles.apps}>
{agent.status === "connected" && (
<>
Expand Down Expand Up @@ -419,22 +413,60 @@ const useStyles = makeStyles((theme) => ({
backgroundColor: theme.palette.background.paperLight,
fontSize: 16,
borderLeft: `2px solid ${theme.palette.text.secondary}`,

"&:not(:first-child)": {
borderTop: `2px solid ${theme.palette.divider}`,
},
},

"agentRow-connected": {
borderColor: theme.palette.success.light,
borderLeftColor: theme.palette.success.light,
},

"agentRow-disconnected": {
borderColor: theme.palette.text.secondary,
borderLeftColor: theme.palette.text.secondary,
},

"agentRow-connecting": {
borderColor: theme.palette.info.light,
borderLeftColor: theme.palette.info.light,
},

"agentRow-timeout": {
borderColor: theme.palette.warning.light,
borderLeftColor: theme.palette.warning.light,
},

"agentRow-lifecycle-created": {},

"agentRow-lifecycle-starting": {
borderLeftColor: theme.palette.info.light,
},

"agentRow-lifecycle-ready": {
borderLeftColor: theme.palette.success.light,
},

"agentRow-lifecycle-start_timeout": {
borderLeftColor: theme.palette.warning.light,
},

"agentRow-lifecycle-start_error": {
borderLeftColor: theme.palette.error.light,
},

"agentRow-lifecycle-shutting_down": {
borderLeftColor: theme.palette.info.light,
},

"agentRow-lifecycle-shutdown_timeout": {
borderLeftColor: theme.palette.warning.light,
},

"agentRow-lifecycle-shutdown_error": {
borderLeftColor: theme.palette.error.light,
},

"agentRow-lifecycle-off": {
borderLeftColor: theme.palette.text.secondary,
},

agentInfo: {
Expand Down Expand Up @@ -564,10 +596,4 @@ const useStyles = makeStyles((theme) => ({
agentOS: {
textTransform: "capitalize",
},

agentMetadata: {
padding: theme.spacing(2.5, 4),
borderTop: `1px solid ${theme.palette.divider}`,
background: theme.palette.background.paper,
},
}))
8 changes: 4 additions & 4 deletions site/src/components/Resources/AgentStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -422,15 +422,15 @@ const useStyles = makeStyles((theme) => ({

timeoutWarning: {
color: theme.palette.warning.light,
width: theme.spacing(2.5),
height: theme.spacing(2.5),
width: theme.spacing(2),
height: theme.spacing(2),
position: "relative",
},

errorWarning: {
color: theme.palette.error.main,
width: theme.spacing(2.5),
height: theme.spacing(2.5),
width: theme.spacing(2),
height: theme.spacing(2),
position: "relative",
},
}))
4 changes: 2 additions & 2 deletions site/src/components/Resources/AgentVersion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const AgentVersion: FC<{
const { outdated } = getDisplayVersionStatus(agent.version, serverVersion)

if (!outdated) {
return <span>{agent.version}</span>
return <span>Updated</span>
}

return (
Expand All @@ -29,7 +29,7 @@ export const AgentVersion: FC<{
onMouseLeave={() => setIsOpen(false)}
className={styles.trigger}
>
Agent Outdated
Outdated
</span>
<AgentOutdatedTooltip
id={id}
Expand Down