Skip to content

Commit d2fac85

Browse files
refactor: Align values when there are more than one row in agent preview (#4795)
1 parent 10df2fd commit d2fac85

File tree

4 files changed

+44
-9
lines changed

4 files changed

+44
-9
lines changed

site/src/components/AppLink/AppPreviewLink.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ const useStyles = makeStyles((theme) => ({
3535
background: theme.palette.background.paper,
3636
flexShrink: 0,
3737
width: "fit-content",
38+
fontSize: 12,
3839

3940
"& img, & svg": {
40-
width: 14,
41+
width: 13,
4142
},
4243
},
4344
}))

site/src/components/Resources/AgentRowPreview.tsx

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,20 @@ import { combineClasses } from "util/combineClasses"
66
import { WorkspaceAgent } from "../../api/typesGenerated"
77
import { Stack } from "../Stack/Stack"
88

9-
export interface AgentRowPreviewProps {
9+
interface AgentRowPreviewStyles {
10+
// Helpful when there are more than one row so the values are aligned
11+
// When it is only one row, it is better to have than "flex" and not hard aligned
12+
alignValues?: boolean
13+
}
14+
export interface AgentRowPreviewProps extends AgentRowPreviewStyles {
1015
agent: WorkspaceAgent
1116
}
1217

13-
export const AgentRowPreview: FC<AgentRowPreviewProps> = ({ agent }) => {
14-
const styles = useStyles()
18+
export const AgentRowPreview: FC<AgentRowPreviewProps> = ({
19+
agent,
20+
alignValues,
21+
}) => {
22+
const styles = useStyles({ alignValues })
1523
const { t } = useTranslation("agent")
1624

1725
return (
@@ -36,7 +44,11 @@ export const AgentRowPreview: FC<AgentRowPreviewProps> = ({ agent }) => {
3644
direction="row"
3745
alignItems="baseline"
3846
spacing={1}
39-
className={combineClasses([styles.noShrink, styles.agentDataItem])}
47+
className={combineClasses([
48+
styles.noShrink,
49+
styles.agentDataItem,
50+
styles.agentDataName,
51+
])}
4052
>
4153
<span>{t("labels.agent").toString()}:</span>
4254
<span className={styles.agentDataValue}>{agent.name}</span>
@@ -46,7 +58,11 @@ export const AgentRowPreview: FC<AgentRowPreviewProps> = ({ agent }) => {
4658
direction="row"
4759
alignItems="baseline"
4860
spacing={1}
49-
className={combineClasses([styles.noShrink, styles.agentDataItem])}
61+
className={combineClasses([
62+
styles.noShrink,
63+
styles.agentDataItem,
64+
styles.agentDataOS,
65+
])}
5066
>
5167
<span>{t("labels.os").toString()}:</span>
5268
<span
@@ -142,6 +158,20 @@ const useStyles = makeStyles((theme) => ({
142158
},
143159
},
144160

161+
agentDataName: {
162+
[theme.breakpoints.up("sm")]: {
163+
minWidth: ({ alignValues }: AgentRowPreviewStyles) =>
164+
alignValues ? 240 : undefined,
165+
},
166+
},
167+
168+
agentDataOS: {
169+
[theme.breakpoints.up("sm")]: {
170+
minWidth: ({ alignValues }: AgentRowPreviewStyles) =>
171+
alignValues ? 100 : undefined,
172+
},
173+
},
174+
145175
agentDataValue: {
146176
color: theme.palette.text.primary,
147177
},

site/src/components/Resources/Resources.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const countAgents = (resource: WorkspaceResource) => {
1515

1616
interface ResourcesProps {
1717
resources: WorkspaceResource[]
18-
agentRow: (agent: WorkspaceAgent) => JSX.Element
18+
agentRow: (agent: WorkspaceAgent, numberOfAgents: number) => JSX.Element
1919
}
2020

2121
export const Resources: FC<React.PropsWithChildren<ResourcesProps>> = ({
@@ -39,7 +39,7 @@ export const Resources: FC<React.PropsWithChildren<ResourcesProps>> = ({
3939
<ResourceCard
4040
key={resource.id}
4141
resource={resource}
42-
agentRow={agentRow}
42+
agentRow={(agent) => agentRow(agent, countAgents(resource))}
4343
/>
4444
))}
4545
{hasHideResources && (

site/src/components/TemplateResourcesTable/TemplateResourcesTable.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ export const TemplateResourcesTable: FC<
1313
return (
1414
<Resources
1515
resources={resources}
16-
agentRow={(agent) => <AgentRowPreview key={agent.id} agent={agent} />}
16+
agentRow={(agent, count) => (
17+
// Align values if there are more than one row
18+
// When it is only one row, it is better to have it "flex" and not hard aligned
19+
<AgentRowPreview key={agent.id} agent={agent} alignValues={count > 1} />
20+
)}
1721
/>
1822
)
1923
}

0 commit comments

Comments
 (0)