@@ -15,7 +15,6 @@ import {
1515import { QueryHistoryConfig } from "../config" ;
1616import {
1717 showAndLogErrorMessage ,
18- showAndLogExceptionWithTelemetry ,
1918 showAndLogInformationMessage ,
2019 showAndLogWarningMessage ,
2120 showBinaryChoiceDialog ,
@@ -25,7 +24,7 @@ import { extLogger } from "../common";
2524import { URLSearchParams } from "url" ;
2625import { DisposableObject } from "../pure/disposable-object" ;
2726import { 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" ;
2928import { CompletedLocalQueryInfo , LocalQueryInfo } from "../query-results" ;
3029import {
3130 getActionsWorkflowRunUrl ,
@@ -54,7 +53,6 @@ import { VariantAnalysisManager } from "../variant-analysis/variant-analysis-man
5453import { VariantAnalysisHistoryItem } from "./variant-analysis-history-item" ;
5554import { getTotalResultCount } from "../variant-analysis/shared/variant-analysis" ;
5655import { HistoryTreeDataProvider } from "./history-tree-data-provider" ;
57- import { redactableError } from "../pure/errors" ;
5856import { QueryHistoryDirs } from "./query-history-dirs" ;
5957import { QueryHistoryCommands } from "../common/commands" ;
6058import { App } from "../common/app" ;
@@ -587,43 +585,46 @@ export class QueryHistoryManager extends DisposableObject {
587585 }
588586 }
589587
588+ isSuccessfulCompletedLocalQueryInfo (
589+ item : QueryHistoryInfo ,
590+ ) : item is CompletedLocalQueryInfo {
591+ return item . t === "local" && item . completedQuery ?. successful === true ;
592+ }
593+
590594 async handleCompareWith (
591595 singleItem : QueryHistoryInfo ,
592596 multiSelect : QueryHistoryInfo [ ] | undefined ,
593597 ) {
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 ] ;
604599
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+ }
610608
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 ;
613615
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 ) ;
620619 } 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 ) } ` ,
625622 ) ;
626623 }
624+
625+ if ( toItem !== undefined ) {
626+ await this . doCompareCallback ( fromItem , toItem ) ;
627+ }
627628 }
628629
629630 async handleItemClicked (
@@ -1177,57 +1178,40 @@ export class QueryHistoryManager extends DisposableObject {
11771178 }
11781179
11791180 private async findOtherQueryToCompare (
1180- singleItem : QueryHistoryInfo ,
1181- multiSelect : QueryHistoryInfo [ ] ,
1181+ fromItem : CompletedLocalQueryInfo ,
1182+ allItemsSelected : CompletedLocalQueryInfo [ ] ,
11821183 ) : 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 ;
11921185
11931186 // 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 ) {
12061193 throw new Error ( "Query databases must be the same." ) ;
12071194 }
1208- return otherQuery as CompletedLocalQueryInfo ;
1195+ return otherItem ;
12091196 }
12101197
1211- if ( multiSelect ? .length > 2 ) {
1198+ if ( allItemsSelected . length > 2 ) {
12121199 throw new Error ( "Please select no more than 2 queries." ) ;
12131200 }
12141201
12151202 // otherwise, let the user choose
12161203 const comparableQueryLabels = this . treeDataProvider . allHistory
1204+ . filter ( this . isSuccessfulCompletedLocalQueryInfo )
12171205 . 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 ,
12241209 )
12251210 . map ( ( item ) => ( {
12261211 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 ,
12311215 } ) ) ;
12321216 if ( comparableQueryLabels . length < 1 ) {
12331217 throw new Error ( "No other queries available to compare with." ) ;
0 commit comments