@@ -3,11 +3,19 @@ import { watchAgentMetadata } from "api/api"
3
3
import { WorkspaceAgent , WorkspaceAgentMetadata } from "api/typesGenerated"
4
4
import { Stack } from "components/Stack/Stack"
5
5
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"
7
14
import Skeleton from "@mui/material/Skeleton"
8
15
import { MONOSPACE_FONT_FAMILY } from "theme/constants"
9
16
import { combineClasses } from "utils/combineClasses"
10
17
import Tooltip from "@mui/material/Tooltip"
18
+ import Box , { BoxProps } from "@mui/material/Box"
11
19
12
20
type ItemStatus = "stale" | "valid" | "loading"
13
21
@@ -55,35 +63,34 @@ const MetadataItem: FC<{ item: WorkspaceAgentMetadata }> = ({ item }) => {
55
63
/>
56
64
) : status === "stale" ? (
57
65
< Tooltip title = "This data is stale and no longer up to date" >
58
- < div
66
+ < StaticWidth
59
67
className = { combineClasses ( [
60
68
styles . metadataValue ,
61
69
styles . metadataStale ,
62
70
] ) }
63
71
>
64
72
{ item . result . value }
65
- </ div >
73
+ </ StaticWidth >
66
74
</ Tooltip >
67
75
) : (
68
- < div
76
+ < StaticWidth
69
77
className = { combineClasses ( [
70
78
styles . metadataValue ,
71
-
72
79
item . result . error . length === 0
73
80
? styles . metadataValueSuccess
74
81
: styles . metadataValueError ,
75
82
] ) }
76
83
>
77
84
{ item . result . value }
78
- </ div >
85
+ </ StaticWidth >
79
86
)
80
87
81
88
return (
82
89
< div className = { styles . metadata } >
83
90
< div className = { styles . metadataLabel } >
84
91
{ item . description . display_name }
85
92
</ div >
86
- < div > { value } </ div >
93
+ < Box > { value } </ Box >
87
94
</ div >
88
95
)
89
96
}
@@ -190,6 +197,24 @@ export const AgentMetadataSkeleton: FC = () => {
190
197
)
191
198
}
192
199
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
+
193
218
// These are more or less copied from
194
219
// site/src/components/Resources/ResourceCard.tsx
195
220
const useStyles = makeStyles ( ( theme ) => ( {
0 commit comments