@@ -10,8 +10,8 @@ import {
10
10
} from "components/DropdownArrows/DropdownArrows" ;
11
11
import IconButton from "@mui/material/IconButton" ;
12
12
import Tooltip from "@mui/material/Tooltip" ;
13
- import { Maybe } from "components/Conditionals/Maybe" ;
14
13
import { CopyableValue } from "components/CopyableValue/CopyableValue" ;
14
+ import { type Theme } from "@mui/material/styles" ;
15
15
16
16
export interface ResourceCardProps {
17
17
resource : WorkspaceResource ;
@@ -21,12 +21,20 @@ export interface ResourceCardProps {
21
21
export const ResourceCard : FC < ResourceCardProps > = ( { resource, agentRow } ) => {
22
22
const [ shouldDisplayAllMetadata , setShouldDisplayAllMetadata ] =
23
23
useState ( false ) ;
24
- const styles = useStyles ( ) ;
25
24
const metadataToDisplay = resource . metadata ?? [ ] ;
26
25
const visibleMetadata = shouldDisplayAllMetadata
27
26
? metadataToDisplay
28
27
: metadataToDisplay . slice ( 0 , 4 ) ;
29
28
29
+ // Add one to `metadataLength` if the resource has a cost, and hide one
30
+ // additional metadata item, because cost is displayed in the same grid.
31
+ let metadataLength = resource . metadata ?. length ?? 0 ;
32
+ if ( resource . daily_cost > 0 ) {
33
+ metadataLength += 1 ;
34
+ visibleMetadata . pop ( ) ;
35
+ }
36
+ const styles = useStyles ( { metadataLength } ) ;
37
+
30
38
return (
31
39
< div key = { resource . id } className = { `${ styles . resourceCard } resource-card` } >
32
40
< Stack
@@ -49,57 +57,52 @@ export const ResourceCard: FC<ResourceCardProps> = ({ resource, agentRow }) => {
49
57
</ div >
50
58
</ Stack >
51
59
52
- < Stack alignItems = "flex-start" direction = "row" spacing = { 5 } >
53
- < div className = { styles . metadataHeader } >
54
- { resource . daily_cost > 0 && (
55
- < div className = { styles . metadata } >
56
- < div className = { styles . metadataLabel } >
57
- < b > cost</ b >
58
- </ div >
60
+ < div className = { styles . metadataHeader } >
61
+ { resource . daily_cost > 0 && (
62
+ < div className = { styles . metadata } >
63
+ < div className = { styles . metadataLabel } >
64
+ < b > cost</ b >
65
+ </ div >
66
+ < div className = { styles . metadataValue } > { resource . daily_cost } </ div >
67
+ </ div >
68
+ ) }
69
+ { visibleMetadata . map ( ( meta ) => {
70
+ return (
71
+ < div className = { styles . metadata } key = { meta . key } >
72
+ < div className = { styles . metadataLabel } > { meta . key } </ div >
59
73
< div className = { styles . metadataValue } >
60
- { resource . daily_cost }
74
+ { meta . sensitive ? (
75
+ < SensitiveValue value = { meta . value } />
76
+ ) : (
77
+ < CopyableValue value = { meta . value } >
78
+ { meta . value }
79
+ </ CopyableValue >
80
+ ) }
61
81
</ div >
62
82
</ div >
63
- ) }
64
- { visibleMetadata . map ( ( meta ) => {
65
- return (
66
- < div className = { styles . metadata } key = { meta . key } >
67
- < div className = { styles . metadataLabel } > { meta . key } </ div >
68
- < div className = { styles . metadataValue } >
69
- { meta . sensitive ? (
70
- < SensitiveValue value = { meta . value } />
71
- ) : (
72
- < CopyableValue value = { meta . value } >
73
- { meta . value }
74
- </ CopyableValue >
75
- ) }
76
- </ div >
77
- </ div >
78
- ) ;
79
- } ) }
80
- </ div >
81
-
82
- < Maybe condition = { metadataToDisplay . length > 4 } >
83
- < Tooltip
84
- title = {
85
- shouldDisplayAllMetadata ? "Hide metadata" : "Show all metadata"
86
- }
83
+ ) ;
84
+ } ) }
85
+ </ div >
86
+ { metadataLength > 4 && (
87
+ < Tooltip
88
+ title = {
89
+ shouldDisplayAllMetadata ? "Hide metadata" : "Show all metadata"
90
+ }
91
+ >
92
+ < IconButton
93
+ onClick = { ( ) => {
94
+ setShouldDisplayAllMetadata ( ( value ) => ! value ) ;
95
+ } }
96
+ size = "large"
87
97
>
88
- < IconButton
89
- onClick = { ( ) => {
90
- setShouldDisplayAllMetadata ( ( value ) => ! value ) ;
91
- } }
92
- size = "large"
93
- >
94
- { shouldDisplayAllMetadata ? (
95
- < CloseDropdown margin = { false } />
96
- ) : (
97
- < OpenDropdown margin = { false } />
98
- ) }
99
- </ IconButton >
100
- </ Tooltip >
101
- </ Maybe >
102
- </ Stack >
98
+ { shouldDisplayAllMetadata ? (
99
+ < CloseDropdown margin = { false } />
100
+ ) : (
101
+ < OpenDropdown margin = { false } />
102
+ ) }
103
+ </ IconButton >
104
+ </ Tooltip >
105
+ ) }
103
106
</ Stack >
104
107
105
108
{ resource . agents && resource . agents . length > 0 && (
@@ -109,7 +112,7 @@ export const ResourceCard: FC<ResourceCardProps> = ({ resource, agentRow }) => {
109
112
) ;
110
113
} ;
111
114
112
- const useStyles = makeStyles ( ( theme ) => ( {
115
+ const useStyles = makeStyles < Theme , { metadataLength : number } > ( ( theme ) => ( {
113
116
resourceCard : {
114
117
background : theme . palette . background . paper ,
115
118
borderRadius : theme . shape . borderRadius ,
@@ -141,12 +144,15 @@ const useStyles = makeStyles((theme) => ({
141
144
} ,
142
145
} ,
143
146
144
- metadataHeader : {
147
+ metadataHeader : ( props ) => ( {
148
+ flexGrow : 2 ,
145
149
display : "grid" ,
146
- gridTemplateColumns : "repeat(4, minmax(0, 1fr))" ,
150
+ gridTemplateColumns : `repeat(${
151
+ props . metadataLength === 1 ? 1 : 4
152
+ } , minmax(0, 1fr))`,
147
153
gap : theme . spacing ( 5 ) ,
148
154
rowGap : theme . spacing ( 3 ) ,
149
- } ,
155
+ } ) ,
150
156
151
157
metadata : {
152
158
...theme . typography . body2 ,
0 commit comments