Skip to content

Commit 701ad1e

Browse files
Fix Non-Admin Add GH Org button for org selector (#103127)
This PR refactors the recent change of updating the org selector's link button to match the integration settings page's GH app installation button (#102680). The most recent change used inner components of the IntegrationButton component in order to use the integration settings "Add installation" button and modified the styling to be the clear button designated in the Figma. However, for non-admins who did not have access, clicking on the button would just pop out the new window and redirect back to the prevent/tests page with a error toast (if they were already GH authenticated) since they wouldn't have proper permissions.
1 parent 0ee419a commit 701ad1e

File tree

4 files changed

+38
-22
lines changed

4 files changed

+38
-22
lines changed

static/app/components/prevent/integratedOrgSelector/integratedOrgSelector.tsx

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {useCallback, useMemo} from 'react';
22
import styled from '@emotion/styled';
33

4-
import {Button} from 'sentry/components/core/button';
4+
import Access from 'sentry/components/acl/access';
55
import {LinkButton} from 'sentry/components/core/button/linkButton';
66
import type {SelectOption} from 'sentry/components/core/compactSelect';
77
import {CompactSelect} from 'sentry/components/core/compactSelect';
@@ -14,19 +14,20 @@ import {usePreventContext} from 'sentry/components/prevent/context/preventContex
1414
import {integratedOrgIdToName} from 'sentry/components/prevent/utils';
1515
import {IconAdd, IconBuilding, IconInfo} from 'sentry/icons';
1616
import {t, tct} from 'sentry/locale';
17-
import type {IntegrationWithConfig} from 'sentry/types/integrations';
17+
import type {Integration} from 'sentry/types/integrations';
1818
import {useApiQuery} from 'sentry/utils/queryClient';
1919
import useOrganization from 'sentry/utils/useOrganization';
2020
import {useGetActiveIntegratedOrgs} from 'sentry/views/prevent/tests/queries/useGetActiveIntegratedOrgs';
21-
import AddIntegration from 'sentry/views/settings/organizationIntegrations/addIntegration';
21+
import IntegrationButton from 'sentry/views/settings/organizationIntegrations/integrationButton';
22+
import {IntegrationContext} from 'sentry/views/settings/organizationIntegrations/integrationContext';
2223
import type {IntegrationInformation} from 'sentry/views/settings/organizationIntegrations/integrationDetailedView';
2324

2425
const DEFAULT_ORG_LABEL = 'Select GitHub Org';
2526

2627
function OrgFooterMessage() {
2728
const organization = useOrganization();
2829

29-
const handleAddIntegration = useCallback((_integration: IntegrationWithConfig) => {
30+
const handleAddIntegration = useCallback((_integration: Integration) => {
3031
window.location.reload();
3132
}, []);
3233

@@ -46,7 +47,10 @@ function OrgFooterMessage() {
4647
}
4748
);
4849

50+
const {data: installedIntegrations = []} = useGetActiveIntegratedOrgs({organization});
51+
4952
const provider = integrationInfo?.providers[0];
53+
const hasInstalledIntegration = installedIntegrations.length > 0;
5054

5155
return (
5256
<Flex gap="sm" direction="column" align="start">
@@ -70,22 +74,31 @@ function OrgFooterMessage() {
7074
{isIntegrationInfoPending ? (
7175
<LoadingIndicator />
7276
) : provider ? (
73-
<AddIntegration
74-
provider={provider}
75-
onInstall={handleAddIntegration}
76-
organization={organization}
77+
<IntegrationContext
78+
value={{
79+
provider,
80+
type: 'first_party',
81+
installStatus: hasInstalledIntegration ? 'Installed' : 'Not Installed',
82+
analyticsParams: {
83+
view: 'test_analytics_org_selector',
84+
already_installed: hasInstalledIntegration,
85+
},
86+
}}
7787
>
78-
{openDialog => (
79-
<Button
80-
size="xs"
81-
icon={<IconAdd />}
82-
priority="default"
83-
onClick={() => openDialog()}
84-
>
85-
{t('GitHub Organization')}
86-
</Button>
87-
)}
88-
</AddIntegration>
88+
<Access access={['org:integrations']} organization={organization}>
89+
{({hasAccess}) => (
90+
<IntegrationButton
91+
userHasAccess={hasAccess}
92+
onAddIntegration={handleAddIntegration}
93+
onExternalClick={() => {}}
94+
buttonProps={{
95+
size: 'sm',
96+
priority: 'primary',
97+
}}
98+
/>
99+
)}
100+
</Access>
101+
</IntegrationContext>
89102
) : (
90103
<LinkButton
91104
href="https://github.com/apps/sentry/installations/select_target"

static/app/utils/analytics/integrations/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ export type IntegrationView = {
1919
| 'project_creation'
2020
| 'developer_settings'
2121
| 'new_integration_modal'
22-
| 'test_analytics_onboarding';
22+
| 'test_analytics_onboarding'
23+
| 'test_analytics_org_selector';
2324
};
2425

2526
type SingleIntegrationEventParams = {

static/app/views/settings/organizationIntegrations/addIntegration.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ type Props = {
2323
| 'integrations_directory'
2424
| 'onboarding'
2525
| 'project_creation'
26-
| 'test_analytics_onboarding';
26+
| 'test_analytics_onboarding'
27+
| 'test_analytics_org_selector';
2728
};
2829
modalParams?: Record<string, string>;
2930
};

static/app/views/settings/organizationIntegrations/integrationContext.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ type IntegrationContextProps = {
1212
| 'integrations_directory'
1313
| 'onboarding'
1414
| 'project_creation'
15-
| 'test_analytics_onboarding';
15+
| 'test_analytics_onboarding'
16+
| 'test_analytics_org_selector';
1617
referrer?: string;
1718
};
1819
installStatus: string;

0 commit comments

Comments
 (0)