11import * as React from 'react' ;
2- import { useCallback , useState } from 'react' ;
2+ import { useCallback , useEffect , useState } from 'react' ;
33import styled from 'styled-components' ;
44import { VSCodeBadge , VSCodeCheckbox } from '@vscode/webview-ui-toolkit/react' ;
55import {
@@ -11,6 +11,7 @@ import { formatDecimal } from '../../pure/number';
1111import { Codicon , ErrorIcon , LoadingIcon , SuccessIcon , WarningIcon } from '../common' ;
1212import { Repository } from '../../remote-queries/shared/repository' ;
1313import { AnalysisAlert , AnalysisRawResults } from '../../remote-queries/shared/analysis-result' ;
14+ import { vscode } from '../vscode-api' ;
1415import { AnalyzedRepoItemContent } from './AnalyzedRepoItemContent' ;
1516
1617// This will ensure that these icons have a className which we can use in the TitleContainer
@@ -82,10 +83,32 @@ export const RepoRow = ({
8283 rawResults,
8384} : RepoRowProps ) => {
8485 const [ isExpanded , setExpanded ] = useState ( false ) ;
86+ const resultsLoaded = ! ! interpretedResults || ! ! rawResults ;
87+ const [ resultsLoading , setResultsLoading ] = useState ( false ) ;
8588
86- const toggleExpanded = useCallback ( ( ) => {
87- setExpanded ( oldIsExpanded => ! oldIsExpanded ) ;
88- } , [ ] ) ;
89+ const toggleExpanded = useCallback ( async ( ) => {
90+ if ( resultsLoading ) {
91+ return ;
92+ }
93+
94+ if ( resultsLoaded ) {
95+ setExpanded ( oldIsExpanded => ! oldIsExpanded ) ;
96+ return ;
97+ }
98+
99+ vscode . postMessage ( {
100+ t : 'requestRepositoryResults' ,
101+ repositoryFullName : repository . fullName ,
102+ } ) ;
103+
104+ setResultsLoading ( true ) ;
105+ } , [ resultsLoading , resultsLoaded , repository . fullName ] ) ;
106+
107+ useEffect ( ( ) => {
108+ if ( resultsLoaded ) {
109+ setResultsLoading ( false ) ;
110+ }
111+ } , [ resultsLoaded ] ) ;
89112
90113 const disabled = ! status || ! isCompletedAnalysisRepoStatus ( status ) ;
91114
@@ -107,7 +130,7 @@ export const RepoRow = ({
107130 </ span >
108131 { downloadStatus === VariantAnalysisScannedRepositoryDownloadStatus . InProgress && < LoadingIcon label = "Downloading" /> }
109132 </ TitleContainer >
110- { isExpanded && status &&
133+ { isExpanded && resultsLoaded && status &&
111134 < AnalyzedRepoItemContent status = { status } interpretedResults = { interpretedResults } rawResults = { rawResults } /> }
112135 </ div >
113136 ) ;
0 commit comments