-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
feat(spans): Allow horizontal scrolling on left pane of span view #34006
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
1f9f002
feat(spans): Allow horizontal scrolling on left pane of span view
dashed c683f32
Merge branch 'master' into wheel-scroll-spanbar
0Calories 549ec0b
Move wheel events to ScrollPane component
0Calories e274b7d
Prevent scrolling if cursor is past the divider
0Calories 2351e55
Remove cursor position conditional check
0Calories bef0da5
Add isWheeling lock to prevent double rendering from onScroll event
0Calories f47b42a
Revert changes
0Calories 9aa9da1
Add isWheeling guard to prevent double renders
0Calories 98ddbdd
Use wheel event listener on ref only, and pass scrollbarmanager props…
0Calories fec7685
Set wheelTimeout to null in callback
0Calories 2aa8213
Add scrolling functionality to grouped spanbars
0Calories f4a9eaa
Fix linting issues
0Calories 8f9c3f8
Move onWheel outside of useEffect
0Calories 79ae18d
Linting
0Calories 33d8760
useCallback
0Calories febeb43
zzz
0Calories 633aba3
Update static/app/components/events/interfaces/spans/spanGroupBar.tsx
0Calories 9fbfbf0
Remove unused useCallback import
0Calories File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ export type ScrollbarManagerChildrenProps = { | |
generateContentSpanBarRef: () => (instance: HTMLDivElement | null) => void; | ||
onDragStart: (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => void; | ||
onScroll: () => void; | ||
onWheel: (deltaX: number) => void; | ||
scrollBarAreaRef: React.RefObject<HTMLDivElement>; | ||
updateScrollState: () => void; | ||
virtualScrollbarRef: React.RefObject<HTMLDivElement>; | ||
|
@@ -25,6 +26,7 @@ const ScrollbarManagerContext = createContext<ScrollbarManagerChildrenProps>({ | |
scrollBarAreaRef: createRef<HTMLDivElement>(), | ||
onDragStart: () => {}, | ||
onScroll: () => {}, | ||
onWheel: () => {}, | ||
updateScrollState: () => {}, | ||
}); | ||
|
||
|
@@ -105,6 +107,8 @@ export class Provider extends Component<Props, State> { | |
virtualScrollbar: React.RefObject<HTMLDivElement> = createRef<HTMLDivElement>(); | ||
scrollBarArea: React.RefObject<HTMLDivElement> = createRef<HTMLDivElement>(); | ||
isDragging: boolean = false; | ||
isWheeling: boolean = false; | ||
wheelTimeout: NodeJS.Timeout | null = null; | ||
previousUserSelect: UserSelectValues | null = null; | ||
|
||
getReferenceSpanBar() { | ||
|
@@ -233,11 +237,70 @@ export class Provider extends Component<Props, State> { | |
hasInteractiveLayer = (): boolean => !!this.props.interactiveLayerRef.current; | ||
initialMouseClickX: number | undefined = undefined; | ||
|
||
onScroll = () => { | ||
onWheel = (deltaX: number) => { | ||
if (this.isDragging || !this.hasInteractiveLayer()) { | ||
return; | ||
} | ||
|
||
// Setting this here is necessary, since updating the virtual scrollbar position will also trigger the onScroll function | ||
this.isWheeling = true; | ||
|
||
if (this.wheelTimeout) { | ||
clearTimeout(this.wheelTimeout); | ||
} | ||
|
||
this.wheelTimeout = setTimeout(() => { | ||
this.isWheeling = false; | ||
this.wheelTimeout = null; | ||
}, 200); | ||
|
||
const interactiveLayerRefDOM = this.props.interactiveLayerRef.current!; | ||
|
||
const interactiveLayerRect = interactiveLayerRefDOM.getBoundingClientRect(); | ||
const maxScrollLeft = | ||
interactiveLayerRefDOM.scrollWidth - interactiveLayerRefDOM.clientWidth; | ||
|
||
const scrollLeft = clamp( | ||
interactiveLayerRefDOM.scrollLeft + deltaX, | ||
0, | ||
maxScrollLeft | ||
); | ||
|
||
interactiveLayerRefDOM.scrollLeft = scrollLeft; | ||
|
||
// Update scroll position of the virtual scroll bar | ||
selectRefs(this.scrollBarArea, (scrollBarAreaDOM: HTMLDivElement) => { | ||
selectRefs(this.virtualScrollbar, (virtualScrollbarDOM: HTMLDivElement) => { | ||
const scrollBarAreaRect = scrollBarAreaDOM.getBoundingClientRect(); | ||
const virtualScrollbarPosition = scrollLeft / scrollBarAreaRect.width; | ||
|
||
const virtualScrollBarRect = rectOfContent(virtualScrollbarDOM); | ||
const maxVirtualScrollableArea = | ||
1 - virtualScrollBarRect.width / interactiveLayerRect.width; | ||
|
||
const virtualLeft = | ||
clamp(virtualScrollbarPosition, 0, maxVirtualScrollableArea) * | ||
interactiveLayerRect.width; | ||
|
||
virtualScrollbarDOM.style.transform = `translate3d(${virtualLeft}px, 0, 0)`; | ||
virtualScrollbarDOM.style.transformOrigin = 'left'; | ||
}); | ||
}); | ||
|
||
// Update scroll positions of all the span bars | ||
selectRefs(this.contentSpanBar, (spanBarDOM: HTMLDivElement) => { | ||
const left = -scrollLeft; | ||
|
||
spanBarDOM.style.transform = `translate3d(${left}px, 0, 0)`; | ||
spanBarDOM.style.transformOrigin = 'left'; | ||
}); | ||
}; | ||
Comment on lines
+271
to
+297
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. There is likely a ref-less solution to this or at least less transform changes, but we can try this out for now and measure perf on production to decide whether / how to fix it. |
||
|
||
onScroll = () => { | ||
if (this.isDragging || this.isWheeling || !this.hasInteractiveLayer()) { | ||
return; | ||
} | ||
|
||
const interactiveLayerRefDOM = this.props.interactiveLayerRef.current!; | ||
|
||
const interactiveLayerRect = interactiveLayerRefDOM.getBoundingClientRect(); | ||
|
@@ -415,6 +478,7 @@ export class Provider extends Component<Props, State> { | |
generateContentSpanBarRef: this.generateContentSpanBarRef, | ||
onDragStart: this.onDragStart, | ||
onScroll: this.onScroll, | ||
onWheel: this.onWheel, | ||
virtualScrollbarRef: this.virtualScrollbar, | ||
scrollBarAreaRef: this.scrollBarArea, | ||
updateScrollState: this.initializeScrollState, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
!
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 think it's safe to assume it's not null/undefined here, since the wheel event shouldn't be able to occur otherwise