1- import { useCallback , useEffect , useMemo , useState } from 'react' ;
1+ import { useCallback , useMemo , useState } from 'react' ;
22import { useTheme } from '@emotion/react' ;
33import styled from '@emotion/styled' ;
44import uniqBy from 'lodash/uniqBy' ;
@@ -13,7 +13,7 @@ import {Heading, Text} from 'sentry/components/core/text';
1313import { Tooltip } from 'sentry/components/core/tooltip' ;
1414import { IconSettings } from 'sentry/icons' ;
1515import { t , tct } from 'sentry/locale' ;
16- import type { OrganizationIntegration , Repository } from 'sentry/types/integrations' ;
16+ import type { OrganizationIntegration } from 'sentry/types/integrations' ;
1717import { useInfiniteRepositories } from 'sentry/views/prevent/preventAI/hooks/usePreventAIInfiniteRepositories' ;
1818import ManageReposPanel from 'sentry/views/prevent/preventAI/manageReposPanel' ;
1919import 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 />
0 commit comments