Skip to content

Commit 6398ede

Browse files
Pull icon out to function
1 parent 276d675 commit 6398ede

File tree

1 file changed

+37
-22
lines changed

1 file changed

+37
-22
lines changed

extensions/ql-vscode/src/view/variant-analysis/VariantAnalysisRepositoriesStats.tsx

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,38 @@ type Props = {
1717
skippedRepositoryCount: number;
1818
};
1919

20+
function getIcon(
21+
variantAnalysisStatus: VariantAnalysisStatus,
22+
completedRepositoryCount: number,
23+
successfulRepositoryCount: number,
24+
skippedRepositoryCount: number,
25+
) {
26+
if (successfulRepositoryCount < completedRepositoryCount) {
27+
return (
28+
<>
29+
<HorizontalSpace size={2} />
30+
<ErrorIcon label="Some analyses failed" />
31+
</>
32+
);
33+
} else if (skippedRepositoryCount > 0) {
34+
return (
35+
<>
36+
<HorizontalSpace size={2} />
37+
<WarningIcon label="Some repositories were skipped" />
38+
</>
39+
);
40+
} else if (variantAnalysisStatus === VariantAnalysisStatus.Succeeded) {
41+
return (
42+
<>
43+
<HorizontalSpace size={2} />
44+
<SuccessIcon label="Completed" />
45+
</>
46+
);
47+
} else {
48+
return undefined;
49+
}
50+
}
51+
2052
export const VariantAnalysisRepositoriesStats = ({
2153
variantAnalysisStatus,
2254
totalRepositoryCount,
@@ -33,33 +65,16 @@ export const VariantAnalysisRepositoriesStats = ({
3365
);
3466
}
3567

36-
const showError = successfulRepositoryCount < completedRepositoryCount;
37-
const showWarning = skippedRepositoryCount > 0;
38-
3968
return (
4069
<>
4170
{formatDecimal(successfulRepositoryCount)}/
4271
{formatDecimal(totalRepositoryCount)}
43-
{showError && (
44-
<>
45-
<HorizontalSpace size={2} />
46-
<ErrorIcon label="Some analyses failed" />
47-
</>
48-
)}
49-
{showWarning && !showError && (
50-
<>
51-
<HorizontalSpace size={2} />
52-
<WarningIcon label="Some repositories were skipped" />
53-
</>
72+
{getIcon(
73+
variantAnalysisStatus,
74+
completedRepositoryCount,
75+
successfulRepositoryCount,
76+
skippedRepositoryCount,
5477
)}
55-
{!showError &&
56-
!showWarning &&
57-
variantAnalysisStatus === VariantAnalysisStatus.Succeeded && (
58-
<>
59-
<HorizontalSpace size={2} />
60-
<SuccessIcon label="Completed" />
61-
</>
62-
)}
6378
</>
6479
);
6580
};

0 commit comments

Comments
 (0)