Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 25 additions & 14 deletions static/app/views/issueDetails/useGroupDetailsRoute.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import type {RouteComponentProps} from 'sentry/types/legacyReactRouter';
import type {PlainRoute} from 'sentry/types/legacyReactRouter';
import type {Organization} from 'sentry/types/organization';
import {normalizeUrl} from 'sentry/utils/url/normalizeUrl';
import {useOrganization} from 'sentry/utils/useOrganization';
import {useParams} from 'sentry/utils/useParams';
import {useRouter} from 'sentry/utils/useRouter';
import {useRoutes} from 'sentry/utils/useRoutes';
import {Tab, TabPaths} from 'sentry/views/issueDetails/types';

type RouteProps = RouteComponentProps<{groupId: string; eventId?: string}>;

function getCurrentTab({router}: {router: RouteProps['router']}) {
const currentRoute = router.routes[router.routes.length - 1];
function getCurrentTab({
routes,
params,
}: {
params: Record<string, string | undefined>;
routes: PlainRoute[];
}) {
const currentRoute = routes[routes.length - 1];

// If we're in the tag details page ("/distributions/:tagKey/")
if (router.params.tagKey) {
if (params.tagKey) {
return Tab.DISTRIBUTIONS;
}
return (
Expand All @@ -24,21 +28,23 @@ function getCurrentRouteInfo({
groupId,
eventId,
organization,
router,
routes,
params,
}: {
eventId: string | undefined;
groupId: string;
organization: Organization;
router: RouteProps['router'];
params: Record<string, string | undefined>;
routes: PlainRoute[];
}): {
baseUrl: string;
currentTab: Tab;
Comment on lines +37 to 41
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The getCurrentTab function always defaults to the 'Details' tab because route objects are missing the handle.path property, causing currentRoute.path to be an empty string.
Severity: HIGH

Suggested Fix

Update the route definitions for the issue detail tabs to include a handle object with a path property that mirrors the existing path value. For example, a route with path: TabPaths[Tab.ACTIVITY] should also have handle: { path: TabPaths[Tab.ACTIVITY] }. This will ensure useRoutes() correctly populates the path property on the route object, allowing getCurrentTab() to identify the active tab.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: static/app/views/issueDetails/useGroupDetailsRoute.tsx#L37-L41

Potential issue: The `useRoutes()` hook creates route objects where the `path` is
derived from `match.handle?.path ?? ''`. However, the route definitions for the issue
details tabs do not include a `handle` object with a `path` property. Consequently, when
`getCurrentTab()` runs, the `currentRoute.path` is always an empty string. The logic to
find the active tab, `Object.values(Tab).find(tab => currentRoute?.path ===
TabPaths[tab])`, will always fail to find a match, causing it to fall back to the
default `Tab.DETAILS`. This prevents the UI from correctly highlighting the active tab
on the issue details page.

Did we get this right? 👍 / 👎 to inform future reviews.

} {
const currentTab = getCurrentTab({router});
const currentTab = getCurrentTab({routes, params});

const baseUrl = normalizeUrl(
`/organizations/${organization.slug}/issues/${groupId}/${
router.params.eventId && eventId ? `events/${eventId}/` : ''
params.eventId && eventId ? `events/${eventId}/` : ''
}`
);

Expand All @@ -50,12 +56,17 @@ export function useGroupDetailsRoute(): {
currentTab: Tab;
} {
const organization = useOrganization();
const params = useParams<{groupId: string; eventId?: string}>();
const router = useRouter();
const params = useParams<{
groupId: string;
eventId?: string;
tagKey?: string;
}>();
const routes = useRoutes();
return getCurrentRouteInfo({
groupId: params.groupId,
eventId: params.eventId,
organization,
router,
routes,
params,
});
}
Loading