Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions static/app/views/issueDetails/streamline/eventNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,13 @@ function EventNavigationLink({
config?.initialCollapse ?? false
);
return (
<Button
onClick={() => {
<LinkButton
to={{
...location,
hash: `#${config.key}`,
}}
onClick={event => {
event.preventDefault();
setIsCollapsed(false);
document
.getElementById(config.key)
Expand All @@ -354,7 +359,7 @@ function EventNavigationLink({
css={propCss}
>
{sectionLabels[config.key]}
</Button>
</LinkButton>
);
}

Expand Down
31 changes: 28 additions & 3 deletions static/app/views/issueDetails/streamline/foldSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
Fragment,
useCallback,
useLayoutEffect,
useRef,
useState,
} from 'react';
import styled from '@emotion/styled';
Expand All @@ -13,6 +14,7 @@ import InteractionStateLayer from 'sentry/components/interactionStateLayer';
import {IconChevron} from 'sentry/icons';
import {space} from 'sentry/styles/space';
import {trackAnalytics} from 'sentry/utils/analytics';
import mergeRefs from 'sentry/utils/mergeRefs';
import useOrganization from 'sentry/utils/useOrganization';
import {useSyncedLocalStorageState} from 'sentry/utils/useSyncedLocalStorageState';
import type {SectionKey} from 'sentry/views/issueDetails/streamline/context';
Expand Down Expand Up @@ -53,7 +55,6 @@ export const FoldSection = forwardRef<HTMLElement, FoldSectionProps>(function Fo
sectionKey,
initialCollapse = false,
preventCollapse = false,
...props
},
forwardedRef
) {
Expand All @@ -64,6 +65,31 @@ export const FoldSection = forwardRef<HTMLElement, FoldSectionProps>(function Fo
getFoldSectionKey(sectionKey),
initialCollapse
);
const hasAttemptedScroll = useRef(false);

const scrollToSection = useCallback(
(element: HTMLElement | null) => {
if (!element || !navScrollMargin || hasAttemptedScroll.current) {
return;
}
// Prevent scrolling to element on rerenders
hasAttemptedScroll.current = true;

// scroll to element if it's the current section on page load
if (window.location.hash) {
const [, hash] = window.location.hash.split('#');
if (hash === sectionKey) {
if (isCollapsed) {
setIsCollapsed(false);
}

// Delay scrollIntoView to allow for layout changes to take place
setTimeout(() => element?.scrollIntoView(), 100);
}
}
},
[sectionKey, navScrollMargin, isCollapsed, setIsCollapsed]
);

useLayoutEffect(() => {
if (!sectionData.hasOwnProperty(sectionKey)) {
Expand Down Expand Up @@ -92,8 +118,7 @@ export const FoldSection = forwardRef<HTMLElement, FoldSectionProps>(function Fo
return (
<Fragment>
<Section
{...props}
ref={forwardedRef}
ref={mergeRefs([forwardedRef, scrollToSection])}
id={sectionKey}
scrollMargin={navScrollMargin ?? 0}
>
Expand Down
Loading