@@ -788,6 +788,7 @@ const App = () => {
788788 setSelectedProject ( project ) ;
789789 setSelectedNodeId ( project . id ) ;
790790 setSelectedTargetKey ( null ) ;
791+ const freshResults : Record < string , TargetSummary > = { } ;
791792 await Promise . all (
792793 project . targets . map ( async ( node ) => {
793794 const cacheKey = `${ node . projectHash } /${ node . target } /${ node . targetHash } ` ;
@@ -801,14 +802,45 @@ const App = () => {
801802 return ;
802803 }
803804 const summary = ( await response . json ( ) ) as TargetSummary ;
804- setNodeResults ( ( prev ) => ( { ... prev , [ cacheKey ] : summary } ) ) ;
805+ freshResults [ cacheKey ] = summary ;
805806 } )
806807 ) ;
807- if ( project . targets . length > 0 ) {
808- const first = project . targets [ 0 ] ;
809- const cacheKey = `${ first . projectHash } /${ first . target } /${ first . targetHash } ` ;
810- await showTargetLog ( cacheKey , first ) ;
808+ if ( Object . keys ( freshResults ) . length > 0 ) {
809+ setNodeResults ( ( prev ) => ( { ...prev , ...freshResults } ) ) ;
811810 }
811+ if ( project . targets . length === 0 ) {
812+ return ;
813+ }
814+ const resultsLookup = { ...nodeResults , ...freshResults } ;
815+ const newestTarget = project . targets . reduce ( ( newest , candidate ) => {
816+ if ( ! newest ) {
817+ return candidate ;
818+ }
819+ const newestKey =
820+ `${ newest . projectHash } /${ newest . target } /${ newest . targetHash } ` ;
821+ const candidateKey =
822+ `${ candidate . projectHash } /${ candidate . target } /${ candidate . targetHash } ` ;
823+ const newestSummary = resultsLookup [ newestKey ] ;
824+ const candidateSummary = resultsLookup [ candidateKey ] ;
825+ const newestTime = newestSummary
826+ ? Date . parse ( newestSummary . startedAt || newestSummary . endedAt )
827+ : Number . NEGATIVE_INFINITY ;
828+ const candidateTime = candidateSummary
829+ ? Date . parse ( candidateSummary . startedAt || candidateSummary . endedAt )
830+ : Number . NEGATIVE_INFINITY ;
831+ if ( candidateTime === newestTime ) {
832+ return candidate . target . localeCompare ( newest . target ) > 0
833+ ? candidate
834+ : newest ;
835+ }
836+ return candidateTime > newestTime ? candidate : newest ;
837+ } , null as GraphNode | null ) ;
838+ if ( ! newestTarget ) {
839+ return ;
840+ }
841+ const newestKey =
842+ `${ newestTarget . projectHash } /${ newestTarget . target } /${ newestTarget . targetHash } ` ;
843+ await showTargetLog ( newestKey , newestTarget ) ;
812844 } ;
813845
814846 const loadTargetLog = async ( key : string , target : GraphNode ) => {
0 commit comments