Skip to content

Commit c3d0979

Browse files
chore(Node): fix warnings (#586)
1 parent 805a339 commit c3d0979

File tree

2 files changed

+12
-24
lines changed

2 files changed

+12
-24
lines changed

src/containers/Node/Node.tsx

+8-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import * as React from 'react';
22
import {useLocation, useRouteMatch} from 'react-router';
33
import cn from 'bem-cn-lite';
44
import {useDispatch} from 'react-redux';
5-
import _ from 'lodash';
65

76
import {Tabs} from '@gravity-ui/uikit';
87
import {Link} from 'react-router-dom';
@@ -52,21 +51,22 @@ function Node(props: NodeProps) {
5251
const {tenantName: tenantNameFromQuery} = parseQuery(location);
5352

5453
const {activeTabVerified, nodeTabs} = React.useMemo(() => {
55-
const hasStorage = _.find(node?.Roles as any[], (el) => el === STORAGE_ROLE);
56-
let activeTabVerified = activeTab;
54+
const hasStorage = node?.Roles?.find((el) => el === STORAGE_ROLE);
55+
56+
let actualActiveTab = activeTab;
5757
if (!hasStorage && activeTab === STORAGE) {
58-
activeTabVerified = OVERVIEW;
58+
actualActiveTab = OVERVIEW;
5959
}
6060
const nodePages = hasStorage ? NODE_PAGES : NODE_PAGES.filter((el) => el.id !== STORAGE);
6161

62-
const nodeTabs = nodePages.map((page) => {
62+
const actualNodeTabs = nodePages.map((page) => {
6363
return {
6464
...page,
6565
title: page.name,
6666
};
6767
});
6868

69-
return {activeTabVerified, nodeTabs};
69+
return {activeTabVerified: actualActiveTab, nodeTabs: actualNodeTabs};
7070
}, [activeTab, node]);
7171

7272
React.useEffect(() => {
@@ -100,13 +100,13 @@ function Node(props: NodeProps) {
100100
size="l"
101101
items={nodeTabs}
102102
activeTab={activeTabVerified}
103-
wrapTo={({id}, node) => (
103+
wrapTo={({id}, tabNode) => (
104104
<Link
105105
to={createHref(routes.node, {id: nodeId, activeTab: id})}
106106
key={id}
107107
className={b('tab')}
108108
>
109-
{node}
109+
{tabNode}
110110
</Link>
111111
)}
112112
allowNotSelected={true}

src/containers/Node/NodeStructure/NodeStructure.tsx

+4-16
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {useEffect, useRef} from 'react';
22
import {useDispatch} from 'react-redux';
33
import url from 'url';
4-
import _ from 'lodash';
4+
import {isEmpty} from 'lodash/fp';
55

66
import cn from 'bem-cn-lite';
77

@@ -47,23 +47,11 @@ function NodeStructure({nodeId, className}: NodeStructureProps) {
4747
).query;
4848

4949
const scrollContainerRef = useRef<HTMLDivElement>(null);
50-
const scrollContainer = scrollContainerRef.current;
5150

5251
const isReady = useRef(false);
5352

5453
const scrolled = useRef(false);
5554

56-
useEffect(() => {
57-
return () => {
58-
if (scrollContainer) {
59-
scrollContainer.scrollTo({
60-
behavior: 'smooth',
61-
top: 0,
62-
});
63-
}
64-
};
65-
}, []);
66-
6755
useEffect(() => {
6856
dispatch(getNodeStructure(nodeId));
6957
autofetcher.start();
@@ -77,13 +65,13 @@ function NodeStructure({nodeId, className}: NodeStructureProps) {
7765
}, [nodeId, dispatch]);
7866

7967
useEffect(() => {
80-
if (!_.isEmpty(nodeStructure) && scrollContainer) {
68+
if (!isEmpty(nodeStructure) && scrollContainerRef.current) {
8169
isReady.current = true;
8270
}
8371
}, [nodeStructure]);
8472

8573
useEffect(() => {
86-
if (isReady.current && !scrolled.current && scrollContainer) {
74+
if (isReady.current && !scrolled.current && scrollContainerRef.current) {
8775
const element = document.getElementById(
8876
generateId({type: 'pdisk', id: pdiskIdFromUrl as string}),
8977
);
@@ -102,7 +90,7 @@ function NodeStructure({nodeId, className}: NodeStructureProps) {
10290
}
10391

10492
if (element) {
105-
scrollContainer.scrollTo({
93+
scrollContainerRef.current.scrollTo({
10694
behavior: 'smooth',
10795
// should subtract 20 to avoid sticking the element to tabs
10896
top: scrollToVdisk ? scrollToVdisk : element.offsetTop,

0 commit comments

Comments
 (0)