Skip to content

Commit cf1df63

Browse files
ref(navigation): Stop gating hover previews on universal-inbox (#132205)
#130946 turned off the nav hover behavior for orgs with `organizations:universal-inbox`. After negative feedback on that change, we're separating the nav changes from the Inbox flag. This PR removes them from the flag, which is effectively reverts the hover change. We also introduce a slightly different behavior from the inbox, in the spirit of the previous interaction. <details> <summary>Full context (actually pretty helpful)</summary> The new hover behavior is piloted separately behind `organizations:nav-peek` (added in #132197, piloted in #132206). Nothing here checks the new flag. #131856 and #130219 are both still open, so the only hover changes that shipped behind `universal-inbox` came from #130946. **What goes back to the old behavior for orgs with `universal-inbox`** - Hovering a primary nav item previews its group in the secondary sidebar again. That includes the mouse-intent delay (`useMouseMovement`). - The secondary sidebar's slide/fade animation runs again when the group switches. - `useNavigationGroupHoverEnabled` is removed. The nav now reads `universal-inbox` only to decide whether to show the Inbox item. **What stays behind `universal-inbox`** - The Inbox primary nav item, its unread count, and the `/inbox/` page. - Inbox has no secondary sidebar. While the sidebar is expanded, hovering the Inbox item does nothing, so the sidebar isn't pulled out from under the page. Clicking it navigates. **Pages without a secondary sidebar use the collapsed behavior** The Inbox page has no secondary sidebar, so an inline preview would push the page aside. Instead, on any route group configured with `secondaryNavigation: false`, the secondary nav is always collapsed. In practice that's `/inbox/` today. Hovering a primary item there opens its group in the existing collapsed-mode peek overlay, and moving away closes it. `SecondaryNavigationContextProvider` takes a `forceCollapsed` prop for this, set from the route group in `PrimaryNavigationContextProvider`: - The Expand/Collapse toggle is hidden there, since the page decides the state. - Peeks there are tracked apart from the user's saved collapsed preference, so it is neither read nor overwritten. Leaving the Inbox restores whatever the user had before. - The overlay works as soon as `/inbox/` is active, including right after opening the Inbox from the rail. `useCollapsedNavigation` used to attach its hover listeners only once the sidebar collapsed, so a pointer already inside the nav never sent a `mouseenter`. It now tracks the pointer while expanded too, and starts the peek when a page forces the collapse with the pointer already over the nav. It doesn't do this when the user collapses the sidebar themselves, so the toggle still doesn't reopen it under the pointer. - Hovering an item without a secondary nav (Inbox) while the overlay is open hides the overlay. Moving on to another item shows that item's overlay again. This applies whenever the sidebar is collapsed, whether the page forced it or the user collapsed it. <!-- junior-request-attribution:start --> via @natemoo-re. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:local%3Aweb%3A226fcac104760f6113ca947c --> -- [View Session](https://junior-prod.sentry.dev/conversations/local%3Aweb%3A226fcac104760f6113ca947c) [[Sentry]](https://sentry.sentry.io/explore/conversations/local%3Aweb%3A226fcac104760f6113ca947c/?project=4510944073809921) <!-- junior-session-footer:end --> </details> --------- Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: nate <7118177+natemoo-re@users.noreply.github.com> Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com>
1 parent ff3376d commit cf1df63

6 files changed

Lines changed: 227 additions & 53 deletions

File tree

‎static/app/views/navigation/index.desktop.spec.tsx‎

Lines changed: 134 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {UserFixture} from 'sentry-fixture/user';
1010
import {
1111
act,
1212
cleanup,
13+
fireEvent,
1314
render,
1415
type RouterConfig,
1516
screen,
@@ -1969,6 +1970,26 @@ describe('desktop navigation', () => {
19691970
).not.toBeInTheDocument();
19701971
});
19711972

1973+
it('previews groups on hover', async () => {
1974+
render(
1975+
<PrimaryNavigationContextProvider>
1976+
<Navigation />
1977+
</PrimaryNavigationContextProvider>,
1978+
navigationContext({organization: universalInbox})
1979+
);
1980+
1981+
const secondaryNav = screen.getByRole('navigation', {
1982+
name: 'Secondary Navigation',
1983+
});
1984+
expect(
1985+
within(secondaryNav).getByRole('link', {name: 'Feed'})
1986+
).toBeInTheDocument();
1987+
1988+
await userEvent.hover(screen.getByRole('link', {name: 'Explore'}));
1989+
1990+
expect(await screen.findByRole('link', {name: 'Traces'})).toBeInTheDocument();
1991+
});
1992+
19721993
describe('hover', () => {
19731994
beforeEach(() => {
19741995
jest.useFakeTimers();
@@ -1983,32 +2004,136 @@ describe('desktop navigation', () => {
19832004
}
19842005
});
19852006

1986-
it('does not preview groups on hover', async () => {
2007+
async function hoverAndWait(name: string) {
2008+
await userEvent.hover(screen.getByRole('link', {name}), {delay: null});
2009+
// Advance past the longest hover activation delay.
2010+
act(() => jest.advanceTimersByTime(250));
2011+
}
2012+
2013+
it('does not preview anything when hovering Inbox', async () => {
19872014
render(
19882015
<PrimaryNavigationContextProvider>
19892016
<Navigation />
19902017
</PrimaryNavigationContextProvider>,
19912018
navigationContext({organization: universalInbox})
19922019
);
19932020

2021+
await hoverAndWait('Inbox');
2022+
19942023
const secondaryNav = screen.getByRole('navigation', {
19952024
name: 'Secondary Navigation',
19962025
});
19972026
expect(
19982027
within(secondaryNav).getByRole('link', {name: 'Feed'})
19992028
).toBeInTheDocument();
2029+
});
2030+
});
20002031

2001-
await userEvent.hover(screen.getByRole('link', {name: 'Explore'}), {
2002-
delay: null,
2003-
});
2004-
// Advance past the longest hover activation delay.
2005-
act(() => jest.advanceTimersByTime(250));
2032+
it('previews hovered groups as an overlay right after opening the inbox', async () => {
2033+
const {router} = render(
2034+
<PrimaryNavigationContextProvider>
2035+
<Navigation />
2036+
</PrimaryNavigationContextProvider>,
2037+
navigationContext({organization: universalInbox})
2038+
);
2039+
2040+
// The pointer enters the nav while it is still expanded, opens the inbox
2041+
// from the rail, and moves on to another item without leaving the nav.
2042+
// fireEvent keeps the parent from receiving a second mouseenter, which
2043+
// is what happens in a browser.
2044+
const primaryNav = screen.getByRole('navigation', {name: 'Primary Navigation'});
2045+
fireEvent.mouseEnter(primaryNav.parentElement!);
2046+
fireEvent.click(screen.getByRole('link', {name: 'Inbox'}));
2047+
expect(router.location.pathname).toBe('/organizations/org-slug/inbox/');
2048+
fireEvent.mouseOver(screen.getByRole('link', {name: 'Explore'}));
2049+
2050+
await waitFor(() => {
2051+
expect(screen.getByTestId('collapsed-secondary-sidebar')).toHaveAttribute(
2052+
'data-visible',
2053+
'true'
2054+
);
2055+
});
2056+
expect(await screen.findByRole('link', {name: 'Traces'})).toBeInTheDocument();
2057+
});
2058+
2059+
it('hides the inbox overlay when hovering an item without a secondary navigation', async () => {
2060+
render(
2061+
<PrimaryNavigationContextProvider>
2062+
<Navigation />
2063+
</PrimaryNavigationContextProvider>,
2064+
navigationContext({
2065+
organization: universalInbox,
2066+
initialRouterConfig: {location: {pathname: '/organizations/org-slug/inbox/'}},
2067+
})
2068+
);
20062069

2070+
await userEvent.hover(screen.getByRole('link', {name: 'Explore'}));
2071+
await waitFor(() => {
2072+
expect(screen.getByTestId('collapsed-secondary-sidebar')).toHaveAttribute(
2073+
'data-visible',
2074+
'true'
2075+
);
2076+
});
2077+
2078+
await userEvent.hover(screen.getByRole('link', {name: 'Inbox'}));
2079+
await waitFor(() => {
20072080
expect(
2008-
within(secondaryNav).getByRole('link', {name: 'Feed'})
2009-
).toBeInTheDocument();
2010-
expect(screen.queryByRole('link', {name: 'Traces'})).not.toBeInTheDocument();
2081+
screen.queryByTestId('collapsed-secondary-sidebar')
2082+
).not.toBeInTheDocument();
20112083
});
2084+
2085+
// Moving on to an item with a secondary navigation shows it again.
2086+
await userEvent.hover(screen.getByRole('link', {name: 'Explore'}));
2087+
await waitFor(() => {
2088+
expect(screen.getByTestId('collapsed-secondary-sidebar')).toHaveAttribute(
2089+
'data-visible',
2090+
'true'
2091+
);
2092+
});
2093+
});
2094+
2095+
it('previews hovered groups as an overlay on the inbox', async () => {
2096+
const {router} = render(
2097+
<PrimaryNavigationContextProvider>
2098+
<Navigation />
2099+
</PrimaryNavigationContextProvider>,
2100+
navigationContext({
2101+
organization: universalInbox,
2102+
initialRouterConfig: {location: {pathname: '/organizations/org-slug/inbox/'}},
2103+
})
2104+
);
2105+
2106+
const primaryNav = screen.getByRole('navigation', {name: 'Primary Navigation'});
2107+
await userEvent.hover(screen.getByRole('link', {name: 'Explore'}));
2108+
await waitFor(() => {
2109+
expect(screen.getByTestId('collapsed-secondary-sidebar')).toHaveAttribute(
2110+
'data-visible',
2111+
'true'
2112+
);
2113+
});
2114+
expect(await screen.findByRole('link', {name: 'Traces'})).toBeInTheDocument();
2115+
// The inbox decides that the sidebar is collapsed, so it cannot be expanded.
2116+
expect(screen.queryByRole('button', {name: 'Expand'})).not.toBeInTheDocument();
2117+
2118+
await userEvent.unhover(primaryNav);
2119+
await waitFor(() => {
2120+
expect(
2121+
screen.queryByTestId('collapsed-secondary-sidebar')
2122+
).not.toBeInTheDocument();
2123+
});
2124+
2125+
// The user's expanded preference is kept for the rest of the app.
2126+
await userEvent.click(screen.getByRole('link', {name: 'Issues'}));
2127+
expect(router.location.pathname).toBe('/organizations/org-slug/issues/');
2128+
expect(
2129+
screen.getByRole('navigation', {name: 'Secondary Navigation'})
2130+
).toBeInTheDocument();
2131+
expect(
2132+
screen.queryByTestId('collapsed-secondary-sidebar')
2133+
).not.toBeInTheDocument();
2134+
expect(
2135+
localStorage.getItem(NAVIGATION_SIDEBAR_COLLAPSED_LOCAL_STORAGE_KEY)
2136+
).toBeNull();
20122137
});
20132138

20142139
it('shows the secondary navigation after navigating away from the inbox', async () => {

‎static/app/views/navigation/primary/useActivateNavigationGroupOnHover.tsx‎

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {useLocation} from 'sentry/utils/useLocation';
77
import {PRIMARY_SIDEBAR_WIDTH} from 'sentry/views/navigation/constants';
88
import {
99
hasSecondaryNavigation,
10-
useNavigationGroupHoverEnabled,
1110
usePrimaryNavigation,
1211
} from 'sentry/views/navigation/primaryNavigationContext';
1312
import {useSecondaryNavigation} from 'sentry/views/navigation/secondaryNavigationContext';
@@ -29,8 +28,8 @@ import {useMouseMovement} from './useMouseMovement';
2928
* 2. If it looks like the user is skimming the side of the nav (e.g. they are browsing the secondary
3029
* nav), an extra delay is added to prevent accidental activation.
3130
*
32-
* Hover activation is skipped when `useNavigationGroupHoverEnabled` is false, and for
33-
* groups without a secondary navigation.
31+
* While the sidebar is expanded, hover activation is skipped for groups without
32+
* a secondary navigation.
3433
*/
3534

3635
interface UseActivateNavigationGroupOnHoverProps {
@@ -42,12 +41,8 @@ export function useActivateNavigationGroupOnHover({
4241
const {layout, features, setActiveGroup, activeGroup} = usePrimaryNavigation();
4342
const {view, setView} = useSecondaryNavigation();
4443
const location = useLocation();
45-
const hoverEnabled = useNavigationGroupHoverEnabled();
4644

47-
const mouseAccelerationRef = useMouseMovement({
48-
ref,
49-
disabled: layout !== 'sidebar' || !hoverEnabled,
50-
});
45+
const mouseAccelerationRef = useMouseMovement({ref, disabled: layout !== 'sidebar'});
5146
const timeoutRef = useRef<NodeJS.Timeout | null>(null);
5247
const windowHeight = useWindowHeight();
5348

@@ -139,9 +134,10 @@ export function useActivateNavigationGroupOnHover({
139134
setActiveGroup(group);
140135
};
141136

142-
// Hovering a group without a secondary navigation would only hide the
143-
// secondary sidebar, so there is nothing to preview.
144-
const canPreview = hoverEnabled && hasSecondaryNavigation(group);
137+
// A group without a secondary navigation renders no sidebar. Activating it
138+
// hides a collapsed peek, but would pull an expanded sidebar out from under
139+
// the page, so it is skipped there.
140+
const canPreview = hasSecondaryNavigation(group) || view !== 'expanded';
145141

146142
return {
147143
'aria-current': isActive ? ('location' as const) : undefined,

‎static/app/views/navigation/primaryNavigationContext.tsx‎

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,6 @@ export function hasSecondaryNavigation(group: NavigationGroup): boolean {
4242
return PRIMARY_NAVIGATION_GROUP_CONFIG[group].secondaryNavigation;
4343
}
4444

45-
/**
46-
* Whether hovering a primary navigation item previews its group in the
47-
* secondary navigation. When disabled, the secondary navigation only follows
48-
* the current route (and clicks on primary items).
49-
*/
50-
export function useNavigationGroupHoverEnabled(): boolean {
51-
const organization = useOrganization({allowNull: true});
52-
return !organization?.features.includes('universal-inbox');
53-
}
54-
5545
const PRIMARY_NAVIGATION_ROUTE_OVERRIDES: Array<{
5646
group: NavigationGroup;
5747
pattern: RegExp;
@@ -141,7 +131,11 @@ export function PrimaryNavigationContextProvider(
141131
);
142132

143133
return (
144-
<SecondaryNavigationContextProvider>
134+
// Pages without a secondary navigation keep the sidebar collapsed, so hovering
135+
// a primary item previews its group over the page instead of pushing it aside.
136+
<SecondaryNavigationContextProvider
137+
forceCollapsed={!hasSecondaryNavigation(activeRouteGroup)}
138+
>
145139
<PrimaryNavigationContext.Provider value={value}>
146140
{props.children}
147141
</PrimaryNavigationContext.Provider>

‎static/app/views/navigation/secondary/components.tsx‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,7 @@ import {
7070
type NavigationTourElementProps,
7171
} from 'sentry/views/navigation/navigationTour';
7272
import {isPrimaryNavigationLinkActive} from 'sentry/views/navigation/primary/components';
73-
import {
74-
useNavigationGroupHoverEnabled,
75-
usePrimaryNavigation,
76-
} from 'sentry/views/navigation/primaryNavigationContext';
73+
import {usePrimaryNavigation} from 'sentry/views/navigation/primaryNavigationContext';
7774
import {useSecondaryNavigation} from 'sentry/views/navigation/secondaryNavigationContext';
7875
import {useSettingsNavigation} from 'sentry/views/navigation/useSettingsNavigation';
7976
import {useSettingsV3} from 'sentry/views/settings/useSettingsV3';
@@ -123,8 +120,6 @@ function SecondarySidebarPanel({
123120
const containerRef = useObjectRef(tourRef);
124121
const resizeHandleRef = useRef<HTMLDivElement>(null);
125122
const {layout, activeGroup} = usePrimaryNavigation();
126-
// Group switches only animate to smooth over hover previews.
127-
const shouldAnimateGroupSwitch = useNavigationGroupHoverEnabled();
128123
const isSettingsNavigation = useSettingsNavigation();
129124

130125
const [secondarySidebarWidth, setSecondarySidebarWidth] = useSyncedLocalStorageState(
@@ -168,9 +163,9 @@ function SecondarySidebarPanel({
168163
width="100%"
169164
height="100%"
170165
key={activeGroup}
171-
initial={shouldAnimateGroupSwitch ? {x: -6, opacity: 0} : false}
166+
initial={{x: -6, opacity: 0}}
172167
animate={{x: 0, opacity: 1}}
173-
exit={shouldAnimateGroupSwitch ? {x: 6, opacity: 0} : undefined}
168+
exit={{x: 6, opacity: 0}}
174169
transition={{duration: 0.06}}
175170
>
176171
<Grid

‎static/app/views/navigation/secondaryNavigationContext.tsx‎

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ type SecondaryNavState = 'expanded' | 'collapsed' | 'peek';
1515

1616
interface SecondaryNavigationContext {
1717
/**
18-
* When false, the sidebar stays expanded and `setView` is a no-op.
18+
* When false, the page decides whether the sidebar is collapsed, so the user
19+
* cannot toggle it and their collapsed preference is left untouched.
1920
*/
2021
collapsible: boolean;
2122
setView: (view: SecondaryNavState) => void;
@@ -38,46 +39,75 @@ interface SecondaryNavigationContextProviderProps {
3839
children: React.ReactNode;
3940
}
4041

41-
export function SecondaryNavigationContextProvider(
42-
props: SecondaryNavigationContextProviderProps
43-
) {
42+
interface DesktopSecondaryNavigationContextProviderProps extends SecondaryNavigationContextProviderProps {
43+
/**
44+
* Keeps the sidebar collapsed, so it only shows as a peek over the page. Used
45+
* on pages without a secondary navigation of their own.
46+
*/
47+
forceCollapsed?: boolean;
48+
}
49+
50+
export function SecondaryNavigationContextProvider({
51+
children,
52+
forceCollapsed = false,
53+
}: DesktopSecondaryNavigationContextProviderProps) {
4454
const [isCollapsedPersisted, setIsCollapsedPersisted] = useLocalStorageState(
4555
NAVIGATION_SIDEBAR_COLLAPSED_LOCAL_STORAGE_KEY,
4656
false
4757
);
4858
const [view, setViewState] = useState<SecondaryNavState>(
4959
isCollapsedPersisted ? 'collapsed' : 'expanded'
5060
);
61+
// Peeks on a force-collapsed page are kept apart from `view`, so they never
62+
// overwrite the collapsed preference for the rest of the app.
63+
const [isForcedPeek, setIsForcedPeek] = useState(false);
5164
// Settings has too little in its sidebar to be worth hiding, so it ignores the
5265
// collapsed preference without overwriting it for the rest of the app.
53-
const collapsible = !useSettingsNavigation();
66+
const forceExpanded = useSettingsNavigation();
67+
const collapsible = !forceExpanded && !forceCollapsed;
5468

55-
// A peek that was open when the user entered settings must not reopen as an
56-
// unhovered peek once they leave.
69+
// A peek that was open when the user entered settings or a force-collapsed
70+
// page must not reopen as an unhovered peek once they leave.
5771
if (!collapsible && view === 'peek') {
5872
setViewState('collapsed');
5973
}
74+
if (!forceCollapsed && isForcedPeek) {
75+
setIsForcedPeek(false);
76+
}
6077

6178
const setView = useCallback(
6279
(nextView: SecondaryNavState) => {
63-
if (!collapsible) {
80+
if (forceExpanded) {
81+
return;
82+
}
83+
if (forceCollapsed) {
84+
setIsForcedPeek(nextView === 'peek');
6485
return;
6586
}
6687
setViewState(nextView);
6788
if (nextView !== 'peek') {
6889
setIsCollapsedPersisted(nextView === 'collapsed');
6990
}
7091
},
71-
[collapsible, setIsCollapsedPersisted]
92+
[forceExpanded, forceCollapsed, setIsCollapsedPersisted]
7293
);
7394

74-
const value = useMemo(() => {
75-
return {collapsible, view: collapsible ? view : 'expanded', setView};
76-
}, [collapsible, view, setView]);
95+
const currentView: SecondaryNavState = forceExpanded
96+
? 'expanded'
97+
: forceCollapsed
98+
? isForcedPeek
99+
? 'peek'
100+
: 'collapsed'
101+
: view;
102+
103+
const value = useMemo(
104+
() => ({collapsible, view: currentView, setView}),
105+
[collapsible, currentView, setView]
106+
);
77107

78108
return (
79109
<SecondaryNavigationContext.Provider value={value}>
80-
{props.children}
110+
{children}
81111
</SecondaryNavigationContext.Provider>
82112
);
83113
}

0 commit comments

Comments
 (0)