Skip to content

Commit 78838eb

Browse files
refactor(Tablet): separate TabletInfo
1 parent ef5c66b commit 78838eb

File tree

3 files changed

+84
-66
lines changed

3 files changed

+84
-66
lines changed

src/containers/Tablet/Tablet.js

Lines changed: 3 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,27 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33
import {connect} from 'react-redux';
4-
import {Link} from 'react-router-dom';
54
import cn from 'bem-cn-lite';
6-
import _ from 'lodash';
75

8-
import {calcUptime} from '../../utils';
96
import {backend} from '../../store';
107
import {getTablet, getTabletDescribe} from '../../store/reducers/tablet';
118
import '../../services/api';
129

13-
import InfoViewer from '../../components/InfoViewer/InfoViewer';
1410
import EntityStatus from '../../components/EntityStatus/EntityStatus';
1511
import {Tag} from '../../components/Tag';
1612
import {Icon} from '../../components/Icon';
1713
import {EmptyState} from '../../components/EmptyState';
1814
import {Link as ExternalLink, Button, Loader} from '@gravity-ui/uikit';
19-
import DataTable from '@gravity-ui/react-data-table';
2015
import {CriticalActionDialog} from '../../components/CriticalActionDialog';
2116
import routes, {createHref} from '../../routes';
2217
import {getDefaultNodePath} from '../Node/NodePages';
2318

2419
import {TabletTable} from './TabletTable';
20+
import {TabletInfo} from './TabletInfo';
2521

2622
import './Tablet.scss';
2723

28-
const b = cn('tablet-page');
24+
export const b = cn('tablet-page');
2925

3026
class Tablet extends React.Component {
3127
static propTypes = {
@@ -194,25 +190,13 @@ class Tablet extends React.Component {
194190
}
195191
};
196192

197-
hasUptime = () => {
198-
const {tablet} = this.props;
199-
200-
return tablet.State === 'Active';
201-
};
202-
203193
hasHiveId = () => {
204194
const {tablet} = this.props;
205195
const {HiveId} = tablet;
206196

207197
return HiveId && HiveId !== '0';
208198
};
209199

210-
getSchemeShard = () => {
211-
const {tablet} = this.props;
212-
213-
return _.get(tablet, 'TenantId.SchemeShard');
214-
};
215-
216200
isDisabledResume = () => {
217201
const {tablet} = this.props;
218202
const {disableTabletActions} = this.state;
@@ -244,53 +228,6 @@ class Tablet extends React.Component {
244228
renderTablet = () => {
245229
const {tablet, tenantPath} = this.props;
246230
const {TabletId: id} = tablet;
247-
const schemeShard = this.getSchemeShard();
248-
249-
const tabletInfo = [
250-
{label: 'Database', value: tenantPath},
251-
this.hasHiveId()
252-
? {
253-
label: 'HiveId',
254-
value: (
255-
<ExternalLink
256-
href={createHref(routes.tablet, {id: tablet.HiveId})}
257-
target="_blank"
258-
>
259-
{tablet.HiveId}
260-
</ExternalLink>
261-
),
262-
}
263-
: null,
264-
schemeShard
265-
? {
266-
label: 'SchemeShard',
267-
value: (
268-
<ExternalLink
269-
href={createHref(routes.tablet, {id: schemeShard})}
270-
target="_blank"
271-
>
272-
{schemeShard}
273-
</ExternalLink>
274-
),
275-
}
276-
: null,
277-
{label: 'Type', value: tablet.Type},
278-
{label: 'State', value: tablet.State},
279-
this.hasUptime() ? {label: 'Uptime', value: calcUptime(tablet.ChangeTime)} : null,
280-
{label: 'Generation', value: tablet.Generation},
281-
{
282-
label: 'Node',
283-
value: (
284-
<Link className={b('link')} to={getDefaultNodePath(String(tablet.NodeId))}>
285-
{tablet.NodeId}
286-
</Link>
287-
),
288-
},
289-
].filter(Boolean);
290-
291-
if (tablet.SlaveId || tablet.FollowerId) {
292-
tabletInfo.push({label: 'Follower', value: tablet.SlaveId || tablet.FollowerId});
293-
}
294231

295232
const externalLinks = [
296233
{
@@ -319,7 +256,7 @@ class Tablet extends React.Component {
319256
</a>
320257
{(tablet.Master || tablet.Leader) && <Tag text="Leader" type="blue" />}
321258
</div>
322-
<InfoViewer info={tabletInfo} />
259+
<TabletInfo tablet={tablet} tenantPath={tenantPath} />
323260
<div className={b('controls')}>
324261
<Button
325262
onClick={this.showKillDialog}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import {Link} from 'react-router-dom';
2+
3+
import {Link as UIKitLink} from '@gravity-ui/uikit';
4+
5+
import {ETabletState, TTabletStateInfo} from '../../../types/api/tablet';
6+
import {InfoViewer, InfoViewerItem} from '../../../components/InfoViewer';
7+
import routes, {createHref} from '../../../routes';
8+
import {calcUptime} from '../../../utils';
9+
import {getDefaultNodePath} from '../../Node/NodePages';
10+
11+
import {b} from '../Tablet';
12+
13+
interface TabletInfoProps {
14+
tablet: TTabletStateInfo;
15+
tenantPath: string;
16+
}
17+
18+
export const TabletInfo = ({tablet, tenantPath}: TabletInfoProps) => {
19+
const {
20+
ChangeTime,
21+
Generation,
22+
FollowerId,
23+
NodeId,
24+
HiveId,
25+
State,
26+
Type,
27+
TenantId: {SchemeShard} = {},
28+
} = tablet;
29+
30+
const hasHiveId = HiveId && HiveId !== '0';
31+
const hasUptime = State === ETabletState.Active;
32+
33+
const tabletInfo: InfoViewerItem[] = [{label: 'Database', value: tenantPath}];
34+
35+
if (hasHiveId) {
36+
tabletInfo.push({
37+
label: 'HiveId',
38+
value: (
39+
<UIKitLink href={createHref(routes.tablet, {id: HiveId})} target="_blank">
40+
{HiveId}
41+
</UIKitLink>
42+
),
43+
});
44+
}
45+
46+
if (SchemeShard) {
47+
tabletInfo.push({
48+
label: 'SchemeShard',
49+
value: (
50+
<UIKitLink href={createHref(routes.tablet, {id: SchemeShard})} target="_blank">
51+
{SchemeShard}
52+
</UIKitLink>
53+
),
54+
});
55+
}
56+
57+
tabletInfo.push({label: 'Type', value: Type}, {label: 'State', value: State});
58+
59+
if (hasUptime) {
60+
tabletInfo.push({label: 'Uptime', value: calcUptime(ChangeTime)});
61+
}
62+
63+
tabletInfo.push(
64+
{label: 'Generation', value: Generation},
65+
{
66+
label: 'Node',
67+
value: (
68+
<Link className={b('link')} to={getDefaultNodePath(String(NodeId))}>
69+
{NodeId}
70+
</Link>
71+
),
72+
},
73+
);
74+
75+
if (FollowerId) {
76+
tabletInfo.push({label: 'Follower', value: FollowerId});
77+
}
78+
79+
return <InfoViewer info={tabletInfo} />;
80+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './TabletInfo';

0 commit comments

Comments
 (0)