Skip to content

Commit 081b2e7

Browse files
authored
Merge pull request #489 from pe4cey/3.0-stop-to-top-on-frame-removal
Only scroll to top of stream when frame is added and toggle is on
2 parents 53262ba + dc4e327 commit 081b2e7

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

src/browser/modules/Sidebar/Settings.jsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ const visualSettings =
5858
displayName: 'Max History',
5959
tooltip: 'Max number of history entries. When reached, old entries gets retired.'
6060
}
61+
},
62+
{
63+
scrollToTop: {
64+
displayName: 'Scroll To Top',
65+
tooltip: 'Automatically scroll stream to top on new frames.',
66+
type: 'checkbox'
67+
}
6168
}
6269
]
6370
},

src/browser/modules/Stream/Stream.jsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ import SysInfoFrame from './SysInfoFrame'
3636
import ConnectionFrame from './Auth/ConnectionFrame'
3737
import DisconnectFrame from './Auth/DisconnectFrame'
3838
import ChangePasswordFrame from './Auth/ChangePasswordFrame'
39+
import QueriesFrame from './Queries/QueriesFrame'
3940
import UserList from '../User/UserList'
4041
import UserAdd from '../User/UserAdd'
4142
import { getFrames, setRecentView, getRecentView } from 'shared/modules/stream/streamDuck'
4243
import { getRequests } from 'shared/modules/requests/requestsDuck'
4344
import { getActiveConnectionData } from 'shared/modules/connections/connectionsDuck'
44-
import QueriesFrame from './Queries/QueriesFrame'
45-
import { getMaxRows, getInitialNodeDisplay } from 'shared/modules/settings/settingsDuck'
45+
import { getMaxRows, getInitialNodeDisplay, getScrollToTop } from 'shared/modules/settings/settingsDuck'
4646

4747
const getFrame = (type) => {
4848
const trans = {
@@ -70,7 +70,8 @@ const getFrame = (type) => {
7070

7171
class Stream extends Component {
7272
shouldComponentUpdate (nextProps, nextState) {
73-
const hasSameAmountOfFrames = this.props.frames.length === nextProps.frames.length
73+
const frameHasBeenAdded = this.props.frames.length < nextProps.frames.length
74+
7475
if (this.props.activeConnectionData === nextProps.activeConnectionData &&
7576
this.props.requests === nextProps.requests &&
7677
(this.props.children.length === nextProps.children.length &&
@@ -84,7 +85,7 @@ class Stream extends Component {
8485
) {
8586
return false
8687
} else {
87-
if (!hasSameAmountOfFrames) {
88+
if (this.props.scrollToTop && frameHasBeenAdded) {
8889
this.base.scrollTop = 0
8990
}
9091
return true
@@ -121,7 +122,8 @@ const mapStateToProps = (state) => {
121122
activeConnectionData: getActiveConnectionData(state),
122123
recentView: getRecentView(state),
123124
maxRows: getMaxRows(state),
124-
initialNodeDisplay: getInitialNodeDisplay(state)
125+
initialNodeDisplay: getInitialNodeDisplay(state),
126+
scrollToTop: getScrollToTop(state)
125127
}
126128
}
127129

src/shared/modules/settings/settingsDuck.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export const getBrowserSyncConfig = (state) => {
3737
export const getMaxNeighbours = (state) => state[NAME].maxNeighbours || initialState.maxNeighbours
3838
export const getMaxRows = (state) => state[NAME].maxRows || initialState.maxRows
3939
export const getInitialNodeDisplay = (state) => state[NAME].initialNodeDisplay || initialState.initialNodeDisplay
40+
export const getScrollToTop = (state) => state[NAME].scrollToTop
4041
export const shouldReportUdc = (state) => state[NAME].shouldReportUdc !== false
4142
export const shouldAutoComplete = (state) => state[NAME].autoComplete !== false
4243

@@ -63,7 +64,8 @@ const initialState = {
6364
browserSyncDebugServer: null,
6465
maxRows: 1000,
6566
shouldReportUdc: true,
66-
autoComplete: true
67+
autoComplete: true,
68+
scrollToTop: true
6769
}
6870

6971
export default function settings (state = initialState, action) {

0 commit comments

Comments
 (0)