Skip to content

Commit 9629c99

Browse files
Move alertTitle and alertMessage to props
1 parent 7ade7be commit 9629c99

4 files changed

Lines changed: 32 additions & 55 deletions

File tree

extensions/ql-vscode/src/stories/variant-analysis/VariantAnalysisSkippedRepositoriesTab.stories.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ const Template: ComponentStory<typeof VariantAnalysisSkippedRepositoriesTab> = (
2323

2424
export const NoAccessNoOmissions = Template.bind({});
2525
NoAccessNoOmissions.args = {
26-
reason: 'no_access',
26+
alertTitle: 'No access',
27+
alertMessage: 'The following repositories could not be scanned because you do not have read access.',
2728
skippedRepositoryGroup: {
2829
repositoryCount: 2,
2930
repositories: [
@@ -39,7 +40,7 @@ NoAccessNoOmissions.args = {
3940

4041
export const NoAccessWithOmissions = Template.bind({});
4142
NoAccessWithOmissions.args = {
42-
reason: 'no_access',
43+
...NoAccessNoOmissions.args,
4344
skippedRepositoryGroup: {
4445
repositoryCount: 12345,
4546
repositories: [
@@ -58,7 +59,8 @@ NoAccessWithOmissions.args = {
5859

5960
export const NoDatabaseNoOmissions = Template.bind({});
6061
NoDatabaseNoOmissions.args = {
61-
reason: 'no_database',
62+
alertTitle: 'No database',
63+
alertMessage: 'The following repositories could not be scanned because they do not have an available CodeQL database.',
6264
skippedRepositoryGroup: {
6365
repositoryCount: 2,
6466
repositories: [
@@ -78,7 +80,7 @@ NoDatabaseNoOmissions.args = {
7880

7981
export const NoDatabaseWithOmissions = Template.bind({});
8082
NoDatabaseWithOmissions.args = {
81-
reason: 'no_database',
83+
...NoDatabaseNoOmissions.args,
8284
skippedRepositoryGroup: {
8385
repositoryCount: 12345,
8486
repositories: [

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,15 @@ export const VariantAnalysisOutcomePanels = ({
9191
{notFoundRepos?.repositoryCount &&
9292
<VSCodePanelView>
9393
<VariantAnalysisSkippedRepositoriesTab
94-
reason='no_access'
94+
alertTitle='No access'
95+
alertMessage='The following repositories could not be scanned because you do not have read access.'
9596
skippedRepositoryGroup={notFoundRepos} />
9697
</VSCodePanelView>}
9798
{noCodeqlDbRepos?.repositoryCount &&
9899
<VSCodePanelView>
99100
<VariantAnalysisSkippedRepositoriesTab
100-
reason='no_database'
101+
alertTitle='No database'
102+
alertMessage='The following repositories could not be scanned because they do not have an available CodeQL database.'
101103
skippedRepositoryGroup={noCodeqlDbRepos} />
102104
</VSCodePanelView>}
103105
</VSCodePanels>

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

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,47 +4,26 @@ import { VariantAnalysisSkippedRepositoryGroup } from '../../remote-queries/shar
44
import { Alert } from '../common';
55
import { VariantAnalysisSkippedRepositoryRow } from './VariantAnalysisSkippedRepositoryRow';
66

7-
export type SkippedRepositoriesReason = 'no_access' | 'no_database';
8-
97
export type VariantAnalysisSkippedRepositoriesTabProps = {
10-
reason: SkippedRepositoriesReason,
8+
alertTitle: string,
9+
alertMessage: string,
1110
skippedRepositoryGroup: VariantAnalysisSkippedRepositoryGroup,
1211
};
1312

14-
function getSkipReasonAlertTitle(reason: SkippedRepositoriesReason): string {
15-
switch (reason) {
16-
case 'no_access':
17-
return 'No access';
18-
case 'no_database':
19-
return 'No database';
20-
}
21-
}
22-
23-
function getSkipReasonAlertMessage(
24-
reason: SkippedRepositoriesReason,
13+
function getSkipReasonAlert(
14+
title: string,
15+
message: string,
2516
repos: VariantAnalysisSkippedRepositoryGroup
26-
): string {
17+
) {
2718
const repositoriesOmittedText = repos.repositoryCount > repos.repositories.length
2819
? ` (Only the first ${repos.repositories.length} ${repos.repositories.length > 1 ? 'repositories are' : 'repository is'} shown.)`
2920
: '';
30-
switch (reason) {
31-
case 'no_access':
32-
return `The following repositories could not be scanned because you do not have read access.${repositoriesOmittedText}`;
33-
case 'no_database':
34-
return `The following repositories could not be scanned because they do not have an available CodeQL database.${repositoriesOmittedText}`;
35-
}
36-
}
37-
38-
function getSkipReasonAlert(
39-
reason: SkippedRepositoriesReason,
40-
repos: VariantAnalysisSkippedRepositoryGroup
41-
) {
4221
return (
4322
<Alert
4423
key='alert'
4524
type='warning'
46-
title={getSkipReasonAlertTitle(reason)}
47-
message={getSkipReasonAlertMessage(reason, repos)}
25+
title={title}
26+
message={message + repositoriesOmittedText}
4827
/>
4928
);
5029
}
@@ -57,12 +36,13 @@ const Container = styled.div`
5736
`;
5837

5938
export const VariantAnalysisSkippedRepositoriesTab = ({
60-
reason,
39+
alertTitle,
40+
alertMessage,
6141
skippedRepositoryGroup,
6242
}: VariantAnalysisSkippedRepositoriesTabProps) => {
6343
return (
6444
<Container>
65-
{getSkipReasonAlert(reason, skippedRepositoryGroup)}
45+
{getSkipReasonAlert(alertTitle, alertMessage, skippedRepositoryGroup)}
6646
{skippedRepositoryGroup.repositories.map((repo) =>
6747
<VariantAnalysisSkippedRepositoryRow key={`repo/${repo.fullName}`} repository={repo} />
6848
)}

extensions/ql-vscode/src/view/variant-analysis/__tests__/VariantAnalysisSkippedRepositoriesTab.spec.tsx

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ describe(VariantAnalysisSkippedRepositoriesTab.name, () => {
66
const render = (props: VariantAnalysisSkippedRepositoriesTabProps) =>
77
reactRender(<VariantAnalysisSkippedRepositoriesTab {...props} />);
88

9-
it('renders warning title when reason is no_access', async () => {
9+
it('renders warning title', async () => {
1010
render({
11-
reason: 'no_access',
11+
alertTitle: 'No access',
12+
alertMessage: 'The following repositories could not be scanned because you do not have read access.',
1213
skippedRepositoryGroup: {
1314
repositoryCount: 1,
1415
repositories: [],
@@ -18,21 +19,10 @@ describe(VariantAnalysisSkippedRepositoriesTab.name, () => {
1819
expect(screen.getByText('Warning: No access')).toBeInTheDocument();
1920
});
2021

21-
it('renders warning title when reason is no_database', async () => {
22-
render({
23-
reason: 'no_database',
24-
skippedRepositoryGroup: {
25-
repositoryCount: 1,
26-
repositories: [],
27-
}
28-
});
29-
30-
expect(screen.getByText('Warning: No database')).toBeInTheDocument();
31-
});
32-
3322
it('renders warning message when no repositories are omitted', async () => {
3423
render({
35-
reason: 'no_access',
24+
alertTitle: 'No access',
25+
alertMessage: 'The following repositories could not be scanned because you do not have read access.',
3626
skippedRepositoryGroup: {
3727
repositoryCount: 1,
3828
repositories: [
@@ -48,7 +38,8 @@ describe(VariantAnalysisSkippedRepositoriesTab.name, () => {
4838

4939
it('renders warning message when there are repositories omitted and only one shown', async () => {
5040
render({
51-
reason: 'no_access',
41+
alertTitle: 'No access',
42+
alertMessage: 'The following repositories could not be scanned because you do not have read access.',
5243
skippedRepositoryGroup: {
5344
repositoryCount: 44,
5445
repositories: [
@@ -64,7 +55,8 @@ describe(VariantAnalysisSkippedRepositoriesTab.name, () => {
6455

6556
it('renders warning message when there are repositories omitted and multiple shown', async () => {
6657
render({
67-
reason: 'no_access',
58+
alertTitle: 'No access',
59+
alertMessage: 'The following repositories could not be scanned because you do not have read access.',
6860
skippedRepositoryGroup: {
6961
repositoryCount: 44,
7062
repositories: [
@@ -83,7 +75,8 @@ describe(VariantAnalysisSkippedRepositoriesTab.name, () => {
8375

8476
it('renders multiple skipped repository rows', async () => {
8577
render({
86-
reason: 'no_database',
78+
alertTitle: 'No database',
79+
alertMessage: 'The following repositories could not be scanned because they do not have an available CodeQL database.',
8780
skippedRepositoryGroup: {
8881
repositoryCount: 1,
8982
repositories: [

0 commit comments

Comments
 (0)