Skip to content

feat(ui): List available param keys in useParams #83428

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
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
36 changes: 35 additions & 1 deletion static/app/utils/useParams.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,41 @@ import {CUSTOMER_DOMAIN, USING_CUSTOMER_DOMAIN} from 'sentry/constants';

import {useTestRouteContext} from './useRouteContext';

export function useParams<P = Record<string, string>>(): P {
/**
* List of keys used in routes.tsx `/example/:paramKey/...`
*
* Prevents misspelling of param keys
*/
type ParamKeys =
| 'apiKey'
| 'dataExportId'
| 'eventId'
| 'groupId'
| 'id'
| 'installationId'
| 'integrationSlug'
| 'issueId'
| 'memberId'
| 'orgId'
| 'projectId'
| 'release'
| 'scrubbingId'
| 'searchId'
| 'sentryAppSlug'
| 'shareId'
| 'spanSlug'
| 'teamId'
| 'widgetIndex';

/**
* Get params from the current route. Param availability depends on the current route.
*
* @example
* ```tsx
* const params = useParams<{projectId: string}>();
* ```
*/
export function useParams<P = Partial<Record<ParamKeys, string | undefined>>>(): P {
// When running in test mode we still read from the legacy route context to
// keep test compatability while we fully migrate to react router 6
const testRouteContext = useTestRouteContext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function ContinuousProfileFlamegraph(): React.ReactElement {
<FlamegraphStateProvider initialState={initialFlamegraphPreferencesState}>
<ProfileGroupTypeProvider
input={profiles.type === 'resolved' ? profiles.data : null}
traceID={params.eventID!}
traceID={params.eventId!}
>
<FlamegraphThemeProvider>
<FlamegraphStateQueryParamSync />
Expand Down
2 changes: 1 addition & 1 deletion static/app/views/profiling/profileFlamechart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function ProfileFlamegraph(): React.ReactElement {
<FlamegraphStateProvider initialState={initialFlamegraphPreferencesState}>
<ProfileGroupTypeProvider
input={profiles.type === 'resolved' ? profiles.data : null}
traceID={params.eventID!}
traceID={params.eventId!}
>
<FlamegraphThemeProvider>
<FlamegraphStateQueryParamSync />
Expand Down
Loading