Skip to content

Commit 19db2bb

Browse files
committed
fix: informative popups
1 parent ec7832b commit 19db2bb

File tree

5 files changed

+79
-23
lines changed

5 files changed

+79
-23
lines changed

src/components/CellWithPopover/CellWithPopover.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,9 @@
1616
.g-popover__handler {
1717
display: inline;
1818
}
19+
20+
&_full-width {
21+
width: 100%;
22+
}
1923
}
2024
}

src/components/CellWithPopover/CellWithPopover.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const b = cn('ydb-cell-with-popover');
99

1010
interface CellWithPopoverProps extends PopoverProps {
1111
wrapperClassName?: string;
12+
fullWidth?: boolean;
1213
}
1314

1415
const DELAY_TIMEOUT = 100;
@@ -17,14 +18,15 @@ export function CellWithPopover({
1718
children,
1819
className,
1920
wrapperClassName,
21+
fullWidth,
2022
...props
2123
}: CellWithPopoverProps) {
2224
return (
23-
<div className={b(null, wrapperClassName)}>
25+
<div className={b({fullWidth}, wrapperClassName)}>
2426
<Popover
2527
delayClosing={DELAY_TIMEOUT}
2628
delayOpening={DELAY_TIMEOUT}
27-
className={b('popover', className)}
29+
className={b('popover', {'full-width': fullWidth}, className)}
2830
{...props}
2931
>
3032
{children}

src/components/TooltipsContent/PoolTooltipContent/PoolTooltipContent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type {TPoolStats} from '../../../types/api/nodes';
22
import {InfoViewer, createInfoFormatter, formatObject} from '../../InfoViewer';
33

4-
const formatPool = createInfoFormatter<TPoolStats>({
4+
export const formatPool = createInfoFormatter<TPoolStats>({
55
values: {
66
Usage: (value) => value && `${(Number(value) * 100).toFixed(2)} %`,
77
},

src/components/nodesColumns/columns.tsx

Lines changed: 67 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import DataTable from '@gravity-ui/react-data-table';
2+
import {DefinitionList} from '@gravity-ui/uikit';
23

34
import {getLoadSeverityForNode} from '../../store/reducers/nodes/utils';
45
import type {TPoolStats} from '../../types/api/nodes';
@@ -11,15 +12,18 @@ import {
1112
} from '../../utils/dataFormatters/dataFormatters';
1213
import {getSpaceUsageSeverity} from '../../utils/storage';
1314
import type {Column} from '../../utils/tableUtils/types';
15+
import {isNumeric} from '../../utils/utils';
1416
import {CellWithPopover} from '../CellWithPopover/CellWithPopover';
1517
import {NodeHostWrapper} from '../NodeHostWrapper/NodeHostWrapper';
1618
import type {NodeHostData} from '../NodeHostWrapper/NodeHostWrapper';
1719
import {PoolsGraph} from '../PoolsGraph/PoolsGraph';
1820
import {ProgressViewer} from '../ProgressViewer/ProgressViewer';
1921
import {TabletsStatistic} from '../TabletsStatistic';
22+
import {formatPool} from '../TooltipsContent';
2023
import {UsageLabel} from '../UsageLabel/UsageLabel';
2124

2225
import {NODES_COLUMNS_IDS, NODES_COLUMNS_TITLES} from './constants';
26+
import i18n from './i18n';
2327
import type {GetNodesColumnsParams} from './types';
2428

2529
export function getNodeIdColumn<T extends {NodeId?: string | number}>(): Column<T> {
@@ -114,24 +118,52 @@ export function getMemoryColumn<
114118
resizeMinWidth: 170,
115119
};
116120
}
121+
117122
export function getRAMColumn<T extends {MemoryUsed?: string; MemoryLimit?: string}>(): Column<T> {
118123
return {
119124
name: NODES_COLUMNS_IDS.RAM,
120125
header: NODES_COLUMNS_TITLES.RAM,
121126
sortAccessor: ({MemoryUsed = 0}) => Number(MemoryUsed),
122127
defaultOrder: DataTable.DESCENDING,
123-
render: ({row}) => (
124-
<ProgressViewer
125-
value={row.MemoryUsed}
126-
capacity={row.MemoryLimit}
127-
formatValues={(value, total) =>
128-
formatStorageValues(value, total, 'gb', undefined, true)
129-
}
130-
colorizeProgress
131-
vertical
132-
hideCapacity
133-
/>
134-
),
128+
render: ({row}) => {
129+
const [memoryUsed, memoryLimit] =
130+
isNumeric(row.MemoryUsed) && isNumeric(row.MemoryLimit)
131+
? formatStorageValues(
132+
Number(row.MemoryUsed),
133+
Number(row.MemoryLimit),
134+
'gb',
135+
undefined,
136+
true,
137+
)
138+
: [0, 0];
139+
return (
140+
<CellWithPopover
141+
placement={['top', 'auto']}
142+
fullWidth
143+
content={
144+
<DefinitionList responsive>
145+
<DefinitionList.Item name={i18n('field_memory-used')}>
146+
{memoryUsed}
147+
</DefinitionList.Item>
148+
<DefinitionList.Item name={i18n('field_memory-limit')}>
149+
{memoryLimit}
150+
</DefinitionList.Item>
151+
</DefinitionList>
152+
}
153+
>
154+
<ProgressViewer
155+
value={row.MemoryUsed}
156+
capacity={row.MemoryLimit}
157+
formatValues={(value, total) =>
158+
formatStorageValues(value, total, 'gb', undefined, true)
159+
}
160+
colorizeProgress
161+
vertical
162+
hideCapacity
163+
/>
164+
</CellWithPopover>
165+
);
166+
},
135167
align: DataTable.LEFT,
136168
width: 85,
137169
resizeMinWidth: 40,
@@ -183,13 +215,29 @@ export function getTotalCpuColumn<T extends {PoolStats?: TPoolStats[]}>(): Colum
183215
const totalPoolUsage = row.PoolStats.reduce((acc, pool) => acc + (pool.Usage || 0), 0);
184216

185217
return (
186-
<ProgressViewer
187-
value={totalPoolUsage}
188-
capacity={1}
189-
colorizeProgress
190-
percents
191-
vertical
192-
/>
218+
<CellWithPopover
219+
placement={['top', 'auto']}
220+
fullWidth
221+
content={
222+
<DefinitionList responsive>
223+
{row.PoolStats.map((pool) =>
224+
isNumeric(pool.Usage) ? (
225+
<DefinitionList.Item key={pool.Name} name={pool.Name}>
226+
{formatPool('Usage', pool.Usage).value}
227+
</DefinitionList.Item>
228+
) : null,
229+
)}
230+
</DefinitionList>
231+
}
232+
>
233+
<ProgressViewer
234+
value={totalPoolUsage}
235+
capacity={1}
236+
colorizeProgress
237+
percents
238+
vertical
239+
/>
240+
</CellWithPopover>
193241
);
194242
},
195243
align: DataTable.LEFT,

src/components/nodesColumns/i18n/en.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,7 @@
1717
"caches": "Caches",
1818
"sessions": "Sessions",
1919
"missing": "Missing",
20-
"pdisks": "PDisks"
20+
"pdisks": "PDisks",
21+
"field_memory-used": "Memory used",
22+
"field_memory-limit": "Memory limit"
2123
}

0 commit comments

Comments
 (0)