Skip to content

Commit

Permalink
Merge pull request #489 from pe4cey/3.0-stop-to-top-on-frame-removal
Browse files Browse the repository at this point in the history
Only scroll to top of stream when frame is added and toggle is on
  • Loading branch information
irfannuri authored May 5, 2017
2 parents 53262ba + dc4e327 commit 081b2e7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
7 changes: 7 additions & 0 deletions src/browser/modules/Sidebar/Settings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ const visualSettings =
displayName: 'Max History',
tooltip: 'Max number of history entries. When reached, old entries gets retired.'
}
},
{
scrollToTop: {
displayName: 'Scroll To Top',
tooltip: 'Automatically scroll stream to top on new frames.',
type: 'checkbox'
}
}
]
},
Expand Down
12 changes: 7 additions & 5 deletions src/browser/modules/Stream/Stream.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ import SysInfoFrame from './SysInfoFrame'
import ConnectionFrame from './Auth/ConnectionFrame'
import DisconnectFrame from './Auth/DisconnectFrame'
import ChangePasswordFrame from './Auth/ChangePasswordFrame'
import QueriesFrame from './Queries/QueriesFrame'
import UserList from '../User/UserList'
import UserAdd from '../User/UserAdd'
import { getFrames, setRecentView, getRecentView } from 'shared/modules/stream/streamDuck'
import { getRequests } from 'shared/modules/requests/requestsDuck'
import { getActiveConnectionData } from 'shared/modules/connections/connectionsDuck'
import QueriesFrame from './Queries/QueriesFrame'
import { getMaxRows, getInitialNodeDisplay } from 'shared/modules/settings/settingsDuck'
import { getMaxRows, getInitialNodeDisplay, getScrollToTop } from 'shared/modules/settings/settingsDuck'

const getFrame = (type) => {
const trans = {
Expand Down Expand Up @@ -70,7 +70,8 @@ const getFrame = (type) => {

class Stream extends Component {
shouldComponentUpdate (nextProps, nextState) {
const hasSameAmountOfFrames = this.props.frames.length === nextProps.frames.length
const frameHasBeenAdded = this.props.frames.length < nextProps.frames.length

if (this.props.activeConnectionData === nextProps.activeConnectionData &&
this.props.requests === nextProps.requests &&
(this.props.children.length === nextProps.children.length &&
Expand All @@ -84,7 +85,7 @@ class Stream extends Component {
) {
return false
} else {
if (!hasSameAmountOfFrames) {
if (this.props.scrollToTop && frameHasBeenAdded) {
this.base.scrollTop = 0
}
return true
Expand Down Expand Up @@ -121,7 +122,8 @@ const mapStateToProps = (state) => {
activeConnectionData: getActiveConnectionData(state),
recentView: getRecentView(state),
maxRows: getMaxRows(state),
initialNodeDisplay: getInitialNodeDisplay(state)
initialNodeDisplay: getInitialNodeDisplay(state),
scrollToTop: getScrollToTop(state)
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/shared/modules/settings/settingsDuck.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const getBrowserSyncConfig = (state) => {
export const getMaxNeighbours = (state) => state[NAME].maxNeighbours || initialState.maxNeighbours
export const getMaxRows = (state) => state[NAME].maxRows || initialState.maxRows
export const getInitialNodeDisplay = (state) => state[NAME].initialNodeDisplay || initialState.initialNodeDisplay
export const getScrollToTop = (state) => state[NAME].scrollToTop
export const shouldReportUdc = (state) => state[NAME].shouldReportUdc !== false
export const shouldAutoComplete = (state) => state[NAME].autoComplete !== false

Expand All @@ -63,7 +64,8 @@ const initialState = {
browserSyncDebugServer: null,
maxRows: 1000,
shouldReportUdc: true,
autoComplete: true
autoComplete: true,
scrollToTop: true
}

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

0 comments on commit 081b2e7

Please sign in to comment.