@@ -30,12 +30,12 @@ import { CopyButton } from '../shared/CopyButton';
30
30
import {
31
31
BackgroundColorProps ,
32
32
getBackgroundColor ,
33
+ getStatusBackgroundColor ,
33
34
} from '../shared/getBackgroundColor' ;
34
35
import { PinButton } from '../shared/PinButton' ;
35
36
import { SingleLineBox } from '../shared/SingleLineBox' ;
36
- import { getStatusBackgroundColor } from '../shared/StatusInfo' ;
37
37
import { ResourceItemProps } from '../types' ;
38
- import { WarningRightEdgeBadgeSvg } from './WarningSideBadgeSvg ' ;
38
+ import { WarningRightEdgeBadgeSvg } from './WarningRightEdgeBadgeSvg ' ;
39
39
40
40
// Since we do a lot of manual resizing and some absolute positioning, we have
41
41
// to put some layout constants in place here.
@@ -54,23 +54,26 @@ const ResTypeIconBox = styled(Box)`
54
54
` ;
55
55
56
56
export function ResourceCard ( {
57
- name,
58
- primaryIconName,
59
- SecondaryIcon,
60
57
onLabelClick,
61
- cardViewProps,
62
- ActionButton,
63
- labels,
64
58
pinningSupport,
65
59
pinned,
66
60
pinResource,
67
61
selectResource,
68
- requiresRequest,
69
62
selected,
70
- status,
71
63
onShowStatusInfo,
72
- viewingUnhealthyStatus,
73
- } : Omit < ResourceItemProps , 'listViewProps' | 'expandAllLabels' > ) {
64
+ showingStatusInfo,
65
+ viewItem,
66
+ } : Omit < ResourceItemProps , 'expandAllLabels' > ) {
67
+ const {
68
+ name,
69
+ primaryIconName,
70
+ SecondaryIcon,
71
+ cardViewProps,
72
+ ActionButton,
73
+ labels,
74
+ requiresRequest,
75
+ status,
76
+ } = viewItem ;
74
77
const { primaryDesc, secondaryDesc } = cardViewProps ;
75
78
76
79
const [ showMoreLabelsButton , setShowMoreLabelsButton ] = useState ( false ) ;
@@ -83,10 +86,20 @@ export function ResourceCard({
83
86
const labelsInnerContainer = useRef < HTMLDivElement > ( null ) ;
84
87
const collapseTimeout = useRef < ReturnType < typeof setTimeout > > ( null ) ;
85
88
89
+ // This saves the height of the card on initial render. It's the full
90
+ // height when all contents fill up the card.
91
+ // This was required for the WarningRightEdgeBadgeIcon to stay in place
92
+ // when we "showAllLabels". Showing all labels makes the inner container
93
+ // pop out, and the container (where the svg is held) shrunk in size
94
+ // resulting in the auto-sizing svg to lose its place.
95
+ const [ baseCardHeight , setBaseCardHeight ] = useState ( 0 ) ;
96
+
86
97
// This effect installs a resize observer whose purpose is to detect the size
87
98
// of the component that contains all the labels. If this component is taller
88
99
// than the height of a single label row, we show a "+x more" button.
89
100
useLayoutEffect ( ( ) => {
101
+ setBaseCardHeight ( innerContainer . current ?. getBoundingClientRect ( ) . height ) ;
102
+
90
103
if ( ! labelsInnerContainer . current ) return ;
91
104
92
105
// TODO(ravicious): Use useResizeObserver instead. Ensure that the callback passed to
@@ -169,7 +182,7 @@ export function ResourceCard({
169
182
< CardContainer
170
183
onMouseEnter = { ( ) => setHovered ( true ) }
171
184
onMouseLeave = { ( ) => setHovered ( false ) }
172
- viewingUnhealthyStatus = { viewingUnhealthyStatus }
185
+ showingStatusInfo = { showingStatusInfo }
173
186
>
174
187
< CardOuterContainer
175
188
showAllLabels = { showAllLabels }
@@ -186,9 +199,12 @@ export function ResourceCard({
186
199
pinned = { pinned }
187
200
requiresRequest = { requiresRequest }
188
201
selected = { selected }
189
- viewingUnhealthyStatus = { viewingUnhealthyStatus }
202
+ showingStatusInfo = { showingStatusInfo }
190
203
hasUnhealthyStatus = { hasUnhealthyStatus }
204
+ // we set extra padding to push contents to the right to make
205
+ // space for the WarningRightEdgeBadgeIcon.
191
206
{ ...( hasUnhealthyStatus && ! showAllLabels && { pr : '35px' } ) }
207
+ { ...( hasUnhealthyStatus && showAllLabels && { pr : '7px' } ) }
192
208
>
193
209
< HoverTooltip tipContent = { selected ? 'Deselect' : 'Select' } >
194
210
< CheckboxInput
@@ -257,7 +273,10 @@ export function ResourceCard({
257
273
) }
258
274
</ Flex >
259
275
< LabelsContainer showAll = { showAllLabels } >
260
- < LabelsInnerContainer ref = { labelsInnerContainer } >
276
+ < LabelsInnerContainer
277
+ ref = { labelsInnerContainer }
278
+ hasUnhealthyStatus = { hasUnhealthyStatus }
279
+ >
261
280
< MoreLabelsButton
262
281
style = { {
263
282
visibility :
@@ -293,23 +312,25 @@ export function ResourceCard({
293
312
) }
294
313
</ CardInnerContainer >
295
314
</ CardOuterContainer >
296
- { /* This is to let the StatusWarningEdgeIcon stay in place while inner
315
+ { /* This is to let the WarningRightEdgeBadgeIcon stay in place while inner
297
316
container expands vertically from rendering all labels. */ }
298
317
{ hasUnhealthyStatus && showAllLabels && (
299
- < WarningRightEdgeBadgeIcon onClick = { onShowStatusInfo } />
318
+ < Box height = { `${ baseCardHeight } px` } css = { { position : 'relative' } } >
319
+ < WarningRightEdgeBadgeIcon />
320
+ </ Box >
300
321
) }
301
322
</ CardContainer >
302
323
) ;
303
324
}
304
325
305
- const WarningRightEdgeBadgeIcon = ( { onClick } : { onClick ( ) : void } ) => {
326
+ const WarningRightEdgeBadgeIcon = ( { onClick } : { onClick ? ( ) : void } ) => {
306
327
return (
307
328
< Box
308
329
onClick = { onClick }
309
330
css = { `
310
331
position: absolute;
311
332
top: 0;
312
- right: 0px ;
333
+ right: 0 ;
313
334
cursor: pointer;
314
335
height: 100%;
315
336
` }
@@ -331,12 +352,15 @@ const WarningRightEdgeBadgeIcon = ({ onClick }: { onClick(): void }) => {
331
352
* outer container.
332
353
*/
333
354
const CardContainer = styled ( Box ) < {
334
- viewingUnhealthyStatus : boolean ;
355
+ showingStatusInfo : boolean ;
335
356
} > `
336
357
position: relative;
337
358
.resource-health-status-svg {
359
+ width: 100%;
360
+ height: 100%;
361
+
338
362
fill: ${ p =>
339
- p . viewingUnhealthyStatus
363
+ p . showingStatusInfo
340
364
? p . theme . colors . interactive . solid . alert . active
341
365
: p . theme . colors . interactive . solid . alert . default } ;
342
366
}
@@ -358,7 +382,7 @@ const CardOuterContainer = styled(Box)<{
358
382
css `
359
383
position : absolute;
360
384
left : 0 ;
361
- // The padding is required to show the StatusWarningEdgeIcon
385
+ // The padding is required to show the WarningRightEdgeBadgeIcon
362
386
right : ${ props . hasUnhealthyStatus ? '28px' : 0 } ;
363
387
z-index : 1 ;
364
388
` }
@@ -404,15 +428,15 @@ const CardInnerContainer = styled(Flex)<BackgroundColorProps>`
404
428
css `
405
429
border : 2px solid ${ p . theme . colors . interactive . solid . alert . default } ;
406
430
background-color : ${ getStatusBackgroundColor ( {
407
- viewingUnhealthyStatus : p . viewingUnhealthyStatus ,
431
+ showingStatusInfo : p . showingStatusInfo ,
408
432
theme : p . theme ,
409
433
action : '' ,
410
434
viewType : 'card' ,
411
435
} ) } ;
412
436
` }
413
437
414
438
${ p =>
415
- p . viewingUnhealthyStatus &&
439
+ p . showingStatusInfo &&
416
440
css `
417
441
border : 2px solid ${ p . theme . colors . interactive . solid . alert . active } ;
418
442
` }
@@ -426,7 +450,7 @@ const CardInnerContainer = styled(Flex)<BackgroundColorProps>`
426
450
css `
427
451
border-color : ${ p . theme . colors . interactive . solid . alert . hover } ;
428
452
background-color : ${ getStatusBackgroundColor ( {
429
- viewingUnhealthyStatus : p . viewingUnhealthyStatus ,
453
+ showingStatusInfo : p . showingStatusInfo ,
430
454
theme : p . theme ,
431
455
action : 'hover' ,
432
456
viewType : 'card' ,
@@ -459,12 +483,16 @@ const StyledLabel = styled(Label)`
459
483
* The inner labels container always adapts to the size of labels. Its height
460
484
* is measured by the resize observer.
461
485
*/
462
- const LabelsInnerContainer = styled ( Flex ) `
486
+ const LabelsInnerContainer = styled ( Flex ) < { hasUnhealthyStatus : boolean } > `
463
487
position: relative;
464
488
flex-wrap: wrap;
465
489
align-items: start;
466
490
gap: ${ props => props . theme . space [ 1 ] } px;
467
- padding-right: 60px;
491
+ // Padding is required to prevent the more label button to not collide
492
+ // with the rendered labels. Just a tiny bit more padding needed to
493
+ // accomodate contents getting pushed more to the right when a
494
+ // WarningRightEdgeBadgeIcon renders.
495
+ padding-right: ${ p => ( p . hasUnhealthyStatus ? '75px' : '74px' ) } ;
468
496
` ;
469
497
470
498
/**
0 commit comments