Skip to content

Commit 5d4ed06

Browse files
authored
feat(discover): Open in discover from issues page doesn't apply sort (#95679)
When on an issue and the user clicks "View More Events", they're presented with an "Open in Discover" button. That button currently doesn't persist the sort param, so I've added it in this PR. If there is a query param that overrides the default sort, use that. Otherwise, use `-timestamp` which is what the default sort is for the issue events.
1 parent 89af26d commit 5d4ed06

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

static/app/views/issueDetails/streamline/eventNavigation.spec.tsx

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,53 @@ describe('EventNavigation', () => {
9292
expect.stringContaining(`/organizations/${organization.slug}/issues/${group.id}/`)
9393
);
9494
});
95+
96+
it('supplies the default timestamp sort when no sort is set in the query params', () => {
97+
const allEventsRouter = RouterFixture({
98+
params: {groupId: group.id},
99+
routes: [{path: TabPaths[Tab.EVENTS]}],
100+
location: LocationFixture({
101+
pathname: `/organizations/${organization.slug}/issues/${group.id}/events/`,
102+
}),
103+
});
104+
105+
render(<IssueEventNavigation {...defaultProps} />, {
106+
router: allEventsRouter,
107+
deprecatedRouterMocks: true,
108+
});
109+
110+
const discoverButton = screen.getByLabelText('Open in Discover');
111+
expect(discoverButton).toBeInTheDocument();
112+
const url = new URL(
113+
discoverButton.getAttribute('href') ?? '',
114+
'https://www.example.com'
115+
);
116+
expect(url.searchParams.get('sort')).toBe('-timestamp');
117+
});
118+
119+
it('supplies the sort when it is set in the query params', () => {
120+
const allEventsRouter = RouterFixture({
121+
params: {groupId: group.id},
122+
routes: [{path: TabPaths[Tab.EVENTS]}],
123+
location: LocationFixture({
124+
pathname: `/organizations/${organization.slug}/issues/${group.id}/events/`,
125+
query: {sort: '-title'},
126+
}),
127+
});
128+
129+
render(<IssueEventNavigation {...defaultProps} />, {
130+
router: allEventsRouter,
131+
deprecatedRouterMocks: true,
132+
});
133+
134+
const discoverButton = screen.getByLabelText('Open in Discover');
135+
expect(discoverButton).toBeInTheDocument();
136+
const url = new URL(
137+
discoverButton.getAttribute('href') ?? '',
138+
'https://www.example.com'
139+
);
140+
expect(url.searchParams.get('sort')).toBe('-title');
141+
});
95142
});
96143

97144
describe('counts', () => {

static/app/views/issueDetails/streamline/eventNavigation.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,13 @@ export function IssueEventNavigation({event, group}: IssueEventNavigationProps)
271271
<ButtonBar>
272272
{issueTypeConfig.discover.enabled && currentTab === Tab.EVENTS && (
273273
<LinkButton
274-
to={discoverUrl}
274+
to={{
275+
pathname: discoverUrl.pathname,
276+
query: {
277+
...discoverUrl.query,
278+
sort: location.query.sort ?? '-timestamp',
279+
},
280+
}}
275281
aria-label={t('Open in Discover')}
276282
size="xs"
277283
icon={<IconTelescope />}

0 commit comments

Comments
 (0)