-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Checking that there is indeed a selection before scrolling #257
Changes from 8 commits
4702db9
6700c6f
ae29dff
07ebdb7
b984f49
8d40d64
3ad96e4
6f8a4db
38b9f7d
b7ea117
3649075
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -46,11 +46,13 @@ interface SeqViewerContainerProps { | |||
rotateOnScroll: boolean; | ||||
search: NameRange[]; | ||||
selectAllEvent: (event: React.KeyboardEvent<HTMLElement>) => boolean; | ||||
selection?: { | ||||
clockwise?: boolean; | ||||
end: number; | ||||
start: number; | ||||
}; | ||||
selection?: | ||||
| { | ||||
clockwise?: boolean; | ||||
end: number; | ||||
start: number; | ||||
} | ||||
| Selection; | ||||
seq: string; | ||||
seqType: SeqType; | ||||
showComplement: boolean; | ||||
|
@@ -91,6 +93,24 @@ class SeqViewerContainer extends React.Component<SeqViewerContainerProps, SeqVie | |||
}; | ||||
} | ||||
|
||||
selectionIsProgramatic(selection: any): selection is Selection { | ||||
// If the selection was done programatically, it has not type | ||||
return !selection.type; | ||||
} | ||||
|
||||
// If the selection prop updates, also scroll the linear view to the new selection | ||||
componentDidUpdate = (prevProps: SeqViewerContainerProps) => { | ||||
// Only scroll if the selection was done programatically | ||||
guzmanvig marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
if (this.selectionIsProgramatic(this.props.selection)) { | ||||
if ( | ||||
this.props.selection?.start !== prevProps.selection?.start && | ||||
this.props.selection?.start !== this.props.selection?.end | ||||
) { | ||||
this.setCentralIndex("LINEAR", this.props.selection?.start || 0); | ||||
} | ||||
} | ||||
}; | ||||
|
||||
/** this is here because the size listener is returning a new "size" prop every time */ | ||||
shouldComponentUpdate = (nextProps: SeqViewerContainerProps, nextState: any) => | ||||
!isEqual(nextProps, this.props) || !isEqual(nextState, this.state); | ||||
|
@@ -125,11 +145,13 @@ class SeqViewerContainer extends React.Component<SeqViewerContainerProps, SeqVie | |||
*/ | ||||
getSelection = ( | ||||
state: Selection, | ||||
prop?: { | ||||
clockwise?: boolean; | ||||
end: number; | ||||
start: number; | ||||
} | ||||
prop?: | ||||
| { | ||||
clockwise?: boolean; | ||||
end: number; | ||||
start: number; | ||||
} | ||||
| Selection | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this doesn't need to change either, it's 1:1 w/ the prop that users pass in so it doesn't have those other fields. Looking thru it quickly, a few lines (maybe more) that need to change:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure this is right, the
I've added an |
||||
): Selection => { | ||||
if (prop) { | ||||
return { ...prop, clockwise: typeof prop.clockwise === "undefined" || !!prop.clockwise, type: "" }; | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to change this one. This is the prop that can only be passed from the public prop. It's the state on the component, and the func args, that need that enhancement
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was my understanding as well, but for some reason the function
componentDidUpdate = (prevProps: SeqViewerContainerProps)
gets called when a user clicks on an element, and inthis.props.selection
you see the selection with type and the other fields.In any case, I removed this since the type guard takes care of checking if it's a Selection or not.