11import { Fragment , useCallback , useMemo , useRef , useState } from 'react' ;
2- import { css } from '@emotion/react' ;
32import styled from '@emotion/styled' ;
43import { useVirtualizer } from '@tanstack/react-virtual' ;
54import uniqBy from 'lodash/uniqBy' ;
65import { debounce , parseAsString , useQueryState } from 'nuqs' ;
76
8- import { Button } from '@sentry/scraps/button' ;
7+ import { LinkButton } from '@sentry/scraps/button' ;
98import { InputGroup } from '@sentry/scraps/input' ;
109import { Flex , Grid } from '@sentry/scraps/layout' ;
1110import { Text } from '@sentry/scraps/text' ;
1211
13- import { openModal } from 'sentry/actionCreators/modal' ;
1412import {
1513 isSeerSupportedProvider ,
1614 useSeerSupportedProviderIds ,
@@ -20,7 +18,7 @@ import {LoadingIndicator} from 'sentry/components/loadingIndicator';
2018import { Panel } from 'sentry/components/panels/panel' ;
2119import { useBulkUpdateRepositorySettings } from 'sentry/components/repositories/useBulkUpdateRepositorySettings' ;
2220import { getRepositoryWithSettingsQueryKey } from 'sentry/components/repositories/useRepositoryWithSettings' ;
23- import { IconAdd } from 'sentry/icons' ;
21+ import { IconOpen } from 'sentry/icons/iconOpen ' ;
2422import { IconSearch } from 'sentry/icons/iconSearch' ;
2523import { t , tct } from 'sentry/locale' ;
2624import type { RepositoryWithSettings } from 'sentry/types/integrations' ;
@@ -38,7 +36,7 @@ import {useOrganization} from 'sentry/utils/useOrganization';
3836import { SeerRepoTableHeader } from 'getsentry/views/seerAutomation/components/repoTable/seerRepoTableHeader' ;
3937import { SeerRepoTableRow } from 'getsentry/views/seerAutomation/components/repoTable/seerRepoTableRow' ;
4038
41- const GRID_COLUMNS = '40px 1fr 118px 150px' ;
39+ const GRID_COLUMNS = '40px 1fr 138px 150px' ;
4240const SELECTED_ROW_HEIGHT = 44 ;
4341const BOTTOM_PADDING = 24 ; // px gap between table bottom and viewport edge
4442const estimateSize = ( ) => 68 ;
@@ -76,27 +74,54 @@ export function SeerRepoTable() {
7674 repository . externalId &&
7775 isSeerSupportedProvider ( repository . provider , supportedProviderIds )
7876 )
79- . sort ( ( a , b ) => {
77+ . sort ( ( a , b ) : number => {
8078 if ( sort . field === 'name' ) {
8179 return sort . kind === 'asc'
8280 ? a . name . localeCompare ( b . name )
8381 : b . name . localeCompare ( a . name ) ;
8482 }
85- // TODO: if we can bulk-fetch all the preferences, then it'll be easier to sort by fixes, pr creation, and repos
86- // if (sort.field === 'fixes') {
87- // return a.slug.localeCompare(b.slug);
88- // }
89- // if (sort.field === 'pr_creation') {
90- // return a.platform.localeCompare(b.platform);
91- // }
92- // if (sort.field === 'repos') {
93- // return a.status.localeCompare(b.status);
94- // }
83+
84+ if ( sort . field === 'enabled' ) {
85+ if (
86+ ( a . settings ?. enabledCodeReview ?? false ) ===
87+ ( b . settings ?. enabledCodeReview ?? false )
88+ ) {
89+ return sort . kind === 'asc'
90+ ? a . name . localeCompare ( b . name )
91+ : b . name . localeCompare ( a . name ) ;
92+ }
93+ return sort . kind === 'asc'
94+ ? a . settings ?. enabledCodeReview
95+ ? - 1
96+ : 1
97+ : b . settings ?. enabledCodeReview
98+ ? - 1
99+ : 1 ;
100+ }
101+
102+ if ( sort . field === 'triggers' ) {
103+ if (
104+ a . settings ?. codeReviewTriggers ?. length ===
105+ b . settings ?. codeReviewTriggers ?. length
106+ ) {
107+ return sort . kind === 'asc'
108+ ? ( a . settings ?. codeReviewTriggers [ 0 ] ?. localeCompare (
109+ b . settings ?. codeReviewTriggers [ 0 ] ?? ''
110+ ) ?? 0 )
111+ : ( b . settings ?. codeReviewTriggers [ 0 ] ?. localeCompare (
112+ a . settings ?. codeReviewTriggers [ 0 ] ?? ''
113+ ) ?? 0 ) ;
114+ }
115+ return sort . kind === 'asc'
116+ ? ( a . settings ?. codeReviewTriggers ?. length ?? 0 ) -
117+ ( b . settings ?. codeReviewTriggers ?. length ?? 0 )
118+ : ( b . settings ?. codeReviewTriggers ?. length ?? 0 ) -
119+ ( a . settings ?. codeReviewTriggers ?. length ?? 0 ) ;
120+ }
95121 return 0 ;
96122 } ) ,
97123 } ) ;
98124
99- // Auto-fetch each page, one at a time
100125 useFetchAllPages ( { result} ) ;
101126
102127 const {
@@ -163,28 +188,14 @@ export function SeerRepoTable() {
163188
164189 { isFetchingNextPage ? < LoadingIndicator mini /> : null }
165190
166- < Button
191+ < LinkButton
167192 priority = "primary"
168- icon = { < IconAdd /> }
169- onClick = { async ( ) => {
170- const { ScmRepoTreeModal} =
171- await import ( 'sentry/components/repositories/scmRepoTreeModal' ) ;
172-
173- openModal (
174- deps => < ScmRepoTreeModal { ...deps } title = { t ( 'Add Repository' ) } /> ,
175- {
176- modalCss : css `
177- width : 700px ;
178- ` ,
179- onClose : ( ) => {
180- queryClient . invalidateQueries ( { queryKey : queryOptions . queryKey } ) ;
181- } ,
182- }
183- ) ;
184- } }
193+ size = "sm"
194+ to = { `/settings/${ organization . slug } /repos/` }
195+ icon = { < IconOpen /> }
185196 >
186- { t ( 'Add Repository ' ) }
187- </ Button >
197+ { t ( 'Manage Repositories ' ) }
198+ </ LinkButton >
188199 </ Grid >
189200 < ListItemCheckboxProvider
190201 hits = { repositories ?. length ?? 0 }
0 commit comments