Skip to content

Commit 50d2e99

Browse files
authored
fix(dashboards): Add All Metrics fails to add on first attempt (#106371)
The `navigate` call here was triggering a failed attempt to Add to Dashboard for adding All Metrics. The reason why it does this is because the route components are lazily loaded. When the first view occurs, it lazily loads the component. When the navigate is called, it goes down a different code path which seems to remount the component. Getting rid of the navigate call fixes this issue and `location.state` isn't preserved through navigations so there isn't a need to reset the state.
1 parent ece19fa commit 50d2e99

File tree

2 files changed

+2
-15
lines changed

2 files changed

+2
-15
lines changed

static/app/views/dashboards/create.spec.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {OrganizationFixture} from 'sentry-fixture/organization';
22
import {ProjectFixture} from 'sentry-fixture/project';
33
import {WidgetFixture} from 'sentry-fixture/widget';
44

5-
import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';
5+
import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
66

77
import PageFiltersStore from 'sentry/stores/pageFiltersStore';
88
import ProjectsStore from 'sentry/stores/projectsStore';
@@ -128,10 +128,6 @@ describe('Dashboards > CreateDashboard', () => {
128128
// Wait for widgets to be rendered
129129
expect(await screen.findAllByTestId('sortable-widget')).toHaveLength(2);
130130

131-
// Verify location state is cleared after consuming widgets
132-
await waitFor(() => {
133-
expect(router.location.state).toEqual({});
134-
});
135131
expect(router.location.pathname).toBe('/organizations/org-slug/dashboards/new/');
136132

137133
// Click save to check that the widgets are passed to the API

static/app/views/dashboards/create.tsx

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import {useEffect, useState} from 'react';
1+
import {useState} from 'react';
22

33
import Feature from 'sentry/components/acl/feature';
44
import {Alert} from 'sentry/components/core/alert';
55
import ErrorBoundary from 'sentry/components/errorBoundary';
66
import * as Layout from 'sentry/components/layouts/thirds';
77
import {t} from 'sentry/locale';
88
import {useLocation} from 'sentry/utils/useLocation';
9-
import {useNavigate} from 'sentry/utils/useNavigate';
109
import useOrganization from 'sentry/utils/useOrganization';
1110
import {useParams} from 'sentry/utils/useParams';
1211

@@ -20,7 +19,6 @@ export default function CreateDashboard() {
2019
const organization = useOrganization();
2120
const {templateId} = useParams<{templateId: string}>();
2221
const location = useLocation();
23-
const navigate = useNavigate();
2422

2523
const template = templateId
2624
? getDashboardTemplates(organization).find(
@@ -45,13 +43,6 @@ export default function CreateDashboard() {
4543
return baseDashboard;
4644
});
4745

48-
// Clear location state after consuming it
49-
useEffect(() => {
50-
if (hasWidgetsToAdd) {
51-
navigate(location.pathname, {replace: true, state: {}});
52-
}
53-
}, [hasWidgetsToAdd, navigate, location.pathname]);
54-
5546
function renderDisabled() {
5647
return (
5748
<Layout.Page withPadding>

0 commit comments

Comments
 (0)