-
Notifications
You must be signed in to change notification settings - Fork 227
Expand file tree
/
Copy pathAnalyzedRepoItemContent.tsx
More file actions
137 lines (127 loc) · 3.88 KB
/
AnalyzedRepoItemContent.tsx
File metadata and controls
137 lines (127 loc) · 3.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import * as React from "react";
import { styled } from "styled-components";
import {
AnalysisAlert,
AnalysisRawResults,
} from "../../variant-analysis/shared/analysis-result";
import AnalysisAlertResult from "./AnalysisAlertResult";
import RawResultsTable from "./RawResultsTable";
import {
VariantAnalysisRepoStatus,
VariantAnalysisScannedRepositoryDownloadStatus,
} from "../../variant-analysis/shared/variant-analysis";
import { Alert } from "../common";
import { ResultFormat } from "../../variant-analysis/shared/variant-analysis-result-format";
const ContentContainer = styled.div`
display: flex;
flex-direction: column;
`;
const AlertContainer = styled.div`
margin-top: 1em;
`;
const InterpretedResultsContainer = styled.ul`
list-style-type: none;
margin: 1em 0 0;
padding: 0.5em 0 0 0;
`;
const InterpretedResultItem = styled.li`
margin-bottom: 1em;
background-color: var(--vscode-notifications-background);
`;
const RawResultsContainer = styled.div`
display: block;
margin-top: 0.5em;
`;
function chooseResultFormat(
interpretedResults: AnalysisAlert[] | undefined,
rawResults: AnalysisRawResults | undefined,
resultFormat: ResultFormat,
): ResultFormat | undefined {
if (interpretedResults && resultFormat === ResultFormat.Alerts) {
return ResultFormat.Alerts;
} else if (rawResults) {
return ResultFormat.RawResults;
} else {
return undefined;
}
}
export type AnalyzedRepoItemContentProps = {
status?: VariantAnalysisRepoStatus;
downloadStatus?: VariantAnalysisScannedRepositoryDownloadStatus;
interpretedResults?: AnalysisAlert[];
rawResults?: AnalysisRawResults;
resultFormat: ResultFormat;
};
export const AnalyzedRepoItemContent = ({
status,
downloadStatus,
interpretedResults,
rawResults,
resultFormat,
}: AnalyzedRepoItemContentProps) => {
const chosenResultFormat = chooseResultFormat(
interpretedResults,
rawResults,
resultFormat,
);
return (
<ContentContainer>
{status === VariantAnalysisRepoStatus.Failed && (
<AlertContainer>
<Alert
type="error"
title="Failed"
message="The query failed to run on this repository."
/>
</AlertContainer>
)}
{status === VariantAnalysisRepoStatus.TimedOut && (
<AlertContainer>
<Alert
type="error"
title="Timed out"
message="The analysis ran out of time and we couldn't scan the repository."
/>
</AlertContainer>
)}
{status === VariantAnalysisRepoStatus.Canceled && (
<AlertContainer>
<Alert
type="error"
title="Canceled"
message="The variant analysis for this repository was canceled."
/>
</AlertContainer>
)}
{downloadStatus ===
VariantAnalysisScannedRepositoryDownloadStatus.Failed && (
<AlertContainer>
<Alert
type="error"
title="Download failed"
message="The query was successful on this repository, but the extension failed to download the results for this repository."
/>
</AlertContainer>
)}
{interpretedResults && chosenResultFormat === ResultFormat.Alerts && (
<InterpretedResultsContainer>
{interpretedResults.map((r, i) => (
<InterpretedResultItem key={i}>
<AnalysisAlertResult alert={r} />
</InterpretedResultItem>
))}
</InterpretedResultsContainer>
)}
{rawResults && chosenResultFormat === ResultFormat.RawResults && (
<RawResultsContainer>
<RawResultsTable
schema={rawResults.schema}
results={rawResults.resultSet}
fileLinkPrefix={rawResults.fileLinkPrefix}
sourceLocationPrefix={rawResults.sourceLocationPrefix}
/>
</RawResultsContainer>
)}
</ContentContainer>
);
};