@@ -15,7 +15,6 @@ import {
15
15
import { QueryHistoryConfig } from "../config" ;
16
16
import {
17
17
showAndLogErrorMessage ,
18
- showAndLogExceptionWithTelemetry ,
19
18
showAndLogInformationMessage ,
20
19
showAndLogWarningMessage ,
21
20
showBinaryChoiceDialog ,
@@ -25,7 +24,7 @@ import { extLogger } from "../common";
25
24
import { URLSearchParams } from "url" ;
26
25
import { DisposableObject } from "../pure/disposable-object" ;
27
26
import { ONE_HOUR_IN_MS , TWO_HOURS_IN_MS } from "../pure/time" ;
28
- import { asError , assertNever , getErrorMessage } from "../pure/helpers-pure" ;
27
+ import { assertNever , getErrorMessage } from "../pure/helpers-pure" ;
29
28
import { CompletedLocalQueryInfo , LocalQueryInfo } from "../query-results" ;
30
29
import {
31
30
getActionsWorkflowRunUrl ,
@@ -54,7 +53,6 @@ import { VariantAnalysisManager } from "../variant-analysis/variant-analysis-man
54
53
import { VariantAnalysisHistoryItem } from "./variant-analysis-history-item" ;
55
54
import { getTotalResultCount } from "../variant-analysis/shared/variant-analysis" ;
56
55
import { HistoryTreeDataProvider } from "./history-tree-data-provider" ;
57
- import { redactableError } from "../pure/errors" ;
58
56
import { QueryHistoryDirs } from "./query-history-dirs" ;
59
57
import { QueryHistoryCommands } from "../common/commands" ;
60
58
import { App } from "../common/app" ;
@@ -573,40 +571,41 @@ export class QueryHistoryManager extends DisposableObject {
573
571
}
574
572
}
575
573
574
+ isSuccessfulCompletedLocalQueryInfo (
575
+ item : QueryHistoryInfo ,
576
+ ) : item is CompletedLocalQueryInfo {
577
+ return item . t === "local" && item . completedQuery ?. successful === true ;
578
+ }
579
+
576
580
async handleCompareWith (
577
581
singleItem : QueryHistoryInfo ,
578
582
multiSelect : QueryHistoryInfo [ ] | undefined ,
579
583
) {
580
584
multiSelect ||= [ singleItem ] ;
581
585
582
- try {
583
- // local queries only
584
- if ( singleItem ?. t !== "local" ) {
585
- throw new Error ( "Please select a local query." ) ;
586
- }
587
-
588
- if ( ! singleItem . completedQuery ?. successful ) {
589
- throw new Error (
590
- "Please select a query that has completed successfully." ,
591
- ) ;
592
- }
586
+ if (
587
+ ! this . isSuccessfulCompletedLocalQueryInfo ( singleItem ) ||
588
+ ! multiSelect . every ( this . isSuccessfulCompletedLocalQueryInfo )
589
+ ) {
590
+ throw new Error (
591
+ "Please only select local queries that have completed successfully." ,
592
+ ) ;
593
+ }
593
594
594
- const from = this . compareWithItem || singleItem ;
595
- const to = await this . findOtherQueryToCompare ( from , multiSelect ) ;
595
+ const fromItem = this . getFromQueryToCompare ( singleItem , multiSelect ) ;
596
596
597
- if ( from . completed && to ?. completed ) {
598
- await this . doCompareCallback (
599
- from as CompletedLocalQueryInfo ,
600
- to as CompletedLocalQueryInfo ,
601
- ) ;
602
- }
597
+ let toItem : CompletedLocalQueryInfo | undefined = undefined ;
598
+ try {
599
+ toItem = await this . findOtherQueryToCompare ( fromItem , multiSelect ) ;
603
600
} catch ( e ) {
604
- void showAndLogExceptionWithTelemetry (
605
- redactableError (
606
- asError ( e ) ,
607
- ) `Failed to compare queries: ${ getErrorMessage ( e ) } ` ,
601
+ void showAndLogErrorMessage (
602
+ `Failed to compare queries: ${ getErrorMessage ( e ) } ` ,
608
603
) ;
609
604
}
605
+
606
+ if ( toItem !== undefined ) {
607
+ await this . doCompareCallback ( fromItem , toItem ) ;
608
+ }
610
609
}
611
610
612
611
async handleItemClicked (
@@ -1066,58 +1065,56 @@ export class QueryHistoryManager extends DisposableObject {
1066
1065
}
1067
1066
}
1068
1067
1069
- private async findOtherQueryToCompare (
1070
- singleItem : QueryHistoryInfo ,
1071
- multiSelect : QueryHistoryInfo [ ] ,
1072
- ) : Promise < CompletedLocalQueryInfo | undefined > {
1073
- // Variant analyses cannot be compared
1068
+ private getFromQueryToCompare (
1069
+ singleItem : CompletedLocalQueryInfo ,
1070
+ multiSelect : CompletedLocalQueryInfo [ ] ,
1071
+ ) : CompletedLocalQueryInfo {
1074
1072
if (
1075
- singleItem . t !== "local" ||
1076
- multiSelect . some ( ( s ) => s . t !== "local" ) ||
1077
- ! singleItem . completedQuery
1073
+ this . compareWithItem &&
1074
+ this . isSuccessfulCompletedLocalQueryInfo ( this . compareWithItem ) &&
1075
+ multiSelect . includes ( this . compareWithItem )
1078
1076
) {
1079
- return undefined ;
1077
+ return this . compareWithItem ;
1078
+ } else {
1079
+ return singleItem ;
1080
1080
}
1081
- const dbName = singleItem . initialInfo . databaseInfo . name ;
1082
-
1083
- // if exactly 2 queries are selected, use those
1084
- if ( multiSelect ?. length === 2 ) {
1085
- // return the query that is not the first selected one
1086
- const otherQuery = (
1087
- singleItem === multiSelect [ 0 ] ? multiSelect [ 1 ] : multiSelect [ 0 ]
1088
- ) as LocalQueryInfo ;
1089
- if ( ! otherQuery . completedQuery ) {
1090
- throw new Error ( "Please select a completed query." ) ;
1091
- }
1092
- if ( ! otherQuery . completedQuery . successful ) {
1093
- throw new Error ( "Please select a successful query." ) ;
1094
- }
1095
- if ( otherQuery . initialInfo . databaseInfo . name !== dbName ) {
1081
+ }
1082
+
1083
+ private async findOtherQueryToCompare (
1084
+ fromItem : CompletedLocalQueryInfo ,
1085
+ allSelectedItems : CompletedLocalQueryInfo [ ] ,
1086
+ ) : Promise < CompletedLocalQueryInfo | undefined > {
1087
+ const dbName = fromItem . databaseName ;
1088
+
1089
+ // If exactly 2 items are selected, return the one that
1090
+ // isn't being used as the "from" item.
1091
+ if ( allSelectedItems . length === 2 ) {
1092
+ const otherItem =
1093
+ fromItem === allSelectedItems [ 0 ]
1094
+ ? allSelectedItems [ 1 ]
1095
+ : allSelectedItems [ 0 ] ;
1096
+ if ( otherItem . databaseName !== dbName ) {
1096
1097
throw new Error ( "Query databases must be the same." ) ;
1097
1098
}
1098
- return otherQuery as CompletedLocalQueryInfo ;
1099
+ return otherItem ;
1099
1100
}
1100
1101
1101
- if ( multiSelect ? .length > 2 ) {
1102
+ if ( allSelectedItems . length > 2 ) {
1102
1103
throw new Error ( "Please select no more than 2 queries." ) ;
1103
1104
}
1104
1105
1105
- // otherwise, let the user choose
1106
+ // Otherwise, present a dialog so the user can choose the item they want to use.
1106
1107
const comparableQueryLabels = this . treeDataProvider . allHistory
1108
+ . filter ( this . isSuccessfulCompletedLocalQueryInfo )
1107
1109
. filter (
1108
- ( otherQuery ) =>
1109
- otherQuery !== singleItem &&
1110
- otherQuery . t === "local" &&
1111
- otherQuery . completedQuery &&
1112
- otherQuery . completedQuery . successful &&
1113
- otherQuery . initialInfo . databaseInfo . name === dbName ,
1110
+ ( otherItem ) =>
1111
+ otherItem !== fromItem && otherItem . databaseName === dbName ,
1114
1112
)
1115
1113
. map ( ( item ) => ( {
1116
1114
label : this . labelProvider . getLabel ( item ) ,
1117
- description : ( item as CompletedLocalQueryInfo ) . initialInfo . databaseInfo
1118
- . name ,
1119
- detail : ( item as CompletedLocalQueryInfo ) . completedQuery . statusString ,
1120
- query : item as CompletedLocalQueryInfo ,
1115
+ description : item . databaseName ,
1116
+ detail : item . completedQuery . statusString ,
1117
+ query : item ,
1121
1118
} ) ) ;
1122
1119
if ( comparableQueryLabels . length < 1 ) {
1123
1120
throw new Error ( "No other queries available to compare with." ) ;
0 commit comments