Skip to content

Commit 9c799d8

Browse files
refactor(PoolsGraph): migrate to ts, use ContentWithPopup (#406)
1 parent 5d51dc8 commit 9c799d8

File tree

13 files changed

+110
-200
lines changed

13 files changed

+110
-200
lines changed

src/components/PoolBar/PoolBar.js

Lines changed: 0 additions & 52 deletions
This file was deleted.

src/components/PoolBar/PoolBar.scss

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.pool-bar {
1+
.ydb-pool-bar {
22
position: relative;
33

44
width: 6px;
@@ -10,6 +10,11 @@
1010
border: 1px solid;
1111
border-radius: 1px;
1212

13+
&__popup-content {
14+
width: 170px;
15+
padding: 10px;
16+
}
17+
1318
&:last-child {
1419
margin-right: 0;
1520
}

src/components/PoolBar/PoolBar.tsx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import block from 'bem-cn-lite';
2+
3+
import type {TPoolStats} from '../../types/api/nodes';
4+
5+
import {ContentWithPopup} from '../ContentWithPopup/ContentWithPopup';
6+
import {PoolTooltipContent} from '../TooltipsContent';
7+
8+
import './PoolBar.scss';
9+
10+
const b = block('ydb-pool-bar');
11+
12+
const getBarType = (usage: number) => {
13+
if (usage >= 75) {
14+
return 'danger';
15+
} else if (usage >= 50 && usage < 75) {
16+
return 'warning';
17+
} else {
18+
return 'normal';
19+
}
20+
};
21+
22+
interface PoolBarProps {
23+
data?: TPoolStats;
24+
}
25+
26+
export const PoolBar = ({data = {}}: PoolBarProps) => {
27+
const {Usage: usage = 0} = data;
28+
const usagePercents = Math.min(usage * 100, 100);
29+
const type = getBarType(usagePercents);
30+
31+
return (
32+
<ContentWithPopup
33+
className={b({type})}
34+
content={<PoolTooltipContent data={data} className={b('popup-content')} />}
35+
>
36+
<div style={{height: `${usagePercents}%`}} className={b('value', {type})} />
37+
</ContentWithPopup>
38+
);
39+
};

src/components/PoolsGraph/PoolsGraph.js

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
.pools-graph {
1+
.ydb-pools-graph {
22
display: flex;
33
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import block from 'bem-cn-lite';
2+
3+
import type {TPoolStats} from '../../types/api/nodes';
4+
5+
import {PoolBar} from '../PoolBar/PoolBar';
6+
7+
import './PoolsGraph.scss';
8+
9+
const b = block('ydb-pools-graph');
10+
11+
interface PoolsGraphProps {
12+
pools?: TPoolStats[];
13+
}
14+
15+
export const PoolsGraph = ({pools = []}: PoolsGraphProps) => {
16+
return (
17+
<div className={b()}>
18+
{pools.map((item, index) => (
19+
<PoolBar key={index} data={item} />
20+
))}
21+
</div>
22+
);
23+
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import type {TPoolStats} from '../../../types/api/nodes';
2+
3+
import {InfoViewer, createInfoFormatter, formatObject} from '../../InfoViewer';
4+
5+
const formatPool = createInfoFormatter<TPoolStats>({
6+
values: {
7+
Usage: (value) => value && `${(Number(value) * 100).toFixed(2)} %`,
8+
},
9+
labels: {
10+
Name: 'Pool',
11+
},
12+
defaultValueFormatter: (value) => value && String(value),
13+
});
14+
15+
interface PoolTooltipContentProps {
16+
data?: TPoolStats;
17+
className?: string;
18+
}
19+
20+
export const PoolTooltipContent = ({data = {}, className}: PoolTooltipContentProps) => {
21+
const info = formatObject(formatPool, data);
22+
23+
return <InfoViewer className={className} info={info} dots={false} size={'s'} />;
24+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from './NodeEndpointsTooltipContent/NodeEndpointsTooltipContent';
22
export * from './TabletTooltipContent/TabletTooltipContent';
3+
export * from './PoolTooltipContent/PoolTooltipContent';

src/containers/Nodes/Nodes.tsx

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import {
3131
getComputeNodes,
3232
} from '../../store/reducers/nodes';
3333
import {changeFilter, ProblemFilterValues} from '../../store/reducers/settings/settings';
34-
import {hideTooltip, showTooltip} from '../../store/reducers/tooltip';
3534

3635
import {isDatabaseEntityType} from '../Tenant/utils/schema';
3736

@@ -129,18 +128,8 @@ export const Nodes = ({path, type, className, additionalNodesInfo = {}}: NodesPr
129128
);
130129
};
131130

132-
const onShowTooltip = (...args: Parameters<typeof showTooltip>) => {
133-
dispatch(showTooltip(...args));
134-
};
135-
136-
const onHideTooltip = () => {
137-
dispatch(hideTooltip());
138-
};
139-
140131
const renderTable = () => {
141132
const columns = getNodesColumns({
142-
showTooltip: onShowTooltip,
143-
hideTooltip: onHideTooltip,
144133
getNodeRef: additionalNodesInfo.getNodeRef,
145134
});
146135

src/containers/Nodes/getNodesColumns.tsx

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import DataTable, {Column} from '@gravity-ui/react-data-table';
22
import {Popover} from '@gravity-ui/uikit';
33

4-
import PoolsGraph from '../../components/PoolsGraph/PoolsGraph';
4+
import {PoolsGraph} from '../../components/PoolsGraph/PoolsGraph';
55
import ProgressViewer from '../../components/ProgressViewer/ProgressViewer';
66
import {TabletsStatistic} from '../../components/TabletsStatistic';
77
import {NodeHostWrapper} from '../../components/NodeHostWrapper/NodeHostWrapper';
@@ -10,21 +10,13 @@ import type {NodeAddress} from '../../utils/nodes';
1010
import {formatBytesToGigabyte} from '../../utils/index';
1111

1212
import type {INodesPreparedEntity} from '../../types/store/nodes';
13-
import {showTooltip as externalShowTooltip} from '../../store/reducers/tooltip';
1413

1514
interface GetNodesColumnsProps {
16-
showTooltip: (...args: Parameters<typeof externalShowTooltip>) => void;
17-
hideTooltip: VoidFunction;
1815
tabletsPath?: string;
1916
getNodeRef?: (node?: NodeAddress) => string;
2017
}
2118

22-
export function getNodesColumns({
23-
showTooltip,
24-
hideTooltip,
25-
tabletsPath,
26-
getNodeRef,
27-
}: GetNodesColumnsProps) {
19+
export function getNodesColumns({tabletsPath, getNodeRef}: GetNodesColumnsProps) {
2820
const columns: Column<INodesPreparedEntity>[] = [
2921
{
3022
name: 'NodeId',
@@ -96,16 +88,7 @@ export function getNodesColumns({
9688
}
9789
}, 0),
9890
defaultOrder: DataTable.DESCENDING,
99-
render: ({row}) =>
100-
row.PoolStats ? (
101-
<PoolsGraph
102-
onMouseEnter={showTooltip}
103-
onMouseLeave={hideTooltip}
104-
pools={row.PoolStats}
105-
/>
106-
) : (
107-
'—'
108-
),
91+
render: ({row}) => (row.PoolStats ? <PoolsGraph pools={row.PoolStats} /> : '—'),
10992
align: DataTable.LEFT,
11093
width: '120px',
11194
},

0 commit comments

Comments
 (0)