Skip to content

Commit 0c261fb

Browse files
authored
fix(custom-views): Replace hard coded pathname with useLocation (#76859)
This PR replaces any navigation that was done in custom views to use the location/pathname from `useLocation`, rather than just hard coding the same pathname every time (`organizations/<org-slug>/issues/`). There are routing improvements that need to be made (which were alluded to in [this PR](#76672 (comment))), but this seems to fix some compatibility issues with RR 6.
1 parent d3edb1c commit 0c261fb

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

static/app/views/issueList/customViewsHeader.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {t} from 'sentry/locale';
1010
import {space} from 'sentry/styles/space';
1111
import type {InjectedRouter} from 'sentry/types/legacyReactRouter';
1212
import type {Organization} from 'sentry/types/organization';
13+
import {useLocation} from 'sentry/utils/useLocation';
1314
import {useNavigate} from 'sentry/utils/useNavigate';
1415
import useProjects from 'sentry/utils/useProjects';
1516
import {
@@ -84,10 +85,11 @@ function CustomViewsIssueListHeaderTabsContent({
8485
router,
8586
views,
8687
}: CustomViewsIssueListHeaderTabsContentProps) {
87-
// Remove cursor and page when switching tabs
88+
// TODO(msun): Possible replace navigate with useSearchParams() in the future?
8889
const navigate = useNavigate();
90+
const location = useLocation();
8991

90-
// TODO: Replace this with useLocation
92+
// TODO(msun): Use the location from useLocation instead of props router in the future
9193
const {cursor: _cursor, page: _page, ...queryParams} = router?.location.query;
9294
const {query, sort, viewId} = queryParams;
9395

@@ -164,13 +166,13 @@ function CustomViewsIssueListHeaderTabsContent({
164166
// If no query, sort, or viewId is present, set the first tab as the selected tab, update query accordingly
165167
if (!query && !sort && !viewId) {
166168
navigate({
169+
...location,
167170
query: {
168171
...queryParams,
169172
query: draggableTabs[0].query,
170173
sort: draggableTabs[0].querySort,
171174
viewId: draggableTabs[0].id,
172175
},
173-
pathname: `/organizations/${organization.slug}/issues/`,
174176
});
175177
tabListState?.setSelectedKey(draggableTabs[0].key);
176178
return;
@@ -208,13 +210,13 @@ function CustomViewsIssueListHeaderTabsContent({
208210
}
209211
if (selectedTab && query === undefined) {
210212
navigate({
213+
...location,
211214
query: {
212215
...queryParams,
213216
query: selectedTab.query,
214217
sort: selectedTab.querySort,
215218
viewId: selectedTab.id,
216219
},
217-
pathname: `/organizations/${organization.slug}/issues/`,
218220
});
219221
tabListState?.setSelectedKey(selectedTab.key);
220222
return;
@@ -223,11 +225,11 @@ function CustomViewsIssueListHeaderTabsContent({
223225
// if a viewId does not exist, remove it from the query
224226
tabListState?.setSelectedKey('temporary-tab');
225227
navigate({
228+
...location,
226229
query: {
227230
...queryParams,
228231
viewId: undefined,
229232
},
230-
pathname: `/organizations/${organization.slug}/issues/`,
231233
});
232234
return;
233235
}
@@ -257,11 +259,11 @@ function CustomViewsIssueListHeaderTabsContent({
257259
}
258260
});
259261
navigate({
262+
...location,
260263
query: {
261264
...queryParams,
262265
viewId: tab.id,
263266
},
264-
pathname: `/organizations/${organization.slug}/issues/`,
265267
});
266268
}
267269
return tab;

static/app/views/issueList/groupSearchViewTabs/draggableTabBar.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {t} from 'sentry/locale';
1212
import type {InjectedRouter} from 'sentry/types/legacyReactRouter';
1313
import {defined} from 'sentry/utils';
1414
import normalizeUrl from 'sentry/utils/url/normalizeUrl';
15+
import {useLocation} from 'sentry/utils/useLocation';
1516
import {useNavigate} from 'sentry/utils/useNavigate';
1617
import {DraggableTabMenuButton} from 'sentry/views/issueList/groupSearchViewTabs/draggableTabMenuButton';
1718
import EditableTabTitle from 'sentry/views/issueList/groupSearchViewTabs/editableTabTitle';
@@ -104,6 +105,7 @@ export function DraggableTabBar({
104105
const [editingTabKey, setEditingTabKey] = useState<string | null>(null);
105106

106107
const navigate = useNavigate();
108+
const location = useLocation();
107109

108110
const {cursor: _cursor, page: _page, ...queryParams} = router?.location?.query ?? {};
109111

@@ -149,13 +151,13 @@ export function DraggableTabBar({
149151
})
150152
);
151153
navigate({
154+
...location,
152155
query: {
153156
...queryParams,
154157
query: originalTab.query,
155158
sort: originalTab.querySort,
156159
...(originalTab.id ? {viewId: originalTab.id} : {}),
157160
},
158-
pathname: `/organizations/${orgSlug}/issues/`,
159161
});
160162
onDiscard?.();
161163
}
@@ -188,11 +190,11 @@ export function DraggableTabBar({
188190
...tabs.slice(idx + 1),
189191
];
190192
navigate({
193+
...location,
191194
query: {
192195
...queryParams,
193196
viewId: tempId,
194197
},
195-
pathname: `/organizations/${orgSlug}/issues/`,
196198
});
197199
setTabs(newTabs);
198200
tabListState?.setSelectedKey(tempId);
@@ -251,11 +253,11 @@ export function DraggableTabBar({
251253
},
252254
];
253255
navigate({
256+
...location,
254257
query: {
255258
...queryParams,
256259
viewId: tempId,
257260
},
258-
pathname: `/organizations/${orgSlug}/issues/`,
259261
});
260262
setTabs(newTabs);
261263
tabListState?.setSelectedKey(tempId);

0 commit comments

Comments
 (0)