Skip to content

Commit 78b0639

Browse files
fix(site): fix metadata value changing width all the time (#8780)
1 parent ea2ae10 commit 78b0639

File tree

1 file changed

+32
-7
lines changed

1 file changed

+32
-7
lines changed

site/src/components/Resources/AgentMetadata.tsx

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,19 @@ import { watchAgentMetadata } from "api/api"
33
import { WorkspaceAgent, WorkspaceAgentMetadata } from "api/typesGenerated"
44
import { Stack } from "components/Stack/Stack"
55
import dayjs from "dayjs"
6-
import { createContext, FC, useContext, useEffect, useState } from "react"
6+
import {
7+
createContext,
8+
FC,
9+
useContext,
10+
useEffect,
11+
useRef,
12+
useState,
13+
} from "react"
714
import Skeleton from "@mui/material/Skeleton"
815
import { MONOSPACE_FONT_FAMILY } from "theme/constants"
916
import { combineClasses } from "utils/combineClasses"
1017
import Tooltip from "@mui/material/Tooltip"
18+
import Box, { BoxProps } from "@mui/material/Box"
1119

1220
type ItemStatus = "stale" | "valid" | "loading"
1321

@@ -55,35 +63,34 @@ const MetadataItem: FC<{ item: WorkspaceAgentMetadata }> = ({ item }) => {
5563
/>
5664
) : status === "stale" ? (
5765
<Tooltip title="This data is stale and no longer up to date">
58-
<div
66+
<StaticWidth
5967
className={combineClasses([
6068
styles.metadataValue,
6169
styles.metadataStale,
6270
])}
6371
>
6472
{item.result.value}
65-
</div>
73+
</StaticWidth>
6674
</Tooltip>
6775
) : (
68-
<div
76+
<StaticWidth
6977
className={combineClasses([
7078
styles.metadataValue,
71-
7279
item.result.error.length === 0
7380
? styles.metadataValueSuccess
7481
: styles.metadataValueError,
7582
])}
7683
>
7784
{item.result.value}
78-
</div>
85+
</StaticWidth>
7986
)
8087

8188
return (
8289
<div className={styles.metadata}>
8390
<div className={styles.metadataLabel}>
8491
{item.description.display_name}
8592
</div>
86-
<div>{value}</div>
93+
<Box>{value}</Box>
8794
</div>
8895
)
8996
}
@@ -190,6 +197,24 @@ export const AgentMetadataSkeleton: FC = () => {
190197
)
191198
}
192199

200+
const StaticWidth = (props: BoxProps) => {
201+
const ref = useRef<HTMLDivElement>(null)
202+
203+
useEffect(() => {
204+
if (!ref.current) {
205+
return
206+
}
207+
208+
const currentWidth = ref.current.getBoundingClientRect().width
209+
ref.current.style.width = "auto"
210+
const autoWidth = ref.current.getBoundingClientRect().width
211+
ref.current.style.width =
212+
autoWidth > currentWidth ? `${autoWidth}px` : `${currentWidth}px`
213+
}, [props.children])
214+
215+
return <Box {...props} ref={ref} />
216+
}
217+
193218
// These are more or less copied from
194219
// site/src/components/Resources/ResourceCard.tsx
195220
const useStyles = makeStyles((theme) => ({

0 commit comments

Comments
 (0)