@@ -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" ;
@@ -587,43 +585,46 @@ export class QueryHistoryManager extends DisposableObject {
587
585
}
588
586
}
589
587
588
+ isSuccessfulCompletedLocalQueryInfo (
589
+ item : QueryHistoryInfo ,
590
+ ) : item is CompletedLocalQueryInfo {
591
+ return item . t === "local" && item . completedQuery ?. successful === true ;
592
+ }
593
+
590
594
async handleCompareWith (
591
595
singleItem : QueryHistoryInfo ,
592
596
multiSelect : QueryHistoryInfo [ ] | undefined ,
593
597
) {
594
- const { finalSingleItem, finalMultiSelect } = this . determineSelection (
595
- singleItem ,
596
- multiSelect ,
597
- ) ;
598
-
599
- try {
600
- // local queries only
601
- if ( finalSingleItem ?. t !== "local" ) {
602
- throw new Error ( "Please select a local query." ) ;
603
- }
598
+ multiSelect ||= [ singleItem ] ;
604
599
605
- if ( ! finalSingleItem . completedQuery ?. successful ) {
606
- throw new Error (
607
- "Please select a query that has completed successfully." ,
608
- ) ;
609
- }
600
+ if (
601
+ ! this . isSuccessfulCompletedLocalQueryInfo ( singleItem ) ||
602
+ ! multiSelect . every ( this . isSuccessfulCompletedLocalQueryInfo )
603
+ ) {
604
+ throw new Error (
605
+ "Please only select local queries that have completed successfully." ,
606
+ ) ;
607
+ }
610
608
611
- const from = this . compareWithItem || singleItem ;
612
- const to = await this . findOtherQueryToCompare ( from , finalMultiSelect ) ;
609
+ const fromItem =
610
+ this . compareWithItem &&
611
+ this . isSuccessfulCompletedLocalQueryInfo ( this . compareWithItem ) &&
612
+ multiSelect . includes ( this . compareWithItem )
613
+ ? this . compareWithItem
614
+ : singleItem ;
613
615
614
- if ( from . completed && to ?. completed ) {
615
- await this . doCompareCallback (
616
- from as CompletedLocalQueryInfo ,
617
- to as CompletedLocalQueryInfo ,
618
- ) ;
619
- }
616
+ let toItem : CompletedLocalQueryInfo | undefined = undefined ;
617
+ try {
618
+ toItem = await this . findOtherQueryToCompare ( fromItem , multiSelect ) ;
620
619
} catch ( e ) {
621
- void showAndLogExceptionWithTelemetry (
622
- redactableError (
623
- asError ( e ) ,
624
- ) `Failed to compare queries: ${ getErrorMessage ( e ) } ` ,
620
+ void showAndLogErrorMessage (
621
+ `Failed to compare queries: ${ getErrorMessage ( e ) } ` ,
625
622
) ;
626
623
}
624
+
625
+ if ( toItem !== undefined ) {
626
+ await this . doCompareCallback ( fromItem , toItem ) ;
627
+ }
627
628
}
628
629
629
630
async handleItemClicked (
@@ -1177,57 +1178,40 @@ export class QueryHistoryManager extends DisposableObject {
1177
1178
}
1178
1179
1179
1180
private async findOtherQueryToCompare (
1180
- singleItem : QueryHistoryInfo ,
1181
- multiSelect : QueryHistoryInfo [ ] ,
1181
+ fromItem : CompletedLocalQueryInfo ,
1182
+ allItemsSelected : CompletedLocalQueryInfo [ ] ,
1182
1183
) : Promise < CompletedLocalQueryInfo | undefined > {
1183
- // Variant analyses cannot be compared
1184
- if (
1185
- singleItem . t !== "local" ||
1186
- multiSelect . some ( ( s ) => s . t !== "local" ) ||
1187
- ! singleItem . completedQuery
1188
- ) {
1189
- return undefined ;
1190
- }
1191
- const dbName = singleItem . initialInfo . databaseInfo . name ;
1184
+ const dbName = fromItem . initialInfo . databaseInfo . name ;
1192
1185
1193
1186
// if exactly 2 queries are selected, use those
1194
- if ( multiSelect ?. length === 2 ) {
1195
- // return the query that is not the first selected one
1196
- const otherQuery = (
1197
- singleItem === multiSelect [ 0 ] ? multiSelect [ 1 ] : multiSelect [ 0 ]
1198
- ) as LocalQueryInfo ;
1199
- if ( ! otherQuery . completedQuery ) {
1200
- throw new Error ( "Please select a completed query." ) ;
1201
- }
1202
- if ( ! otherQuery . completedQuery . successful ) {
1203
- throw new Error ( "Please select a successful query." ) ;
1204
- }
1205
- if ( otherQuery . initialInfo . databaseInfo . name !== dbName ) {
1187
+ if ( allItemsSelected . length === 2 ) {
1188
+ const otherItem =
1189
+ fromItem === allItemsSelected [ 0 ]
1190
+ ? allItemsSelected [ 1 ]
1191
+ : allItemsSelected [ 0 ] ;
1192
+ if ( otherItem . initialInfo . databaseInfo . name !== dbName ) {
1206
1193
throw new Error ( "Query databases must be the same." ) ;
1207
1194
}
1208
- return otherQuery as CompletedLocalQueryInfo ;
1195
+ return otherItem ;
1209
1196
}
1210
1197
1211
- if ( multiSelect ? .length > 2 ) {
1198
+ if ( allItemsSelected . length > 2 ) {
1212
1199
throw new Error ( "Please select no more than 2 queries." ) ;
1213
1200
}
1214
1201
1215
1202
// otherwise, let the user choose
1216
1203
const comparableQueryLabels = this . treeDataProvider . allHistory
1204
+ . filter ( this . isSuccessfulCompletedLocalQueryInfo )
1217
1205
. filter (
1218
- ( otherQuery ) =>
1219
- otherQuery !== singleItem &&
1220
- otherQuery . t === "local" &&
1221
- otherQuery . completedQuery &&
1222
- otherQuery . completedQuery . successful &&
1223
- otherQuery . initialInfo . databaseInfo . name === dbName ,
1206
+ ( otherItem ) =>
1207
+ otherItem !== fromItem &&
1208
+ otherItem . initialInfo . databaseInfo . name === dbName ,
1224
1209
)
1225
1210
. map ( ( item ) => ( {
1226
1211
label : this . labelProvider . getLabel ( item ) ,
1227
- description : ( item as CompletedLocalQueryInfo ) . initialInfo . databaseInfo
1228
- . name ,
1229
- detail : ( item as CompletedLocalQueryInfo ) . completedQuery . statusString ,
1230
- query : item as CompletedLocalQueryInfo ,
1212
+ description : item . initialInfo . databaseInfo . name ,
1213
+ detail : item . completedQuery . statusString ,
1214
+ query : item ,
1231
1215
} ) ) ;
1232
1216
if ( comparableQueryLabels . length < 1 ) {
1233
1217
throw new Error ( "No other queries available to compare with." ) ;
0 commit comments