Skip to content

Commit 87ecd4e

Browse files
committed
Address Crs
1 parent 7ac742b commit 87ecd4e

File tree

12 files changed

+129
-143
lines changed

12 files changed

+129
-143
lines changed

web/packages/shared/components/SlidingSidePanel/InfoGuide/InfoGuide.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ const InfoGuideHeader = ({
4848
title: customTitle,
4949
}: {
5050
onClose(): void;
51-
title?: string | JSX.Element;
51+
title?: React.ReactNode;
5252
}) => {
53-
let title = <Text bold>Page Info</Text>;
53+
let title: React.ReactNode = <Text bold>Page Info</Text>;
5454
if (customTitle) {
5555
if (typeof customTitle === 'string') {
5656
title = <Text bold>{customTitle}</Text>;

web/packages/shared/components/UnifiedResources/CardsView/CardsView.tsx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,18 @@ export function CardsView({
3939
return (
4040
<CardsContainer className="CardsContainer" gap={2}>
4141
{mappedResources.map(
42-
({ item, key, onShowStatusInfo, viewingUnhealthyStatus }) => (
42+
({ item, key, onShowStatusInfo, showingStatusInfo }) => (
4343
<ResourceCard
4444
key={key}
45-
name={item.name}
46-
ActionButton={item.ActionButton}
47-
primaryIconName={item.primaryIconName}
45+
viewItem={item}
4846
onLabelClick={onLabelClick}
49-
SecondaryIcon={item.SecondaryIcon}
50-
cardViewProps={item.cardViewProps}
51-
labels={item.labels}
5247
pinned={pinnedResources.includes(key)}
53-
requiresRequest={item.requiresRequest}
5448
pinningSupport={pinningSupport}
5549
selected={selectedResources.includes(key)}
5650
selectResource={() => onSelectResource(key)}
5751
pinResource={() => onPinResource(key)}
58-
status={item.status}
5952
onShowStatusInfo={onShowStatusInfo}
60-
viewingUnhealthyStatus={viewingUnhealthyStatus}
53+
showingStatusInfo={showingStatusInfo}
6154
/>
6255
)
6356
)}

web/packages/shared/components/UnifiedResources/CardsView/ResourceCard.story.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,9 @@ export const Cards: Story = {
134134
selectResource={() => {}}
135135
selected={false}
136136
pinningSupport={PinningSupport.Supported}
137-
name={res.name}
138-
primaryIconName={res.primaryIconName}
139-
SecondaryIcon={res.SecondaryIcon}
140-
cardViewProps={res.cardViewProps}
141-
labels={res.labels}
142-
ActionButton={res.ActionButton}
143137
onShowStatusInfo={() => null}
144-
viewingUnhealthyStatus={false}
145-
status={res.status}
138+
showingStatusInfo={false}
139+
viewItem={res}
146140
/>
147141
))}
148142
</Grid>

web/packages/shared/components/UnifiedResources/CardsView/ResourceCard.tsx

Lines changed: 55 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ import { CopyButton } from '../shared/CopyButton';
3030
import {
3131
BackgroundColorProps,
3232
getBackgroundColor,
33+
getStatusBackgroundColor,
3334
} from '../shared/getBackgroundColor';
3435
import { PinButton } from '../shared/PinButton';
3536
import { SingleLineBox } from '../shared/SingleLineBox';
36-
import { getStatusBackgroundColor } from '../shared/StatusInfo';
3737
import { ResourceItemProps } from '../types';
38-
import { WarningRightEdgeBadgeSvg } from './WarningSideBadgeSvg';
38+
import { WarningRightEdgeBadgeSvg } from './WarningRightEdgeBadgeSvg';
3939

4040
// Since we do a lot of manual resizing and some absolute positioning, we have
4141
// to put some layout constants in place here.
@@ -54,23 +54,26 @@ const ResTypeIconBox = styled(Box)`
5454
`;
5555

5656
export function ResourceCard({
57-
name,
58-
primaryIconName,
59-
SecondaryIcon,
6057
onLabelClick,
61-
cardViewProps,
62-
ActionButton,
63-
labels,
6458
pinningSupport,
6559
pinned,
6660
pinResource,
6761
selectResource,
68-
requiresRequest,
6962
selected,
70-
status,
7163
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;
7477
const { primaryDesc, secondaryDesc } = cardViewProps;
7578

7679
const [showMoreLabelsButton, setShowMoreLabelsButton] = useState(false);
@@ -83,10 +86,20 @@ export function ResourceCard({
8386
const labelsInnerContainer = useRef<HTMLDivElement>(null);
8487
const collapseTimeout = useRef<ReturnType<typeof setTimeout>>(null);
8588

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+
8697
// This effect installs a resize observer whose purpose is to detect the size
8798
// of the component that contains all the labels. If this component is taller
8899
// than the height of a single label row, we show a "+x more" button.
89100
useLayoutEffect(() => {
101+
setBaseCardHeight(innerContainer.current?.getBoundingClientRect().height);
102+
90103
if (!labelsInnerContainer.current) return;
91104

92105
// TODO(ravicious): Use useResizeObserver instead. Ensure that the callback passed to
@@ -169,7 +182,7 @@ export function ResourceCard({
169182
<CardContainer
170183
onMouseEnter={() => setHovered(true)}
171184
onMouseLeave={() => setHovered(false)}
172-
viewingUnhealthyStatus={viewingUnhealthyStatus}
185+
showingStatusInfo={showingStatusInfo}
173186
>
174187
<CardOuterContainer
175188
showAllLabels={showAllLabels}
@@ -186,9 +199,12 @@ export function ResourceCard({
186199
pinned={pinned}
187200
requiresRequest={requiresRequest}
188201
selected={selected}
189-
viewingUnhealthyStatus={viewingUnhealthyStatus}
202+
showingStatusInfo={showingStatusInfo}
190203
hasUnhealthyStatus={hasUnhealthyStatus}
204+
// we set extra padding to push contents to the right to make
205+
// space for the WarningRightEdgeBadgeIcon.
191206
{...(hasUnhealthyStatus && !showAllLabels && { pr: '35px' })}
207+
{...(hasUnhealthyStatus && showAllLabels && { pr: '7px' })}
192208
>
193209
<HoverTooltip tipContent={selected ? 'Deselect' : 'Select'}>
194210
<CheckboxInput
@@ -257,7 +273,10 @@ export function ResourceCard({
257273
)}
258274
</Flex>
259275
<LabelsContainer showAll={showAllLabels}>
260-
<LabelsInnerContainer ref={labelsInnerContainer}>
276+
<LabelsInnerContainer
277+
ref={labelsInnerContainer}
278+
hasUnhealthyStatus={hasUnhealthyStatus}
279+
>
261280
<MoreLabelsButton
262281
style={{
263282
visibility:
@@ -293,23 +312,25 @@ export function ResourceCard({
293312
)}
294313
</CardInnerContainer>
295314
</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
297316
container expands vertically from rendering all labels. */}
298317
{hasUnhealthyStatus && showAllLabels && (
299-
<WarningRightEdgeBadgeIcon onClick={onShowStatusInfo} />
318+
<Box height={`${baseCardHeight}px`} css={{ position: 'relative' }}>
319+
<WarningRightEdgeBadgeIcon />
320+
</Box>
300321
)}
301322
</CardContainer>
302323
);
303324
}
304325

305-
const WarningRightEdgeBadgeIcon = ({ onClick }: { onClick(): void }) => {
326+
const WarningRightEdgeBadgeIcon = ({ onClick }: { onClick?(): void }) => {
306327
return (
307328
<Box
308329
onClick={onClick}
309330
css={`
310331
position: absolute;
311332
top: 0;
312-
right: 0px;
333+
right: 0;
313334
cursor: pointer;
314335
height: 100%;
315336
`}
@@ -331,12 +352,15 @@ const WarningRightEdgeBadgeIcon = ({ onClick }: { onClick(): void }) => {
331352
* outer container.
332353
*/
333354
const CardContainer = styled(Box)<{
334-
viewingUnhealthyStatus: boolean;
355+
showingStatusInfo: boolean;
335356
}>`
336357
position: relative;
337358
.resource-health-status-svg {
359+
width: 100%;
360+
height: 100%;
361+
338362
fill: ${p =>
339-
p.viewingUnhealthyStatus
363+
p.showingStatusInfo
340364
? p.theme.colors.interactive.solid.alert.active
341365
: p.theme.colors.interactive.solid.alert.default};
342366
}
@@ -358,7 +382,7 @@ const CardOuterContainer = styled(Box)<{
358382
css`
359383
position: absolute;
360384
left: 0;
361-
// The padding is required to show the StatusWarningEdgeIcon
385+
// The padding is required to show the WarningRightEdgeBadgeIcon
362386
right: ${props.hasUnhealthyStatus ? '28px' : 0};
363387
z-index: 1;
364388
`}
@@ -404,15 +428,15 @@ const CardInnerContainer = styled(Flex)<BackgroundColorProps>`
404428
css`
405429
border: 2px solid ${p.theme.colors.interactive.solid.alert.default};
406430
background-color: ${getStatusBackgroundColor({
407-
viewingUnhealthyStatus: p.viewingUnhealthyStatus,
431+
showingStatusInfo: p.showingStatusInfo,
408432
theme: p.theme,
409433
action: '',
410434
viewType: 'card',
411435
})};
412436
`}
413437
414438
${p =>
415-
p.viewingUnhealthyStatus &&
439+
p.showingStatusInfo &&
416440
css`
417441
border: 2px solid ${p.theme.colors.interactive.solid.alert.active};
418442
`}
@@ -426,7 +450,7 @@ const CardInnerContainer = styled(Flex)<BackgroundColorProps>`
426450
css`
427451
border-color: ${p.theme.colors.interactive.solid.alert.hover};
428452
background-color: ${getStatusBackgroundColor({
429-
viewingUnhealthyStatus: p.viewingUnhealthyStatus,
453+
showingStatusInfo: p.showingStatusInfo,
430454
theme: p.theme,
431455
action: 'hover',
432456
viewType: 'card',
@@ -459,12 +483,16 @@ const StyledLabel = styled(Label)`
459483
* The inner labels container always adapts to the size of labels. Its height
460484
* is measured by the resize observer.
461485
*/
462-
const LabelsInnerContainer = styled(Flex)`
486+
const LabelsInnerContainer = styled(Flex)<{ hasUnhealthyStatus: boolean }>`
463487
position: relative;
464488
flex-wrap: wrap;
465489
align-items: start;
466490
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')};
468496
`;
469497

470498
/**

web/packages/shared/components/UnifiedResources/CardsView/WarningSideBadgeSvg.tsx renamed to web/packages/shared/components/UnifiedResources/CardsView/WarningRightEdgeBadgeSvg.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
1818

19+
/**
20+
* This svg is different from existing warning svg's in that it's specifically
21+
* tailored to fit the design of unified ResourceCard.tsx to the right edge
22+
* of the component.
23+
*/
1924
export function WarningRightEdgeBadgeSvg() {
2025
return (
2126
<svg
@@ -25,10 +30,6 @@ export function WarningRightEdgeBadgeSvg() {
2530
viewBox="0 0 32 102"
2631
fill="none"
2732
xmlns="http://www.w3.org/2000/svg"
28-
style={{
29-
width: '100%',
30-
height: '100%',
31-
}}
3233
preserveAspectRatio="none"
3334
>
3435
<path d="M24 0H0V2C3.31371 2 6 4.68629 6 8H32C32 3.58172 28.4183 0 24 0Z" />

web/packages/shared/components/UnifiedResources/ListView/ListView.tsx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,26 +38,19 @@ export function ListView({
3838
return (
3939
<Flex className="ListContainer">
4040
{mappedResources.map(
41-
({ item, key, onShowStatusInfo, viewingUnhealthyStatus }) => (
41+
({ item, key, onShowStatusInfo, showingStatusInfo }) => (
4242
<ResourceListItem
4343
key={key}
44-
name={item.name}
45-
ActionButton={item.ActionButton}
46-
primaryIconName={item.primaryIconName}
44+
viewItem={item}
4745
onLabelClick={onLabelClick}
48-
SecondaryIcon={item.SecondaryIcon}
49-
listViewProps={item.listViewProps}
50-
labels={item.labels}
5146
pinned={pinnedResources.includes(key)}
5247
pinningSupport={pinningSupport}
53-
requiresRequest={item.requiresRequest}
5448
selected={selectedResources.includes(key)}
5549
selectResource={() => onSelectResource(key)}
5650
pinResource={() => onPinResource(key)}
5751
expandAllLabels={expandAllLabels}
58-
status={item.status}
5952
onShowStatusInfo={onShowStatusInfo}
60-
viewingUnhealthyStatus={viewingUnhealthyStatus}
53+
showingStatusInfo={showingStatusInfo}
6154
/>
6255
)
6356
)}

web/packages/shared/components/UnifiedResources/ListView/ResourceListItem.story.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,10 @@ export const ListItems: Story = {
117117
selectResource={() => {}}
118118
selected={false}
119119
pinningSupport={PinningSupport.Supported}
120-
name={res.name}
121-
primaryIconName={res.primaryIconName}
122-
SecondaryIcon={res.SecondaryIcon}
123-
listViewProps={res.listViewProps}
124-
labels={res.labels}
125-
ActionButton={res.ActionButton}
126120
expandAllLabels={false}
127121
onShowStatusInfo={() => null}
128-
viewingUnhealthyStatus={false}
129-
status={res.status}
122+
showingStatusInfo={false}
123+
viewItem={res}
130124
/>
131125
))}
132126
</Flex>

0 commit comments

Comments
 (0)