-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
feat(settings): Migrate configure integration from deprecatedRouteProps #103128
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,18 +23,22 @@ import type { | |
| OrganizationIntegration, | ||
| PluginWithProjectList, | ||
| } from 'sentry/types/integrations'; | ||
| import type {RouteComponentProps} from 'sentry/types/legacyReactRouter'; | ||
| import type {Organization} from 'sentry/types/organization'; | ||
| import {isActiveSuperuser} from 'sentry/utils/isActiveSuperuser'; | ||
| import {singleLineRenderer} from 'sentry/utils/marked/marked'; | ||
| import type {ApiQueryKey} from 'sentry/utils/queryClient'; | ||
| import {setApiQueryData, useApiQuery, useQueryClient} from 'sentry/utils/queryClient'; | ||
| import {decodeScalar} from 'sentry/utils/queryString'; | ||
| import useRouteAnalyticsEventNames from 'sentry/utils/routeAnalytics/useRouteAnalyticsEventNames'; | ||
| import useRouteAnalyticsParams from 'sentry/utils/routeAnalytics/useRouteAnalyticsParams'; | ||
| import normalizeUrl from 'sentry/utils/url/normalizeUrl'; | ||
| import useApi from 'sentry/utils/useApi'; | ||
| import {useLocation} from 'sentry/utils/useLocation'; | ||
| import {useNavigate} from 'sentry/utils/useNavigate'; | ||
| import useOrganization from 'sentry/utils/useOrganization'; | ||
| import {useParams} from 'sentry/utils/useParams'; | ||
| import useProjects from 'sentry/utils/useProjects'; | ||
| import {useRoutes} from 'sentry/utils/useRoutes'; | ||
| import BreadcrumbTitle from 'sentry/views/settings/components/settingsBreadcrumb/breadcrumbTitle'; | ||
| import SettingsPageHeader from 'sentry/views/settings/components/settingsPageHeader'; | ||
|
|
||
|
|
@@ -48,11 +52,6 @@ import IntegrationMainSettings from './integrationMainSettings'; | |
| import IntegrationRepos from './integrationRepos'; | ||
| import {IntegrationServerlessFunctions} from './integrationServerlessFunctions'; | ||
|
|
||
| type Props = RouteComponentProps<{ | ||
| integrationId: string; | ||
| providerKey: string; | ||
| }>; | ||
|
|
||
| const TABS = [ | ||
| 'repos', | ||
| 'codeMappings', | ||
|
|
@@ -73,12 +72,19 @@ const makePluginQuery = (organization: Organization): ApiQueryKey => { | |
| return [`/organizations/${organization.slug}/plugins/configs/`]; | ||
| }; | ||
|
|
||
| function ConfigureIntegration({params, router, routes, location}: Props) { | ||
| function ConfigureIntegration() { | ||
| const routes = useRoutes(); | ||
| const location = useLocation(); | ||
| const navigate = useNavigate(); | ||
| const api = useApi(); | ||
| const queryClient = useQueryClient(); | ||
| const organization = useOrganization(); | ||
| const tab: Tab = TABS.includes(location.query.tab) ? location.query.tab : 'repos'; | ||
| const {integrationId, providerKey} = params; | ||
| const tabParam = decodeScalar(location.query.tab) as Tab | undefined; | ||
| const tab: Tab = tabParam && TABS.includes(tabParam) ? tabParam : 'repos'; | ||
| const {integrationId, providerKey} = useParams<{ | ||
| integrationId: string; | ||
| providerKey: string; | ||
| }>(); | ||
| const { | ||
| data: config = {providers: []}, | ||
| isPending: isLoadingConfig, | ||
|
|
@@ -133,13 +139,13 @@ function ConfigureIntegration({params, router, routes, location}: Props) { | |
| !organization.access.includes('org:integrations') && | ||
| !isActiveSuperuser() | ||
| ) { | ||
| router.push( | ||
| navigate( | ||
| normalizeUrl({ | ||
| pathname: `/settings/${organization.slug}/integrations/${providerKey}/`, | ||
| }) | ||
| ); | ||
| } | ||
| }, [router, organization, providerKey]); | ||
| }, [navigate, organization, providerKey]); | ||
|
|
||
|
Comment on lines
145
to
149
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The component now uses 🤖 Prompt for AI Agent Did we get this right? 👍 / 👎 to inform future reviews. Reference_id: 2624811 |
||
| if (isLoadingConfig || isLoadingIntegration || isLoadingPlugins) { | ||
| return <LoadingIndicator />; | ||
|
|
@@ -156,7 +162,7 @@ function ConfigureIntegration({params, router, routes, location}: Props) { | |
| const onTabChange = (value: Tab) => { | ||
| // XXX: Omit the cursor to prevent paginating the next tab's queries. | ||
| const {cursor: _, ...query} = location.query; | ||
| router.push({ | ||
| navigate({ | ||
| pathname: location.pathname, | ||
| query: {...query, tab: value}, | ||
| }); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
location.query.tabis being read and type-cast toTab | undefined. However, after the cast, it's being validated againstTABS.includes(tabParam). Consider using proper type narrowing to avoid potential issues. Currently, ifdecodeScalarreturnsundefined, the condition will short-circuit correctly, but making this more explicit would improve code clarity.Severity: MEDIUM
💡 Suggested Fix
Did we get this right? 👍 / 👎 to inform future reviews.
Reference_id: 2624811