|
1 | 1 | import { assertNever } from "../../pure/helpers-pure"; |
2 | | -import { LocalQueryInfo, InitialQueryInfo } from "../../query-results"; |
| 2 | +import { |
| 3 | + LocalQueryInfo, |
| 4 | + InitialQueryInfo, |
| 5 | + CompletedQueryInfo, |
| 6 | +} from "../../query-results"; |
3 | 7 | import { QueryEvaluationInfo } from "../../run-queries-shared"; |
4 | 8 | import { QueryHistoryInfo } from "../query-history-info"; |
5 | 9 | import { |
6 | 10 | QueryHistoryLocalQueryDto, |
7 | 11 | InitialQueryInfoDto, |
8 | 12 | QueryEvaluationInfoDto, |
| 13 | + CompletedQueryInfoDto, |
| 14 | + SortedResultSetInfoDto, |
| 15 | + SortDirectionDto, |
9 | 16 | } from "./query-history-local-query-dto"; |
10 | 17 | import { QueryHistoryDataItem } from "./query-history-data"; |
11 | 18 | import { VariantAnalysisDataItem } from "./variant-analysis-data-item"; |
| 19 | +import { |
| 20 | + RawResultsSortState, |
| 21 | + SortDirection, |
| 22 | + SortedResultSetInfo, |
| 23 | +} from "../../pure/interface-types"; |
12 | 24 |
|
13 | 25 | // Maps Query History Domain Models to Data Models |
14 | 26 |
|
@@ -38,22 +50,65 @@ function mapLocalQueryInfoToDataModel( |
38 | 50 | jsonEvalLogSummaryLocation: query.jsonEvalLogSummaryLocation, |
39 | 51 | evalLogSummarySymbolsLocation: query.evalLogSummarySymbolsLocation, |
40 | 52 | failureReason: query.failureReason, |
41 | | - completedQuery: query.completedQuery && { |
42 | | - query: mapQueryEvaluationInfoToDataModel(query.completedQuery.query), |
43 | | - result: { |
44 | | - runId: query.completedQuery.result.runId, |
45 | | - queryId: query.completedQuery.result.queryId, |
46 | | - resultType: query.completedQuery.result.resultType, |
47 | | - evaluationTime: query.completedQuery.result.evaluationTime, |
48 | | - message: query.completedQuery.result.message, |
49 | | - logFileLocation: query.completedQuery.result.logFileLocation, |
50 | | - }, |
51 | | - logFileLocation: query.completedQuery.logFileLocation, |
52 | | - successful: query.completedQuery.successful, |
53 | | - message: query.completedQuery.message, |
54 | | - resultCount: query.completedQuery.resultCount, |
55 | | - sortedResultsInfo: query.completedQuery.sortedResultsInfo, |
| 53 | + completedQuery: |
| 54 | + query.completedQuery && |
| 55 | + mapCompletedQueryToDataModel(query.completedQuery), |
| 56 | + }; |
| 57 | +} |
| 58 | + |
| 59 | +function mapCompletedQueryToDataModel( |
| 60 | + query: CompletedQueryInfo, |
| 61 | +): CompletedQueryInfoDto { |
| 62 | + const sortedResults = Object.fromEntries( |
| 63 | + Object.entries(query.sortedResultsInfo).map(([key, value]) => { |
| 64 | + return [key, mapSortedResultSetInfoToDataModel(value)]; |
| 65 | + }), |
| 66 | + ); |
| 67 | + |
| 68 | + return { |
| 69 | + query: mapQueryEvaluationInfoToDataModel(query.query), |
| 70 | + result: { |
| 71 | + runId: query.result.runId, |
| 72 | + queryId: query.result.queryId, |
| 73 | + resultType: query.result.resultType, |
| 74 | + evaluationTime: query.result.evaluationTime, |
| 75 | + message: query.result.message, |
| 76 | + logFileLocation: query.result.logFileLocation, |
56 | 77 | }, |
| 78 | + logFileLocation: query.logFileLocation, |
| 79 | + successful: query.successful, |
| 80 | + message: query.message, |
| 81 | + resultCount: query.resultCount, |
| 82 | + sortedResultsInfo: sortedResults, |
| 83 | + }; |
| 84 | +} |
| 85 | + |
| 86 | +function mapSortDirectionToDomainModel( |
| 87 | + sortDirection: SortDirection, |
| 88 | +): SortDirectionDto { |
| 89 | + switch (sortDirection) { |
| 90 | + case SortDirection.asc: |
| 91 | + return SortDirectionDto.asc; |
| 92 | + case SortDirection.desc: |
| 93 | + return SortDirectionDto.desc; |
| 94 | + } |
| 95 | +} |
| 96 | + |
| 97 | +function mapRawResultsSortStateToDataModel( |
| 98 | + sortState: RawResultsSortState, |
| 99 | +): SortedResultSetInfoDto["sortState"] { |
| 100 | + return { |
| 101 | + columnIndex: sortState.columnIndex, |
| 102 | + sortDirection: mapSortDirectionToDomainModel(sortState.sortDirection), |
| 103 | + }; |
| 104 | +} |
| 105 | + |
| 106 | +function mapSortedResultSetInfoToDataModel( |
| 107 | + resultSet: SortedResultSetInfo, |
| 108 | +): SortedResultSetInfoDto { |
| 109 | + return { |
| 110 | + resultsPath: resultSet.resultsPath, |
| 111 | + sortState: mapRawResultsSortStateToDataModel(resultSet.sortState), |
57 | 112 | }; |
58 | 113 | } |
59 | 114 |
|
|
0 commit comments