11import * as React from 'react' ;
2- import { useCallback , useEffect , useState } from 'react' ;
2+ import { ChangeEvent , useCallback , useEffect , useState } from 'react' ;
33import styled from 'styled-components' ;
44import { VSCodeBadge , VSCodeCheckbox } from '@vscode/webview-ui-toolkit/react' ;
55import {
@@ -80,6 +80,9 @@ export type RepoRowProps = {
8080
8181 interpretedResults ?: AnalysisAlert [ ] ;
8282 rawResults ?: AnalysisRawResults ;
83+
84+ selected ?: boolean ;
85+ onSelectedChange ?: ( repositoryId : number , selected : boolean ) => void ;
8386}
8487
8588const canExpand = (
@@ -101,6 +104,11 @@ const canExpand = (
101104 return downloadStatus === VariantAnalysisScannedRepositoryDownloadStatus . Succeeded || downloadStatus === VariantAnalysisScannedRepositoryDownloadStatus . Failed ;
102105} ;
103106
107+ const canSelect = (
108+ status : VariantAnalysisRepoStatus | undefined ,
109+ downloadStatus : VariantAnalysisScannedRepositoryDownloadStatus | undefined ,
110+ ) => status == VariantAnalysisRepoStatus . Succeeded && downloadStatus === VariantAnalysisScannedRepositoryDownloadStatus . Succeeded ;
111+
104112const isExpandableContentLoaded = (
105113 status : VariantAnalysisRepoStatus | undefined ,
106114 downloadStatus : VariantAnalysisScannedRepositoryDownloadStatus | undefined ,
@@ -133,6 +141,8 @@ export const RepoRow = ({
133141 resultCount,
134142 interpretedResults,
135143 rawResults,
144+ selected,
145+ onSelectedChange,
136146} : RepoRowProps ) => {
137147 const [ isExpanded , setExpanded ] = useState ( false ) ;
138148 const resultsLoaded = ! ! interpretedResults || ! ! rawResults ;
@@ -163,13 +173,35 @@ export const RepoRow = ({
163173 }
164174 } , [ resultsLoaded , resultsLoading ] ) ;
165175
176+ const onClickCheckbox = useCallback ( ( e : React . MouseEvent ) => {
177+ // Prevent calling the onClick event of the container, which would toggle the expanded state
178+ e . stopPropagation ( ) ;
179+ } , [ ] ) ;
180+ const onChangeCheckbox = useCallback ( ( e : ChangeEvent < HTMLInputElement > ) => {
181+ // This is called on first render, but we don't really care about this value
182+ if ( e . target . checked === undefined ) {
183+ return ;
184+ }
185+
186+ if ( ! repository . id ) {
187+ return ;
188+ }
189+
190+ onSelectedChange ?.( repository . id , e . target . checked ) ;
191+ } , [ onSelectedChange , repository ] ) ;
192+
166193 const disabled = ! canExpand ( status , downloadStatus ) ;
167194 const expandableContentLoaded = isExpandableContentLoaded ( status , downloadStatus , resultsLoaded ) ;
168195
169196 return (
170197 < div >
171198 < TitleContainer onClick = { toggleExpanded } disabled = { disabled } aria-expanded = { isExpanded } >
172- < VSCodeCheckbox disabled />
199+ < VSCodeCheckbox
200+ onChange = { onChangeCheckbox }
201+ onClick = { onClickCheckbox }
202+ checked = { selected }
203+ disabled = { ! repository . id || ! canSelect ( status , downloadStatus ) }
204+ />
173205 { isExpanded ? < ExpandCollapseCodicon name = "chevron-down" label = "Collapse" /> :
174206 < ExpandCollapseCodicon name = "chevron-right" label = "Expand" /> }
175207 < VSCodeBadge > { resultCount === undefined ? '-' : formatDecimal ( resultCount ) } </ VSCodeBadge >
0 commit comments