-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
feat(repos): Add installation settings button and drawer in repos v2 #114792
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
evanpurkhiser
merged 1 commit into
master
from
evanpurkhiser/feat-repos-add-installation-settings-button-and-drawer-in-repos-v2
May 5, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
142 changes: 142 additions & 0 deletions
142
static/app/views/settings/organizationRepositoriesV2/useInstallationSettings.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| import {Fragment} from 'react'; | ||
| import {mutationOptions, useQueries, useQueryClient} from '@tanstack/react-query'; | ||
|
|
||
| import {Alert} from '@sentry/scraps/alert'; | ||
| import {DrawerBody, DrawerHeader, useDrawer} from '@sentry/scraps/drawer'; | ||
| import {Container, Flex, Stack} from '@sentry/scraps/layout'; | ||
|
|
||
| import {BackendJsonAutoSaveForm} from 'sentry/components/backendJsonFormAdapter/backendJsonAutoSaveForm'; | ||
| import type {FieldValue} from 'sentry/components/backendJsonFormAdapter/types'; | ||
| import {t} from 'sentry/locale'; | ||
| import type {OrganizationIntegration} from 'sentry/types/integrations'; | ||
| import {apiOptions} from 'sentry/utils/api/apiOptions'; | ||
| import {getApiUrl} from 'sentry/utils/api/getApiUrl'; | ||
| import {getIntegrationIcon} from 'sentry/utils/integrationUtil'; | ||
| import {fetchMutation} from 'sentry/utils/queryClient'; | ||
| import {useOrganization} from 'sentry/utils/useOrganization'; | ||
|
|
||
| const NO_ACCESS_REASON = t( | ||
| 'You must be an organization owner, manager, or admin to change these settings.' | ||
| ); | ||
|
|
||
| interface UseInstallationSettingsOptions { | ||
| hasAccess: boolean; | ||
| scmIntegrations: OrganizationIntegration[]; | ||
| } | ||
|
|
||
| interface UseInstallationSettingsResult { | ||
| /** | ||
| * Full integration config keyed by integration ID, populated once each | ||
| * per-integration config query resolves. Values are `undefined` while | ||
| * their query is still in-flight. | ||
| */ | ||
| configByIntegrationId: Record<string, OrganizationIntegration | undefined>; | ||
| /** | ||
| * Opens a settings drawer for the given integration, rendering each | ||
| * `configOrganization` field as an auto-saving form. Fields are disabled | ||
| * with a permission tooltip when `hasAccess` is false. | ||
| */ | ||
| openInstallationSettings: (integration: OrganizationIntegration) => void; | ||
| } | ||
|
|
||
| export function useInstallationSettings({ | ||
| scmIntegrations, | ||
| hasAccess, | ||
| }: UseInstallationSettingsOptions): UseInstallationSettingsResult { | ||
| const organization = useOrganization(); | ||
| const {openDrawer} = useDrawer(); | ||
| const queryClient = useQueryClient(); | ||
|
|
||
| const configByIntegrationId = useQueries({ | ||
| queries: scmIntegrations.map(integration => | ||
| apiOptions.as<OrganizationIntegration>()( | ||
| '/organizations/$organizationIdOrSlug/integrations/$integrationId/', | ||
| { | ||
| path: { | ||
| organizationIdOrSlug: organization.slug, | ||
| integrationId: integration.id, | ||
| }, | ||
| staleTime: 60_000, | ||
| } | ||
| ) | ||
| ), | ||
| combine: results => | ||
| Object.fromEntries( | ||
| scmIntegrations.map((integration, i) => [integration.id, results[i]?.data]) | ||
| ), | ||
| }); | ||
|
|
||
| const openInstallationSettings = (integration: OrganizationIntegration) => { | ||
| const integrationOptions = apiOptions.as<OrganizationIntegration>()( | ||
| '/organizations/$organizationIdOrSlug/integrations/$integrationId/', | ||
| { | ||
| path: {organizationIdOrSlug: organization.slug, integrationId: integration.id}, | ||
| staleTime: 60_000, | ||
| } | ||
| ); | ||
| const integrationEndpoint = getApiUrl( | ||
| '/organizations/$organizationIdOrSlug/integrations/$integrationId/', | ||
| {path: {organizationIdOrSlug: organization.slug, integrationId: integration.id}} | ||
| ); | ||
| const integrationMutationOptions = mutationOptions({ | ||
| mutationFn: (data: Record<string, unknown>) => | ||
| fetchMutation({method: 'POST', url: integrationEndpoint, data}), | ||
| onSuccess: () => | ||
| queryClient.invalidateQueries({queryKey: integrationOptions.queryKey}), | ||
| }); | ||
|
|
||
| const resolvedIntegration = configByIntegrationId[integration.id] ?? integration; | ||
| const fields = hasAccess | ||
| ? (resolvedIntegration.configOrganization ?? []) | ||
| : (resolvedIntegration.configOrganization?.map(f => ({ | ||
| ...f, | ||
| disabled: true, | ||
| disabledReason: NO_ACCESS_REASON, | ||
|
Collaborator
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. I just double checked and I don’t think we map
Collaborator
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. |
||
| })) ?? []); | ||
|
|
||
| openDrawer( | ||
| () => ( | ||
| <Fragment> | ||
| <DrawerHeader> | ||
| <Flex align="center" gap="sm"> | ||
| {getIntegrationIcon(integration.provider.key, 'sm')} | ||
| {t('%s Settings', integration.name)} | ||
| </Flex> | ||
| </DrawerHeader> | ||
| <DrawerBody> | ||
| {!hasAccess && ( | ||
| <Alert.Container> | ||
| <Alert variant="warning">{NO_ACCESS_REASON}</Alert> | ||
| </Alert.Container> | ||
| )} | ||
| <Stack gap="0"> | ||
| {fields.map((fieldConfig, index) => ( | ||
| <Container | ||
| key={fieldConfig.name} | ||
| padding="xl 0" | ||
| borderBottom={index < fields.length - 1 ? 'secondary' : undefined} | ||
| > | ||
| <BackendJsonAutoSaveForm | ||
| field={fieldConfig} | ||
| initialValue={ | ||
| resolvedIntegration.configData?.[fieldConfig.name] as FieldValue< | ||
| typeof fieldConfig | ||
| > | ||
| } | ||
| mutationOptions={integrationMutationOptions} | ||
| /> | ||
| </Container> | ||
| ))} | ||
| </Stack> | ||
| </DrawerBody> | ||
| </Fragment> | ||
| ), | ||
| { | ||
| ariaLabel: t('Integration settings for %s', integration.name), | ||
| drawerKey: `integration-settings-${integration.id}`, | ||
| } | ||
| ); | ||
| }; | ||
|
|
||
| return {configByIntegrationId, openInstallationSettings}; | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Bug: If the API call to fetch an integration's configuration fails, the settings button becomes permanently disabled because
configByIntegrationId[integration.id]isundefined.Severity: MEDIUM
Suggested Fix
The UI should differentiate between a loading state and an error state. Instead of just checking if
configByIntegrationId[integration.id]isundefined, check the status of the corresponding query. If there's an error, display an error message to the user and potentially allow them to retry the action, rather than permanently disabling the button.Prompt for AI Agent
Did we get this right? 👍 / 👎 to inform future reviews.