import type { Interpolation, Theme } from "@emotion/react"; import IconButton from "@mui/material/IconButton"; import Tooltip from "@mui/material/Tooltip"; import type { WorkspaceAgent, WorkspaceResource } from "api/typesGenerated"; import { CopyableValue } from "components/CopyableValue/CopyableValue"; import { DropdownArrow } from "components/DropdownArrow/DropdownArrow"; import { MemoizedInlineMarkdown } from "components/Markdown/Markdown"; import { Stack } from "components/Stack/Stack"; import { Children, type FC, useState } from "react"; import { ResourceAvatar } from "./ResourceAvatar"; import { SensitiveValue } from "./SensitiveValue"; const styles = { resourceCard: (theme) => ({ border: `1px solid ${theme.palette.divider}`, background: theme.palette.background.default, "&:not(:last-child)": { borderBottom: 0, }, "&:first-child": { borderTopLeftRadius: 8, borderTopRightRadius: 8, }, "&:last-child": { borderBottomLeftRadius: 8, borderBottomRightRadius: 8, }, }), resourceCardProfile: { flexShrink: 0, width: "fit-content", minWidth: 220, }, resourceCardHeader: (theme) => ({ padding: "24px 32px", borderBottom: `1px solid ${theme.palette.divider}`, "&:last-child": { borderBottom: 0, }, [theme.breakpoints.down("md")]: { width: "100%", overflow: "scroll", }, }), metadata: () => ({ lineHeight: "1.5", fontSize: 14, }), metadataLabel: (theme) => ({ fontSize: 12, color: theme.palette.text.secondary, textOverflow: "ellipsis", overflow: "hidden", whiteSpace: "nowrap", }), metadataValue: () => ({ textOverflow: "ellipsis", overflow: "hidden", whiteSpace: "nowrap", }), } satisfies Record>; export interface ResourceCardProps { resource: WorkspaceResource; agentRow: (agent: WorkspaceAgent) => JSX.Element; } export const ResourceCard: FC = ({ resource, agentRow }) => { const [shouldDisplayAllMetadata, setShouldDisplayAllMetadata] = useState(false); const metadataToDisplay = resource.metadata ?? []; const visibleMetadata = shouldDisplayAllMetadata ? metadataToDisplay : metadataToDisplay.slice(0, resource.daily_cost > 0 ? 3 : 4); const mLength = resource.daily_cost > 0 ? (resource.metadata?.length ?? 0) + 1 : (resource.metadata?.length ?? 0); const gridWidth = mLength === 1 ? 1 : 4; return (
{resource.type}
{resource.name}
{resource.daily_cost > 0 && (
Daily cost
{resource.daily_cost}
)} {visibleMetadata.map((meta) => { return (
{meta.key}
{meta.sensitive ? ( ) : ( { const childrens = Children.toArray(children); if ( childrens.every( (child) => typeof child === "string", ) ) { return ( {children} ); } return <>{children}; }, }} > {meta.value} )}
); })}
{mLength > 4 && ( { setShouldDisplayAllMetadata((value) => !value); }} size="large" > )}
{resource.agents && resource.agents.length > 0 && (
{resource.agents.map(agentRow)}
)}
); };