Skip to content

Commit d50e281

Browse files
authored
fix(insights): sort not working http landing page (#89486)
This broke in #89325 We should be passing in `location.query.domainsSort` into decodeSorts and not the string `domainsSort`! Also added a test case to ensure sort always works off the query param
1 parent bb3992d commit d50e281

File tree

2 files changed

+65
-10
lines changed

2 files changed

+65
-10
lines changed

static/app/views/insights/http/views/httpLandingPage.spec.tsx

Lines changed: 62 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import ProjectsStore from 'sentry/stores/projectsStore';
77
import {useLocation} from 'sentry/utils/useLocation';
88
import usePageFilters from 'sentry/utils/usePageFilters';
99
import {useReleaseStats} from 'sentry/utils/useReleaseStats';
10+
import {QueryParameterNames} from 'sentry/views/insights/common/views/queryParameters';
1011
import {HTTPLandingPage} from 'sentry/views/insights/http/views/httpLandingPage';
1112

1213
jest.mock('sentry/utils/useLocation');
@@ -42,15 +43,7 @@ describe('HTTPLandingPage', function () {
4243
},
4344
});
4445

45-
jest.mocked(useLocation).mockReturnValue({
46-
pathname: '/insights/backend/http/',
47-
search: '',
48-
query: {statsPeriod: '10d', 'span.domain': 'git', project: '1'},
49-
hash: '',
50-
state: undefined,
51-
action: 'PUSH',
52-
key: '',
53-
});
46+
const useLocationMock = jest.mocked(useLocation);
5447

5548
jest.mocked(useReleaseStats).mockReturnValue({
5649
isLoading: false,
@@ -63,6 +56,16 @@ describe('HTTPLandingPage', function () {
6356
beforeEach(function () {
6457
jest.clearAllMocks();
6558

59+
useLocationMock.mockReturnValue({
60+
pathname: '/insights/backend/http/',
61+
search: '',
62+
query: {statsPeriod: '10d', 'span.domain': 'git', project: '1'},
63+
hash: '',
64+
state: undefined,
65+
action: 'PUSH',
66+
key: '',
67+
});
68+
6669
ProjectsStore.loadInitialData([
6770
ProjectFixture({
6871
id: '1',
@@ -433,4 +436,54 @@ describe('HTTPLandingPage', function () {
433436
expect(screen.getByRole('cell', {name: '333.54ms'})).toBeInTheDocument();
434437
expect(screen.getByRole('cell', {name: '1.35wk'})).toBeInTheDocument();
435438
});
439+
440+
it('sorts with query params', async function () {
441+
useLocationMock.mockReturnValue({
442+
pathname: '/insights/backend/http/',
443+
search: '',
444+
query: {
445+
statsPeriod: '10d',
446+
'span.domain': 'git',
447+
project: '1',
448+
[QueryParameterNames.DOMAINS_SORT]: '-avg(span.self_time)',
449+
},
450+
hash: '',
451+
state: undefined,
452+
action: 'PUSH',
453+
key: '',
454+
});
455+
456+
render(<HTTPLandingPage />, {organization});
457+
458+
await waitForElementToBeRemoved(() => screen.queryAllByTestId('loading-indicator'));
459+
460+
expect(spanListRequestMock).toHaveBeenCalledWith(
461+
`/organizations/${organization.slug}/events/`,
462+
expect.objectContaining({
463+
method: 'GET',
464+
query: {
465+
dataset: 'spansMetrics',
466+
environment: [],
467+
field: [
468+
'project',
469+
'project.id',
470+
'span.domain',
471+
'epm()',
472+
'http_response_rate(3)',
473+
'http_response_rate(4)',
474+
'http_response_rate(5)',
475+
'avg(span.self_time)',
476+
'sum(span.self_time)',
477+
'time_spent_percentage()',
478+
],
479+
per_page: 10,
480+
project: [],
481+
query: 'span.module:http span.op:http.client span.domain:*git*',
482+
referrer: 'api.performance.http.landing-domains-list',
483+
sort: '-avg(span.self_time)',
484+
statsPeriod: '10d',
485+
},
486+
})
487+
);
488+
});
436489
});

static/app/views/insights/http/views/httpLandingPage.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,10 @@ export function HTTPLandingPage() {
4949
[QueryParameterNames.DOMAINS_SORT]: decodeScalar,
5050
},
5151
});
52+
5253
const sort =
53-
decodeSorts(QueryParameterNames.DOMAINS_SORT).find(isAValidSort) ?? DEFAULT_SORT;
54+
decodeSorts(query?.[QueryParameterNames.DOMAINS_SORT]).find(isAValidSort) ??
55+
DEFAULT_SORT;
5456
const cursor = decodeScalar(location.query?.[QueryParameterNames.DOMAINS_CURSOR]);
5557

5658
const chartFilters = useHttpLandingChartFilter();

0 commit comments

Comments
 (0)