Skip to content

Commit 335ee16

Browse files
fix(dashboards): Preserve page filters when navigating from prebuilt dashboard link (#113070)
Fixes DAIN-1445 - The link from a prebuilt dashboard banner to the saved dashboard was dropping project, environment, and date filter selections. - Uses `extractSelectionParameters` to carry the current page filter query params through to the dashboard link. - Also fixes the link path from `dashboards` to `dashboard` (singular) to match the correct route.
1 parent b4dbfb0 commit 335ee16

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import {OrganizationFixture} from 'sentry-fixture/organization';
2+
3+
import {render, screen} from 'sentry-test/reactTestingLibrary';
4+
5+
import {PrebuiltDashboardRenderer} from 'sentry/views/dashboards/prebuiltDashboardRenderer';
6+
import {PrebuiltDashboardId} from 'sentry/views/dashboards/utils/prebuiltConfigs';
7+
8+
jest.mock('sentry/views/dashboards/detail', () => ({
9+
DashboardDetailWithInjectedProps: () => <div data-test-id="dashboard-detail" />,
10+
}));
11+
12+
jest.mock('sentry/views/dashboards/utils/usePopulateLinkedDashboards', () => ({
13+
useGetPrebuiltDashboard: () => ({
14+
dashboard: {id: '42', widgets: []},
15+
isLoading: false,
16+
}),
17+
}));
18+
19+
describe('PrebuiltDashboardRenderer', () => {
20+
const organization = OrganizationFixture();
21+
22+
it('renders dashboard link with page filter query params from the URL', async () => {
23+
render(
24+
<PrebuiltDashboardRenderer prebuiltId={PrebuiltDashboardId.BACKEND_OVERVIEW} />,
25+
{
26+
organization,
27+
initialRouterConfig: {
28+
location: {
29+
pathname: '/insights/backend/',
30+
query: {
31+
project: '1',
32+
environment: 'production',
33+
statsPeriod: '7d',
34+
},
35+
},
36+
},
37+
}
38+
);
39+
40+
const link = await screen.findByRole('link', {
41+
name: 'View this page on Dashboards',
42+
});
43+
44+
expect(link).toHaveAttribute(
45+
'href',
46+
expect.stringContaining(`/organizations/${organization.slug}/dashboard/42/`)
47+
);
48+
expect(link).toHaveAttribute('href', expect.stringContaining('project=1'));
49+
expect(link).toHaveAttribute(
50+
'href',
51+
expect.stringContaining('environment=production')
52+
);
53+
expect(link).toHaveAttribute('href', expect.stringContaining('statsPeriod=7d'));
54+
});
55+
});

static/app/views/dashboards/prebuiltDashboardRenderer.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ import {Link} from '@sentry/scraps/link';
55

66
import {useDismissable} from 'sentry/components/banner';
77
import {LoadingContainer} from 'sentry/components/loading/loadingContainer';
8+
import {extractSelectionParameters} from 'sentry/components/pageFilters/parse';
89
import {usePageFilters} from 'sentry/components/pageFilters/usePageFilters';
910
import {IconClose} from 'sentry/icons';
1011
import {tct} from 'sentry/locale';
1112
import {useIsSentryEmployee} from 'sentry/utils/useIsSentryEmployee';
13+
import {useLocation} from 'sentry/utils/useLocation';
1214
import {useOrganization} from 'sentry/utils/useOrganization';
1315
import {DashboardDetailWithInjectedProps as DashboardDetail} from 'sentry/views/dashboards/detail';
1416
import {
@@ -33,6 +35,7 @@ export function PrebuiltDashboardRenderer({
3335
storageNamespace,
3436
}: PrebuiltDashboardRendererProps) {
3537
const organization = useOrganization();
38+
const location = useLocation();
3639
const prebuiltDashboard = PREBUILT_DASHBOARDS[prebuiltId];
3740
const {dashboard: populatedPrebuiltDashboard, isLoading} =
3841
useGetPrebuiltDashboard(prebuiltId);
@@ -100,7 +103,10 @@ export function PrebuiltDashboardRenderer({
100103
{
101104
link: (
102105
<Link
103-
to={`/organizations/${organization.slug}/dashboards/${dashboardId}/`}
106+
to={{
107+
pathname: `/organizations/${organization.slug}/dashboard/${dashboardId}/`,
108+
query: extractSelectionParameters(location.query),
109+
}}
104110
/>
105111
),
106112
}

0 commit comments

Comments
 (0)