Skip to content

Commit 4b9897f

Browse files
committed
fix: dont render unneeded content
1 parent 2e47251 commit 4b9897f

File tree

5 files changed

+27
-25
lines changed

5 files changed

+27
-25
lines changed

src/components/HoverPopup/HoverPopup.tsx

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const DEBOUNCE_TIMEOUT = 100;
1414

1515
type HoverPopupProps = {
1616
children: React.ReactNode;
17-
popupContent: React.ReactNode;
17+
renderPopupContent: () => React.ReactNode;
1818
showPopup?: boolean;
1919
offset?: [number, number];
2020
anchorRef?: React.RefObject<HTMLElement>;
@@ -26,7 +26,7 @@ type HoverPopupProps = {
2626

2727
export const HoverPopup = ({
2828
children,
29-
popupContent,
29+
renderPopupContent,
3030
showPopup,
3131
offset,
3232
anchorRef,
@@ -98,22 +98,24 @@ export const HoverPopup = ({
9898
<span ref={anchor} onMouseEnter={onMouseEnter} onMouseLeave={onMouseLeave}>
9999
{children}
100100
</span>
101-
<Popup
102-
contentClassName={b(null, contentClassName)}
103-
anchorRef={anchorRef || anchor}
104-
open={open}
105-
onMouseEnter={onPopupMouseEnter}
106-
onMouseLeave={onPopupMouseLeave}
107-
onEscapeKeyDown={onPopupEscapeKeyDown}
108-
onBlur={onPopupBlur}
109-
placement={placement}
110-
hasArrow
111-
// bigger offset for easier switching to neighbour nodes
112-
// matches the default offset for popup with arrow out of a sense of beauty
113-
offset={offset || [0, 12]}
114-
>
115-
<div onContextMenu={onPopupContextMenu}>{popupContent}</div>
116-
</Popup>
101+
{open ? (
102+
<Popup
103+
contentClassName={b(null, contentClassName)}
104+
anchorRef={anchorRef || anchor}
105+
onMouseEnter={onPopupMouseEnter}
106+
onMouseLeave={onPopupMouseLeave}
107+
onEscapeKeyDown={onPopupEscapeKeyDown}
108+
onBlur={onPopupBlur}
109+
placement={placement}
110+
hasArrow
111+
open
112+
// bigger offset for easier switching to neighbour nodes
113+
// matches the default offset for popup with arrow out of a sense of beauty
114+
offset={offset || [0, 12]}
115+
>
116+
<div onContextMenu={onPopupContextMenu}>{renderPopupContent()}</div>
117+
</Popup>
118+
) : null}
117119
</React.Fragment>
118120
);
119121
};

src/components/MemoryViewer/MemoryViewer.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export function MemoryViewer({
100100

101101
return (
102102
<HoverPopup
103-
popupContent={
103+
renderPopupContent={() => (
104104
<DefinitionList responsive>
105105
{memorySegments.map(
106106
({label, value: segmentSize, capacity: segmentCapacity, key}) => (
@@ -132,7 +132,7 @@ export function MemoryViewer({
132132
),
133133
)}
134134
</DefinitionList>
135-
}
135+
)}
136136
>
137137
<div className={b({theme, status}, className)}>
138138
<div className={b('progress-container')}>

src/components/VDisk/VDisk.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export const VDisk = ({
4141
showPopup={showPopup}
4242
onShowPopup={onShowPopup}
4343
onHidePopup={onHidePopup}
44-
popupContent={<VDiskPopup data={data} />}
44+
renderPopupContent={() => <VDiskPopup data={data} />}
4545
offset={[0, 5]}
4646
delayClose={delayClose}
4747
delayOpen={delayOpen}

src/containers/PDiskPage/PDiskSpaceDistribution/PDiskSpaceDistribution.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ function Slot<T extends SlotItemType>({item, pDiskId, nodeId}: SlotProps<T>) {
8686

8787
return (
8888
<HoverPopup
89-
popupContent={<VDiskInfo data={item.SlotData} withTitle />}
89+
renderPopupContent={() => <VDiskInfo data={item.SlotData} withTitle />}
9090
contentClassName={b('vdisk-popup')}
9191
placement={['right', 'top']}
9292
>
@@ -111,7 +111,7 @@ function Slot<T extends SlotItemType>({item, pDiskId, nodeId}: SlotProps<T>) {
111111
if (isLogSlot(item)) {
112112
return (
113113
<HoverPopup
114-
popupContent={<LogInfo data={item.SlotData} />}
114+
renderPopupContent={() => <LogInfo data={item.SlotData} />}
115115
contentClassName={b('vdisk-popup')}
116116
placement={['right', 'top']}
117117
>
@@ -134,7 +134,7 @@ function Slot<T extends SlotItemType>({item, pDiskId, nodeId}: SlotProps<T>) {
134134
if (isEmptySlot(item)) {
135135
return (
136136
<HoverPopup
137-
popupContent={<EmptySlotInfo data={item.SlotData} />}
137+
renderPopupContent={() => <EmptySlotInfo data={item.SlotData} />}
138138
contentClassName={b('vdisk-popup')}
139139
placement={['right', 'top']}
140140
>

src/containers/Storage/PDisk/PDisk.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export const PDisk = ({
8787
anchorRef={anchorRef}
8888
onShowPopup={onShowPopup}
8989
onHidePopup={onHidePopup}
90-
popupContent={<PDiskPopup data={data} />}
90+
renderPopupContent={() => <PDiskPopup data={data} />}
9191
delayClose={200}
9292
>
9393
<InternalLink to={pDiskPath} className={b('content')}>

0 commit comments

Comments
 (0)