Skip to content

Commit

Permalink
chore(Node): fix warnings (#586)
Browse files Browse the repository at this point in the history
  • Loading branch information
artemmufazalov authored Nov 17, 2023
1 parent 805a339 commit c3d0979
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 24 deletions.
16 changes: 8 additions & 8 deletions src/containers/Node/Node.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as React from 'react';
import {useLocation, useRouteMatch} from 'react-router';
import cn from 'bem-cn-lite';
import {useDispatch} from 'react-redux';
import _ from 'lodash';

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

const {activeTabVerified, nodeTabs} = React.useMemo(() => {
const hasStorage = _.find(node?.Roles as any[], (el) => el === STORAGE_ROLE);
let activeTabVerified = activeTab;
const hasStorage = node?.Roles?.find((el) => el === STORAGE_ROLE);

let actualActiveTab = activeTab;
if (!hasStorage && activeTab === STORAGE) {
activeTabVerified = OVERVIEW;
actualActiveTab = OVERVIEW;
}
const nodePages = hasStorage ? NODE_PAGES : NODE_PAGES.filter((el) => el.id !== STORAGE);

const nodeTabs = nodePages.map((page) => {
const actualNodeTabs = nodePages.map((page) => {
return {
...page,
title: page.name,
};
});

return {activeTabVerified, nodeTabs};
return {activeTabVerified: actualActiveTab, nodeTabs: actualNodeTabs};
}, [activeTab, node]);

React.useEffect(() => {
Expand Down Expand Up @@ -100,13 +100,13 @@ function Node(props: NodeProps) {
size="l"
items={nodeTabs}
activeTab={activeTabVerified}
wrapTo={({id}, node) => (
wrapTo={({id}, tabNode) => (
<Link
to={createHref(routes.node, {id: nodeId, activeTab: id})}
key={id}
className={b('tab')}
>
{node}
{tabNode}
</Link>
)}
allowNotSelected={true}
Expand Down
20 changes: 4 additions & 16 deletions src/containers/Node/NodeStructure/NodeStructure.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {useEffect, useRef} from 'react';
import {useDispatch} from 'react-redux';
import url from 'url';
import _ from 'lodash';
import {isEmpty} from 'lodash/fp';

import cn from 'bem-cn-lite';

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

const scrollContainerRef = useRef<HTMLDivElement>(null);
const scrollContainer = scrollContainerRef.current;

const isReady = useRef(false);

const scrolled = useRef(false);

useEffect(() => {
return () => {
if (scrollContainer) {
scrollContainer.scrollTo({
behavior: 'smooth',
top: 0,
});
}
};
}, []);

useEffect(() => {
dispatch(getNodeStructure(nodeId));
autofetcher.start();
Expand All @@ -77,13 +65,13 @@ function NodeStructure({nodeId, className}: NodeStructureProps) {
}, [nodeId, dispatch]);

useEffect(() => {
if (!_.isEmpty(nodeStructure) && scrollContainer) {
if (!isEmpty(nodeStructure) && scrollContainerRef.current) {
isReady.current = true;
}
}, [nodeStructure]);

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

if (element) {
scrollContainer.scrollTo({
scrollContainerRef.current.scrollTo({
behavior: 'smooth',
// should subtract 20 to avoid sticking the element to tabs
top: scrollToVdisk ? scrollToVdisk : element.offsetTop,
Expand Down

0 comments on commit c3d0979

Please sign in to comment.