Skip to content

Commit 7236a43

Browse files
committed
fix(Node): scroll to selected vdisk should not apply to undefined container
1 parent e6d9086 commit 7236a43

File tree

3 files changed

+19
-27
lines changed

3 files changed

+19
-27
lines changed

src/containers/Node/Node.tsx

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ interface NodeProps {
3939

4040
function Node(props: NodeProps) {
4141
const dispatch = useDispatch();
42-
const repaint = React.useState({})[1];
4342

4443
const wasLoaded = useSelector((state: any) => state.node.wasLoaded);
4544
const loading = useSelector((state: any) => state.node.loading);
@@ -72,8 +71,6 @@ function Node(props: NodeProps) {
7271
return {activeTabVerified, nodeTabs};
7372
}, [activeTab, node]);
7473

75-
const nodeContainerRef = React.useRef<HTMLDivElement | null>(null);
76-
7774
React.useEffect(() => {
7875
const fetchData = () => dispatch(getNodeInfo(nodeId));
7976
fetchData();
@@ -148,7 +145,6 @@ function Node(props: NodeProps) {
148145
className={b('node-page-wrapper')}
149146
nodeId={nodeId}
150147
additionalNodesInfo={additionalNodesInfo}
151-
scrollContainer={nodeContainerRef.current}
152148
/>
153149
);
154150
}
@@ -157,26 +153,17 @@ function Node(props: NodeProps) {
157153
}
158154
};
159155

160-
const onRefChange = (ref: HTMLDivElement) => {
161-
if (!nodeContainerRef.current) {
162-
nodeContainerRef.current = ref;
163-
repaint({});
164-
}
165-
};
166-
167156
if (loading && !wasLoaded) {
168157
return <Loader />;
169158
} else if (error) {
170159
return <div>{error.statusText}</div>;
171160
} else {
172161
if (node) {
173162
return (
174-
<div className={`${b()} ${props.className}`}>
163+
<div className={b(null, props.className)}>
175164
{renderTabs()}
176165

177-
<div className={b('content')} ref={onRefChange}>
178-
{renderTabContent()}
179-
</div>
166+
<div className={b('content')}>{renderTabContent()}</div>
180167
</div>
181168
);
182169
}

src/containers/Node/NodeStructure/NodeStructure.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
@import '../../../styles/mixins.scss';
22

33
.kv-node-structure {
4+
position: relative;
5+
46
display: flex;
57
overflow: auto;
68
flex-direction: column;
79
flex-shrink: 0;
10+
@include flex-container();
811
@include body2-typography();
912

1013
&__loader {

src/containers/Node/NodeStructure/NodeStructure.tsx

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ interface NodeStructureProps {
2828
nodeId: string;
2929
className?: string;
3030
additionalNodesInfo?: any;
31-
scrollContainer: Element | null;
3231
}
3332

3433
const autofetcher = new AutoFetcher();
@@ -40,9 +39,7 @@ function NodeStructure(props: NodeStructureProps) {
4039

4140
const loadingStructure = useSelector((state: any) => state.node.loadingStructure);
4241
const wasLoadedStructure = useSelector((state: any) => state.node.wasLoadedStructure);
43-
const nodeData = useSelector(
44-
(state: any) => state.node?.data?.SystemStateInfo?.[0]
45-
);
42+
const nodeData = useSelector((state: any) => state.node?.data?.SystemStateInfo?.[0]);
4643

4744
const nodeHref = useMemo(() => {
4845
return props.additionalNodesInfo?.getNodeRef
@@ -55,13 +52,15 @@ function NodeStructure(props: NodeStructureProps) {
5552
true,
5653
).query;
5754

55+
const scrollContainerRef = useRef<HTMLDivElement>(null);
56+
const scrollContainer = scrollContainerRef.current;
57+
5858
const isReady = useRef(false);
5959

6060
const scrolled = useRef(false);
6161

6262
useEffect(() => {
6363
return () => {
64-
const {scrollContainer} = props;
6564
if (scrollContainer) {
6665
scrollContainer.scrollTo({
6766
behavior: 'smooth',
@@ -84,13 +83,12 @@ function NodeStructure(props: NodeStructureProps) {
8483
}, [props.nodeId, dispatch]);
8584

8685
useEffect(() => {
87-
if (!_.isEmpty(nodeStructure) && props.scrollContainer) {
86+
if (!_.isEmpty(nodeStructure) && scrollContainer) {
8887
isReady.current = true;
8988
}
90-
}, [nodeStructure, props.scrollContainer]);
89+
}, [nodeStructure]);
9190

9291
useEffect(() => {
93-
const {scrollContainer} = props;
9492
if (isReady.current && !scrolled.current && scrollContainer) {
9593
const element = document.getElementById(
9694
generateId({type: 'pdisk', id: pdiskIdFromUrl as string}),
@@ -105,20 +103,20 @@ function NodeStructure(props: NodeStructureProps) {
105103
const order = vDisk?.order;
106104

107105
if (dataTable) {
108-
scrollToVdisk += (dataTable as HTMLElement).offsetTop + 40 * (order + 1);
106+
scrollToVdisk += (dataTable as HTMLElement).offsetTop + 40 * order;
109107
}
110108
}
111109

112110
if (element) {
113111
scrollContainer.scrollTo({
114112
behavior: 'smooth',
115113
// should subtract 20 to avoid sticking the element to tabs
116-
top: scrollToVdisk ? scrollToVdisk : element.offsetTop - 20,
114+
top: scrollToVdisk ? scrollToVdisk : element.offsetTop,
117115
});
118116
scrolled.current = true;
119117
}
120118
}
121-
}, [nodeStructure, props.scrollContainer, pdiskIdFromUrl, vdiskIdFromUrl]);
119+
}, [nodeStructure, pdiskIdFromUrl, vdiskIdFromUrl]);
122120

123121
const renderStub = () => {
124122
return 'There is no information about node structure.';
@@ -147,7 +145,11 @@ function NodeStructure(props: NodeStructureProps) {
147145
return renderStructure();
148146
};
149147

150-
return <div className={b(null, props.className)}>{renderContent()}</div>;
148+
return (
149+
<div className={b()} ref={scrollContainerRef}>
150+
<div className={props.className}>{renderContent()}</div>
151+
</div>
152+
);
151153
}
152154

153155
export default NodeStructure;

0 commit comments

Comments
 (0)