@@ -608,23 +608,34 @@ export const ApplicationsTable: React.FC = () => {
608
608
609
609
const dropdownItems = [ ...importDropdownItems , ...applicationDropdownItems ] ;
610
610
611
- const isAnalyzingDisabled = ( ) => {
612
- if ( tasks . length === 0 ) {
611
+ /**
612
+ * Analysis on the selected applications should be allowed if:
613
+ * - At least 1 application is selected
614
+ * - No analysis is in-flight for the selected applications (only 1 analysis at a time)
615
+ */
616
+ const isAnalyzingAllowed = ( ) => {
617
+ if ( selectedRows . length === 0 ) {
613
618
return false ;
614
619
}
615
620
616
- const allowedStates = [ "Succeeded" , "Failed" , null , "" ] ;
617
-
618
- const candidateTasks = selectedRows . filter ( ( app ) => {
619
- const hasAllowedState = tasks . some (
620
- ( task ) =>
621
- task . application ?. id === app . id &&
622
- allowedStates . includes ( task . state || "" )
623
- ) ;
624
- return ! hasAllowedState ;
625
- } ) ;
621
+ if ( tasks . length === 0 ) {
622
+ return true ;
623
+ }
626
624
627
- return candidateTasks . length > 0 ;
625
+ const selectedAppIds = selectedRows . map ( ( { id } ) => id ) ;
626
+ const tasksForSelected = tasks . filter (
627
+ ( task ) =>
628
+ ( task . kind ?? task . addon ) === "analyzer" &&
629
+ selectedAppIds . includes ( task . application . id )
630
+ ) ;
631
+ const terminalStates = [ "Succeeded" , "Failed" , "Canceled" , "" ] ;
632
+
633
+ return (
634
+ tasksForSelected . length === 0 ||
635
+ tasksForSelected . every ( ( { state } ) =>
636
+ terminalStates . includes ( state ?? "" )
637
+ )
638
+ ) ;
628
639
} ;
629
640
630
641
const hasExistingAnalysis = selectedRows . some ( ( app ) =>
@@ -785,9 +796,7 @@ export const ApplicationsTable: React.FC = () => {
785
796
onClick = { ( ) => {
786
797
setAnalyzeModalOpen ( true ) ;
787
798
} }
788
- isDisabled = {
789
- selectedRows . length < 1 || isAnalyzingDisabled ( )
790
- }
799
+ isDisabled = { ! isAnalyzingAllowed ( ) }
791
800
>
792
801
{ t ( "actions.analyze" ) }
793
802
</ Button >
0 commit comments