Skip to content

Commit ef5c66b

Browse files
refactor(Tablet): separate TabletTable
1 parent 8b82c78 commit ef5c66b

File tree

3 files changed

+63
-47
lines changed

3 files changed

+63
-47
lines changed

src/containers/Tablet/Tablet.js

Lines changed: 3 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -21,48 +21,12 @@ import {CriticalActionDialog} from '../../components/CriticalActionDialog';
2121
import routes, {createHref} from '../../routes';
2222
import {getDefaultNodePath} from '../Node/NodePages';
2323

24+
import {TabletTable} from './TabletTable';
25+
2426
import './Tablet.scss';
2527

2628
const b = cn('tablet-page');
2729

28-
const TABLE_SETTINGS = {
29-
displayIndices: false,
30-
};
31-
32-
const CLUSTERS_COLUMNS = [
33-
{
34-
name: 'generation',
35-
header: 'Generation',
36-
align: DataTable.RIGHT,
37-
},
38-
{
39-
name: 'nodeId',
40-
header: 'Node ID',
41-
align: DataTable.RIGHT,
42-
sortable: false,
43-
},
44-
{
45-
name: 'changeTime',
46-
header: 'Change time',
47-
align: DataTable.RIGHT,
48-
sortable: false,
49-
render: ({value}) => calcUptime(value),
50-
},
51-
{
52-
name: 'state',
53-
header: 'State',
54-
sortable: false,
55-
},
56-
{
57-
name: 'follower_id',
58-
header: 'Follower ID',
59-
sortable: false,
60-
render: ({row}) => {
61-
return row.leader ? 'leader' : row.followerId;
62-
},
63-
},
64-
];
65-
6630
class Tablet extends React.Component {
6731
static propTypes = {
6832
id: PropTypes.string,
@@ -388,15 +352,7 @@ class Tablet extends React.Component {
388352
</div>
389353
</div>
390354
<div className={b('rigth-pane')}>
391-
<DataTable
392-
data={this.props.history}
393-
columns={CLUSTERS_COLUMNS}
394-
settings={TABLE_SETTINGS}
395-
initialSortOrder={{
396-
columnId: 'generation',
397-
order: DataTable.DESCENDING,
398-
}}
399-
/>
355+
<TabletTable history={this.props.history} />
400356
</div>
401357
</div>
402358
{this.renderDialog()}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import DataTable, {Column} from '@gravity-ui/react-data-table';
2+
3+
import type {ITabletPreparedHistoryItem} from '../../../types/store/tablet';
4+
import {calcUptime} from '../../../utils';
5+
6+
const columns: Column<ITabletPreparedHistoryItem>[] = [
7+
{
8+
name: 'Generation',
9+
align: DataTable.RIGHT,
10+
render: ({row}) => row.generation,
11+
},
12+
{
13+
name: 'Node ID',
14+
align: DataTable.RIGHT,
15+
sortable: false,
16+
render: ({row}) => row.nodeId,
17+
},
18+
{
19+
name: 'Change time',
20+
align: DataTable.RIGHT,
21+
sortable: false,
22+
render: ({row}) => calcUptime(row.changeTime),
23+
},
24+
{
25+
name: 'State',
26+
sortable: false,
27+
render: ({row}) => row.state,
28+
},
29+
{
30+
name: 'Follower ID',
31+
sortable: false,
32+
render: ({row}) => {
33+
return row.leader ? 'leader' : row.followerId;
34+
},
35+
},
36+
];
37+
38+
const TABLE_SETTINGS = {
39+
displayIndices: false,
40+
};
41+
42+
interface TabletTableProps {
43+
history: ITabletPreparedHistoryItem[];
44+
}
45+
46+
export const TabletTable = ({history}: TabletTableProps) => {
47+
return (
48+
<DataTable
49+
theme="yandex-cloud"
50+
data={history}
51+
columns={columns}
52+
settings={TABLE_SETTINGS}
53+
initialSortOrder={{
54+
columnId: 'Generation',
55+
order: DataTable.DESCENDING,
56+
}}
57+
/>
58+
);
59+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './TabletTable';

0 commit comments

Comments
 (0)