Skip to content

Commit 8945a59

Browse files
cleanup
1 parent 93a064a commit 8945a59

File tree

5 files changed

+18
-45
lines changed

5 files changed

+18
-45
lines changed

static/app/types/prevent.tsx

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,5 @@
1-
// Add any new providers here e.g., 'github' | 'bitbucket' | 'gitlab'
2-
export type PreventAIProvider = 'github';
3-
41
export type Sensitivity = 'low' | 'medium' | 'high' | 'critical';
52

6-
export interface PreventAIRepo {
7-
fullName: string;
8-
id: string;
9-
name: string;
10-
}
11-
12-
export interface PreventAIOrg {
13-
githubOrganizationId: string;
14-
name: string;
15-
provider: PreventAIProvider;
16-
repos: PreventAIRepo[];
17-
}
18-
193
interface PreventAIFeatureConfig {
204
enabled: boolean;
215
triggers: PreventAIFeatureTriggers;

static/app/views/prevent/preventAI/hooks/usePreventAIInfiniteRepositories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import useOrganization from 'sentry/utils/useOrganization';
1111

1212
type QueryKey = [url: string, endpointOptions: QueryKeyEndpointOptions];
1313

14-
export type UseInfiniteRepositoriesOptions = {
14+
type UseInfiniteRepositoriesOptions = {
1515
integrationId: string;
1616
searchTerm?: string;
1717
};

static/app/views/prevent/preventAI/manageRepos.tsx

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {useCallback, useEffect, useMemo, useState} from 'react';
1+
import {useCallback, useMemo, useState} from 'react';
22
import {useTheme} from '@emotion/react';
33
import styled from '@emotion/styled';
44
import uniqBy from 'lodash/uniqBy';
@@ -13,7 +13,7 @@ import {Heading, Text} from 'sentry/components/core/text';
1313
import {Tooltip} from 'sentry/components/core/tooltip';
1414
import {IconSettings} from 'sentry/icons';
1515
import {t, tct} from 'sentry/locale';
16-
import type {OrganizationIntegration, Repository} from 'sentry/types/integrations';
16+
import type {OrganizationIntegration} from 'sentry/types/integrations';
1717
import {useInfiniteRepositories} from 'sentry/views/prevent/preventAI/hooks/usePreventAIInfiniteRepositories';
1818
import ManageReposPanel from 'sentry/views/prevent/preventAI/manageReposPanel';
1919
import ManageReposToolbar, {
@@ -30,7 +30,6 @@ function ManageReposPage({integratedOrgs}: {integratedOrgs: OrganizationIntegrat
3030
() => integratedOrgs[0]?.id ?? ''
3131
);
3232
const [selectedRepoId, setSelectedRepoId] = useState<string>(() => ALL_REPOS_VALUE);
33-
const [selectedRepoData, setSelectedRepoData] = useState<Repository | null>(null);
3433

3534
const queryResult = useInfiniteRepositories({
3635
integrationId: selectedOrgId,
@@ -47,27 +46,23 @@ function ManageReposPage({integratedOrgs}: {integratedOrgs: OrganizationIntegrat
4746
return found ?? integratedOrgs[0];
4847
}, [integratedOrgs, selectedOrgId]);
4948

50-
// Update selectedRepoData when reposData changes and we have a selectedRepoId
51-
useEffect(() => {
49+
// If the selected repo is not present in the list of repos, use null (for "All Repos")
50+
const selectedRepo = useMemo(() => {
5251
if (selectedRepoId === ALL_REPOS_VALUE) {
53-
setSelectedRepoData(null);
54-
return;
52+
return null;
5553
}
5654
const found = reposData.find(repo => repo.id === selectedRepoId);
57-
if (found) {
58-
setSelectedRepoData(found);
59-
}
55+
return found ?? null;
6056
}, [reposData, selectedRepoId]);
6157

6258
// When the org changes, reset to "All Repos"
6359
const setSelectedOrgIdWithCascadeRepoId = useCallback((orgId: string) => {
6460
setSelectedOrgId(orgId);
6561
setSelectedRepoId(ALL_REPOS_VALUE);
66-
setSelectedRepoData(null);
6762
}, []);
6863

6964
const isOrgSelected = !!selectedOrg;
70-
const isRepoSelected = selectedRepoId === ALL_REPOS_VALUE || !!selectedRepoData;
65+
const isRepoSelected = selectedRepoId === ALL_REPOS_VALUE || !!selectedRepo;
7166

7267
return (
7368
<Flex direction="column" maxWidth="1000px" gap="xl">
@@ -76,7 +71,7 @@ function ManageReposPage({integratedOrgs}: {integratedOrgs: OrganizationIntegrat
7671
integratedOrgs={integratedOrgs}
7772
selectedOrg={selectedOrgId}
7873
selectedRepo={selectedRepoId}
79-
selectedRepoData={selectedRepoData}
74+
selectedRepoData={selectedRepo}
8075
onOrgChange={setSelectedOrgIdWithCascadeRepoId}
8176
onRepoChange={setSelectedRepoId}
8277
/>
@@ -146,13 +141,13 @@ function ManageReposPage({integratedOrgs}: {integratedOrgs: OrganizationIntegrat
146141
/>
147142
</Flex>
148143

149-
{selectedOrg && (selectedRepoId === ALL_REPOS_VALUE || selectedRepoData) && (
144+
{selectedOrg && (selectedRepoId === ALL_REPOS_VALUE || selectedRepo) && (
150145
<ManageReposPanel
151146
key={`${selectedOrgId || 'no-org'}-${selectedRepoId || 'no-repo'}`}
152147
collapsed={!isPanelOpen}
153148
onClose={() => setIsPanelOpen(false)}
154149
org={selectedOrg}
155-
repo={selectedRepoData}
150+
repo={selectedRepo}
156151
allRepos={reposData}
157152
isEditingOrgDefaults={selectedRepoId === ALL_REPOS_VALUE}
158153
/>

static/app/views/prevent/preventAI/manageReposToolbar.spec.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,7 @@ describe('ManageReposToolbar', () => {
108108
integratedOrgs: mockIntegratedOrgs,
109109
selectedOrg: '1',
110110
selectedRepo: '1',
111-
selectedRepoData: {
112-
id: mockRepositories[0]!.id,
113-
name: mockRepositories[0]!.name,
114-
},
111+
selectedRepoData: mockRepositories[0] ?? null,
115112
onOrgChange: jest.fn(),
116113
onRepoChange: jest.fn(),
117114
};
@@ -236,10 +233,7 @@ describe('ManageReposToolbar', () => {
236233
{...defaultProps}
237234
selectedOrg="2"
238235
selectedRepo="3"
239-
selectedRepoData={{
240-
id: mockOrg2Repositories[0]!.id,
241-
name: mockOrg2Repositories[0]!.name,
242-
}}
236+
selectedRepoData={mockOrg2Repositories[0] ?? null}
243237
/>,
244238
{
245239
organization: OrganizationFixture({slug: 'org-slug'}),

static/app/views/prevent/preventAI/manageReposToolbar.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {TriggerLabel} from 'sentry/components/core/compactSelect/control';
66
import PageFilterBar from 'sentry/components/organizations/pageFilterBar';
77
import {IconBuilding, IconRepository} from 'sentry/icons';
88
import {t} from 'sentry/locale';
9-
import type {OrganizationIntegration} from 'sentry/types/integrations';
9+
import type {OrganizationIntegration, Repository} from 'sentry/types/integrations';
1010
import {useDebouncedValue} from 'sentry/utils/useDebouncedValue';
1111
import {useInfiniteRepositories} from 'sentry/views/prevent/preventAI/hooks/usePreventAIInfiniteRepositories';
1212
import {getRepoNameWithoutOrg} from 'sentry/views/prevent/preventAI/utils';
@@ -26,7 +26,7 @@ function ManageReposToolbar({
2626
onRepoChange: (repoId: string) => void;
2727
selectedOrg: string;
2828
selectedRepo: string;
29-
selectedRepoData: {id: string; name: string} | null;
29+
selectedRepoData: Repository | null;
3030
}) {
3131
const [searchValue, setSearchValue] = useState<string | undefined>();
3232
const debouncedSearch = useDebouncedValue(searchValue, 300);
@@ -63,15 +63,15 @@ function ManageReposToolbar({
6363
scrollListenerIdRef.current += 1;
6464
const currentId = scrollListenerIdRef.current;
6565

66-
const attachListener = (attempts = 0) => {
67-
if (scrollListenerIdRef.current !== currentId || attempts > 10) return;
66+
const attachListener = () => {
67+
if (scrollListenerIdRef.current !== currentId) return;
6868
const dropdownLists = document.querySelectorAll('ul[role="listbox"]');
6969
const lastList = dropdownLists[dropdownLists.length - 1];
7070
if (lastList instanceof HTMLElement) {
7171
scrollParentRef.current = lastList;
7272
lastList.addEventListener('scroll', handleScroll, {passive: true});
7373
} else {
74-
setTimeout(() => attachListener(attempts + 1), 20);
74+
setTimeout(attachListener, 20);
7575
}
7676
};
7777
attachListener();

0 commit comments

Comments
 (0)