Skip to content

Commit e804515

Browse files
committed
added auto scroll for history link
1 parent 5bedb62 commit e804515

File tree

5 files changed

+35
-11
lines changed

5 files changed

+35
-11
lines changed

src/app/components/StateRoute/History.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable react-hooks/exhaustive-deps */
22
/* eslint-disable */
33
// @ts-nocheck
4-
import React, { useEffect } from 'react';
4+
import React, { useEffect, useRef } from 'react';
55
// formatting findDiff return data to show the changes with colors, aligns with actions.tsx
66
import { diff, formatters } from 'jsondiffpatch';
77
import * as d3 from 'd3';
@@ -41,6 +41,8 @@ function History(props: Record<string, unknown>): JSX.Element {
4141

4242
const svgRef = React.useRef(null);
4343
const root = JSON.parse(JSON.stringify(hierarchy));
44+
const historyEndRef = useRef<HTMLDivElement>(null);
45+
4446
// setting the margins for the Map to render in the tab window.
4547
const innerWidth: number = totalWidth - margin.left - margin.right;
4648
const innerHeight: number = totalHeight - margin.top - margin.bottom - 60;
@@ -239,21 +241,26 @@ function History(props: Record<string, unknown>): JSX.Element {
239241
.style('padding-left', '8px')
240242
.html((d) => findDiff(d.data.index));
241243

244+
if (historyEndRef.current) {
245+
historyEndRef.current.scrollIntoView({ behavior: 'smooth' });
246+
}
242247
return svg.node();
243248
};
244249

245250
useEffect(() => {
246251
makeD3Tree();
247-
}, [root /*, currLocation*/]); // if the 'root' or 'currLocation' changes, re-build the D3 Tree
252+
}, [root, currLocation]);
248253

249254
useEffect(() => {
250255
dispatch(setCurrentTabInApp('history')); // dispatch sent at initial page load allowing changing "immer's" draft.currentTabInApp to 'webmetrics' to facilitate render.
251256
}, []);
252257

253-
// then rendering each node in History tab to render using D3, which will share area with LegendKey
254258
return (
255-
<div className='display'>
256-
<svg ref={svgRef} width={totalWidth} height={totalHeight} />
259+
<div className='history-view'>
260+
<div className='display'>
261+
<svg ref={svgRef} width={totalWidth} height={totalHeight} />
262+
<div ref={historyEndRef} className='history-end-anchor' />
263+
</div>
257264
</div>
258265
);
259266
}

src/app/containers/ActionContainer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function ActionContainer(props: ActionContainerProps): JSX.Element {
3333
if (actionsEndRef.current) {
3434
actionsEndRef.current.scrollIntoView({ behavior: 'smooth' });
3535
}
36-
}, [snapshots]); // Dependency on snapshots array
36+
}, [snapshots]);
3737

3838
const displayArray = (obj: Obj): void => {
3939
if (

src/app/styles/components/d3graph.css

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,9 @@ div.tooltip {
8787
/* Container styling */
8888
.display {
8989
background-color: var(--bg-secondary);
90-
height: 100%;
91-
width: 100%;
90+
flex: 1;
91+
min-height: 0;
9292
overflow: auto;
93-
position: relative;
9493
}
9594

9695
/* State changes text container styling */

src/app/styles/layout/_mainContainer.scss

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,15 @@
1111
height: 100%;
1212
overflow: auto;
1313
}
14+
15+
.history-view {
16+
height: 100%;
17+
width: 100%;
18+
display: flex;
19+
flex-direction: column;
20+
}
21+
22+
.history-end-anchor {
23+
height: 1px;
24+
width: 100%;
25+
}

src/app/styles/layout/_stateContainer.scss

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,16 @@
55
flex-direction: column;
66
}
77

8-
.app-content,
98
.app-body {
109
height: 100%;
11-
overflow: hidden;
10+
display: flex;
11+
flex-direction: column;
12+
}
13+
14+
.app-content {
15+
flex: 1;
16+
min-height: 0;
17+
position: relative;
1218
}
1319

1420
.main-navbar-container--structural {

0 commit comments

Comments
 (0)