From 14c83ace491113918ff9fdcc7c2bc9576379efaa Mon Sep 17 00:00:00 2001 From: Bruno Quaresma Date: Fri, 28 Oct 2022 16:39:17 +0000 Subject: [PATCH] refactor: Align values when there are more than one row in agent preview --- .../src/components/AppLink/AppPreviewLink.tsx | 3 +- .../components/Resources/AgentRowPreview.tsx | 40 ++++++++++++++++--- site/src/components/Resources/Resources.tsx | 4 +- .../TemplateResourcesTable.tsx | 6 ++- 4 files changed, 44 insertions(+), 9 deletions(-) diff --git a/site/src/components/AppLink/AppPreviewLink.tsx b/site/src/components/AppLink/AppPreviewLink.tsx index 4d434f8963a9e..291529f126065 100644 --- a/site/src/components/AppLink/AppPreviewLink.tsx +++ b/site/src/components/AppLink/AppPreviewLink.tsx @@ -35,9 +35,10 @@ const useStyles = makeStyles((theme) => ({ background: theme.palette.background.paper, flexShrink: 0, width: "fit-content", + fontSize: 12, "& img, & svg": { - width: 14, + width: 13, }, }, })) diff --git a/site/src/components/Resources/AgentRowPreview.tsx b/site/src/components/Resources/AgentRowPreview.tsx index 53e6ce0a139b4..5fef65dedc9f3 100644 --- a/site/src/components/Resources/AgentRowPreview.tsx +++ b/site/src/components/Resources/AgentRowPreview.tsx @@ -6,12 +6,20 @@ import { combineClasses } from "util/combineClasses" import { WorkspaceAgent } from "../../api/typesGenerated" import { Stack } from "../Stack/Stack" -export interface AgentRowPreviewProps { +interface AgentRowPreviewStyles { + // Helpful when there are more than one row so the values are aligned + // When it is only one row, it is better to have than "flex" and not hard aligned + alignValues?: boolean +} +export interface AgentRowPreviewProps extends AgentRowPreviewStyles { agent: WorkspaceAgent } -export const AgentRowPreview: FC = ({ agent }) => { - const styles = useStyles() +export const AgentRowPreview: FC = ({ + agent, + alignValues, +}) => { + const styles = useStyles({ alignValues }) const { t } = useTranslation("agent") return ( @@ -36,7 +44,11 @@ export const AgentRowPreview: FC = ({ agent }) => { direction="row" alignItems="baseline" spacing={1} - className={combineClasses([styles.noShrink, styles.agentDataItem])} + className={combineClasses([ + styles.noShrink, + styles.agentDataItem, + styles.agentDataName, + ])} > {t("labels.agent").toString()}: {agent.name} @@ -46,7 +58,11 @@ export const AgentRowPreview: FC = ({ agent }) => { direction="row" alignItems="baseline" spacing={1} - className={combineClasses([styles.noShrink, styles.agentDataItem])} + className={combineClasses([ + styles.noShrink, + styles.agentDataItem, + styles.agentDataOS, + ])} > {t("labels.os").toString()}: ({ }, }, + agentDataName: { + [theme.breakpoints.up("sm")]: { + minWidth: ({ alignValues }: AgentRowPreviewStyles) => + alignValues ? 240 : undefined, + }, + }, + + agentDataOS: { + [theme.breakpoints.up("sm")]: { + minWidth: ({ alignValues }: AgentRowPreviewStyles) => + alignValues ? 100 : undefined, + }, + }, + agentDataValue: { color: theme.palette.text.primary, }, diff --git a/site/src/components/Resources/Resources.tsx b/site/src/components/Resources/Resources.tsx index b1337ca728f65..978099798fadd 100644 --- a/site/src/components/Resources/Resources.tsx +++ b/site/src/components/Resources/Resources.tsx @@ -15,7 +15,7 @@ const countAgents = (resource: WorkspaceResource) => { interface ResourcesProps { resources: WorkspaceResource[] - agentRow: (agent: WorkspaceAgent) => JSX.Element + agentRow: (agent: WorkspaceAgent, numberOfAgents: number) => JSX.Element } export const Resources: FC> = ({ @@ -39,7 +39,7 @@ export const Resources: FC> = ({ agentRow(agent, countAgents(resource))} /> ))} {hasHideResources && ( diff --git a/site/src/components/TemplateResourcesTable/TemplateResourcesTable.tsx b/site/src/components/TemplateResourcesTable/TemplateResourcesTable.tsx index 99b9120e5a090..c0efebebeb971 100644 --- a/site/src/components/TemplateResourcesTable/TemplateResourcesTable.tsx +++ b/site/src/components/TemplateResourcesTable/TemplateResourcesTable.tsx @@ -13,7 +13,11 @@ export const TemplateResourcesTable: FC< return ( } + agentRow={(agent, count) => ( + // Align values if there are more than one row + // When it is only one row, it is better to have it "flex" and not hard aligned + 1} /> + )} /> ) }