Skip to content

Commit 83e0594

Browse files
refactor(Tablet): migrate to ts
1 parent c7967ff commit 83e0594

File tree

9 files changed

+67
-72
lines changed

9 files changed

+67
-72
lines changed

src/components/ClusterInfo/ClusterInfo.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ import ProgressViewer from '../ProgressViewer/ProgressViewer';
1010
//@ts-ignore
1111
import InfoViewer from '../InfoViewer/InfoViewer';
1212
import {Tags} from '../Tags';
13-
//@ts-ignore
14-
import Tablet from '../Tablet/Tablet';
13+
import {Tablet} from '../Tablet';
1514

1615
//@ts-ignore
1716
import {hideTooltip, showTooltip} from '../../store/reducers/tooltip';

src/components/Tablet/Tablet.js

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

src/components/Tablet/Tablet.tsx

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import {useRef} from 'react';
2+
import cn from 'bem-cn-lite';
3+
4+
import type {TTabletStateInfo} from '../../types/api/tablet';
5+
import type {ShowTooltipFunction} from '../../types/store/tooltip';
6+
import {getTabletLabel} from '../../utils/constants';
7+
import routes, {createHref} from '../../routes';
8+
9+
import {InternalLink} from '../InternalLink';
10+
11+
import './Tablet.scss';
12+
13+
const b = cn('tablet');
14+
15+
interface TabletProps {
16+
tablet?: TTabletStateInfo;
17+
onMouseEnter?: (...args: Parameters<ShowTooltipFunction>) => void;
18+
onMouseLeave?: VoidFunction;
19+
}
20+
21+
export const Tablet = ({
22+
tablet = {},
23+
onMouseEnter = () => {},
24+
onMouseLeave = () => {},
25+
}: TabletProps) => {
26+
const ref = useRef(null);
27+
28+
const _onTabletMouseEnter = () => {
29+
onMouseEnter(ref.current, tablet, 'tablet');
30+
};
31+
32+
const _onTabletClick = () => {
33+
const {TabletId: id} = tablet;
34+
35+
if (id) {
36+
onMouseLeave();
37+
}
38+
};
39+
40+
const {TabletId: id} = tablet;
41+
const status = tablet.Overall?.toLowerCase();
42+
43+
return (
44+
<InternalLink
45+
onClick={_onTabletClick}
46+
to={id && createHref(routes.tablet, {id})}
47+
className={b('wrapper')}
48+
>
49+
<div
50+
ref={ref}
51+
className={b({status})}
52+
onMouseEnter={_onTabletMouseEnter}
53+
onMouseLeave={onMouseLeave}
54+
>
55+
<div className={b('type')}>{[getTabletLabel(tablet.Type)]}</div>
56+
</div>
57+
</InternalLink>
58+
);
59+
};

src/components/Tablet/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './Tablet';

src/containers/Tablets/Tablets.scss

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@
2727
max-width: 180px;
2828
}
2929

30-
&__tablet {
31-
margin-bottom: 2px;
32-
}
33-
3430
.tablet {
3531
display: inline-block;
3632

src/containers/Tablets/Tablets.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import ReactList from 'react-list';
55

66
import {Select} from '@gravity-ui/uikit';
77

8-
import Tablet from '../../components/Tablet/Tablet';
8+
import {Tablet} from '../../components/Tablet';
99
import TabletsOverall from '../../components/TabletsOverall/TabletsOverall';
1010
import {Loader} from '../../components/Loader';
1111

@@ -104,7 +104,6 @@ export const Tablets = ({path, nodeId, className}: TabletsProps) => {
104104
onMouseEnter={onShowTooltip}
105105
tablet={tabletsToRender[tabletIndex]}
106106
key={tabletIndex}
107-
className={b('tablet')}
108107
/>
109108
);
110109
};

src/containers/TabletsFilters/TabletsFilters.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import _ from 'lodash';
88
import {Loader, Select} from '@gravity-ui/uikit';
99
import ReactList from 'react-list';
1010

11-
import Tablet from '../../components/Tablet/Tablet';
11+
import {Tablet} from '../../components/Tablet';
1212
import {AccessDenied} from '../../components/Errors/403';
1313

1414
import {tabletColorToTabletState, tabletStates} from '../../utils/tablet';

src/containers/Tenant/Diagnostics/TenantOverview/TenantOverview.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {Loader} from '@gravity-ui/uikit';
77
import EntityStatus from '../../../../components/EntityStatus/EntityStatus';
88
import InfoViewer from '../../../../components/InfoViewer/InfoViewer';
99
import PoolUsage from '../../../../components/PoolUsage/PoolUsage';
10-
import Tablet from '../../../../components/Tablet/Tablet';
10+
import {Tablet} from '../../../../components/Tablet';
1111

1212
import {hideTooltip, showTooltip} from '../../../../store/reducers/tooltip';
1313
import {getTenantInfo} from '../../../../store/reducers/tenant';

src/types/store/tooltip.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ export interface ITooltipState {
1818
additionalData?: any;
1919
}
2020

21-
export type ITooltipAction = ReturnType<typeof hideTooltip> | ReturnType<typeof showTooltip>;
21+
export type ShowTooltipFunction = typeof showTooltip;
22+
23+
export type ITooltipAction = ReturnType<typeof hideTooltip> | ReturnType<ShowTooltipFunction>;
2224

2325
export interface ITooltipRootStateSlice {
2426
tooltip: ITooltipState;

0 commit comments

Comments
 (0)