Skip to content

refactor: Align values when there are more than one row in agent preview #4795

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 2 commits into from
Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion site/src/components/AppLink/AppPreviewLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
}))
40 changes: 35 additions & 5 deletions site/src/components/Resources/AgentRowPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<AgentRowPreviewProps> = ({ agent }) => {
const styles = useStyles()
export const AgentRowPreview: FC<AgentRowPreviewProps> = ({
agent,
alignValues,
}) => {
const styles = useStyles({ alignValues })
const { t } = useTranslation("agent")

return (
Expand All @@ -36,7 +44,11 @@ export const AgentRowPreview: FC<AgentRowPreviewProps> = ({ agent }) => {
direction="row"
alignItems="baseline"
spacing={1}
className={combineClasses([styles.noShrink, styles.agentDataItem])}
className={combineClasses([
styles.noShrink,
styles.agentDataItem,
styles.agentDataName,
])}
>
<span>{t("labels.agent").toString()}:</span>
<span className={styles.agentDataValue}>{agent.name}</span>
Expand All @@ -46,7 +58,11 @@ export const AgentRowPreview: FC<AgentRowPreviewProps> = ({ agent }) => {
direction="row"
alignItems="baseline"
spacing={1}
className={combineClasses([styles.noShrink, styles.agentDataItem])}
className={combineClasses([
styles.noShrink,
styles.agentDataItem,
styles.agentDataOS,
])}
>
<span>{t("labels.os").toString()}:</span>
<span
Expand Down Expand Up @@ -142,6 +158,20 @@ const useStyles = makeStyles((theme) => ({
},
},

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,
},
Expand Down
4 changes: 2 additions & 2 deletions site/src/components/Resources/Resources.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<React.PropsWithChildren<ResourcesProps>> = ({
Expand All @@ -39,7 +39,7 @@ export const Resources: FC<React.PropsWithChildren<ResourcesProps>> = ({
<ResourceCard
key={resource.id}
resource={resource}
agentRow={agentRow}
agentRow={(agent) => agentRow(agent, countAgents(resource))}
/>
))}
{hasHideResources && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ export const TemplateResourcesTable: FC<
return (
<Resources
resources={resources}
agentRow={(agent) => <AgentRowPreview key={agent.id} agent={agent} />}
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
<AgentRowPreview key={agent.id} agent={agent} alignValues={count > 1} />
)}
/>
)
}