Move alertTitle and alertMessage to props
This commit is contained in:
@@ -23,7 +23,8 @@ const Template: ComponentStory<typeof VariantAnalysisSkippedRepositoriesTab> = (
|
||||
|
||||
export const NoAccessNoOmissions = Template.bind({});
|
||||
NoAccessNoOmissions.args = {
|
||||
reason: 'no_access',
|
||||
alertTitle: 'No access',
|
||||
alertMessage: 'The following repositories could not be scanned because you do not have read access.',
|
||||
skippedRepositoryGroup: {
|
||||
repositoryCount: 2,
|
||||
repositories: [
|
||||
@@ -39,7 +40,7 @@ NoAccessNoOmissions.args = {
|
||||
|
||||
export const NoAccessWithOmissions = Template.bind({});
|
||||
NoAccessWithOmissions.args = {
|
||||
reason: 'no_access',
|
||||
...NoAccessNoOmissions.args,
|
||||
skippedRepositoryGroup: {
|
||||
repositoryCount: 12345,
|
||||
repositories: [
|
||||
@@ -58,7 +59,8 @@ NoAccessWithOmissions.args = {
|
||||
|
||||
export const NoDatabaseNoOmissions = Template.bind({});
|
||||
NoDatabaseNoOmissions.args = {
|
||||
reason: 'no_database',
|
||||
alertTitle: 'No database',
|
||||
alertMessage: 'The following repositories could not be scanned because they do not have an available CodeQL database.',
|
||||
skippedRepositoryGroup: {
|
||||
repositoryCount: 2,
|
||||
repositories: [
|
||||
@@ -78,7 +80,7 @@ NoDatabaseNoOmissions.args = {
|
||||
|
||||
export const NoDatabaseWithOmissions = Template.bind({});
|
||||
NoDatabaseWithOmissions.args = {
|
||||
reason: 'no_database',
|
||||
...NoDatabaseNoOmissions.args,
|
||||
skippedRepositoryGroup: {
|
||||
repositoryCount: 12345,
|
||||
repositories: [
|
||||
|
||||
@@ -91,13 +91,15 @@ export const VariantAnalysisOutcomePanels = ({
|
||||
{notFoundRepos?.repositoryCount &&
|
||||
<VSCodePanelView>
|
||||
<VariantAnalysisSkippedRepositoriesTab
|
||||
reason='no_access'
|
||||
alertTitle='No access'
|
||||
alertMessage='The following repositories could not be scanned because you do not have read access.'
|
||||
skippedRepositoryGroup={notFoundRepos} />
|
||||
</VSCodePanelView>}
|
||||
{noCodeqlDbRepos?.repositoryCount &&
|
||||
<VSCodePanelView>
|
||||
<VariantAnalysisSkippedRepositoriesTab
|
||||
reason='no_database'
|
||||
alertTitle='No database'
|
||||
alertMessage='The following repositories could not be scanned because they do not have an available CodeQL database.'
|
||||
skippedRepositoryGroup={noCodeqlDbRepos} />
|
||||
</VSCodePanelView>}
|
||||
</VSCodePanels>
|
||||
|
||||
@@ -4,47 +4,26 @@ import { VariantAnalysisSkippedRepositoryGroup } from '../../remote-queries/shar
|
||||
import { Alert } from '../common';
|
||||
import { VariantAnalysisSkippedRepositoryRow } from './VariantAnalysisSkippedRepositoryRow';
|
||||
|
||||
export type SkippedRepositoriesReason = 'no_access' | 'no_database';
|
||||
|
||||
export type VariantAnalysisSkippedRepositoriesTabProps = {
|
||||
reason: SkippedRepositoriesReason,
|
||||
alertTitle: string,
|
||||
alertMessage: string,
|
||||
skippedRepositoryGroup: VariantAnalysisSkippedRepositoryGroup,
|
||||
};
|
||||
|
||||
function getSkipReasonAlertTitle(reason: SkippedRepositoriesReason): string {
|
||||
switch (reason) {
|
||||
case 'no_access':
|
||||
return 'No access';
|
||||
case 'no_database':
|
||||
return 'No database';
|
||||
}
|
||||
}
|
||||
|
||||
function getSkipReasonAlertMessage(
|
||||
reason: SkippedRepositoriesReason,
|
||||
function getSkipReasonAlert(
|
||||
title: string,
|
||||
message: string,
|
||||
repos: VariantAnalysisSkippedRepositoryGroup
|
||||
): string {
|
||||
) {
|
||||
const repositoriesOmittedText = repos.repositoryCount > repos.repositories.length
|
||||
? ` (Only the first ${repos.repositories.length} ${repos.repositories.length > 1 ? 'repositories are' : 'repository is'} shown.)`
|
||||
: '';
|
||||
switch (reason) {
|
||||
case 'no_access':
|
||||
return `The following repositories could not be scanned because you do not have read access.${repositoriesOmittedText}`;
|
||||
case 'no_database':
|
||||
return `The following repositories could not be scanned because they do not have an available CodeQL database.${repositoriesOmittedText}`;
|
||||
}
|
||||
}
|
||||
|
||||
function getSkipReasonAlert(
|
||||
reason: SkippedRepositoriesReason,
|
||||
repos: VariantAnalysisSkippedRepositoryGroup
|
||||
) {
|
||||
return (
|
||||
<Alert
|
||||
key='alert'
|
||||
type='warning'
|
||||
title={getSkipReasonAlertTitle(reason)}
|
||||
message={getSkipReasonAlertMessage(reason, repos)}
|
||||
title={title}
|
||||
message={message + repositoriesOmittedText}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -57,12 +36,13 @@ const Container = styled.div`
|
||||
`;
|
||||
|
||||
export const VariantAnalysisSkippedRepositoriesTab = ({
|
||||
reason,
|
||||
alertTitle,
|
||||
alertMessage,
|
||||
skippedRepositoryGroup,
|
||||
}: VariantAnalysisSkippedRepositoriesTabProps) => {
|
||||
return (
|
||||
<Container>
|
||||
{getSkipReasonAlert(reason, skippedRepositoryGroup)}
|
||||
{getSkipReasonAlert(alertTitle, alertMessage, skippedRepositoryGroup)}
|
||||
{skippedRepositoryGroup.repositories.map((repo) =>
|
||||
<VariantAnalysisSkippedRepositoryRow key={`repo/${repo.fullName}`} repository={repo} />
|
||||
)}
|
||||
|
||||
@@ -6,9 +6,10 @@ describe(VariantAnalysisSkippedRepositoriesTab.name, () => {
|
||||
const render = (props: VariantAnalysisSkippedRepositoriesTabProps) =>
|
||||
reactRender(<VariantAnalysisSkippedRepositoriesTab {...props} />);
|
||||
|
||||
it('renders warning title when reason is no_access', async () => {
|
||||
it('renders warning title', async () => {
|
||||
render({
|
||||
reason: 'no_access',
|
||||
alertTitle: 'No access',
|
||||
alertMessage: 'The following repositories could not be scanned because you do not have read access.',
|
||||
skippedRepositoryGroup: {
|
||||
repositoryCount: 1,
|
||||
repositories: [],
|
||||
@@ -18,21 +19,10 @@ describe(VariantAnalysisSkippedRepositoriesTab.name, () => {
|
||||
expect(screen.getByText('Warning: No access')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders warning title when reason is no_database', async () => {
|
||||
render({
|
||||
reason: 'no_database',
|
||||
skippedRepositoryGroup: {
|
||||
repositoryCount: 1,
|
||||
repositories: [],
|
||||
}
|
||||
});
|
||||
|
||||
expect(screen.getByText('Warning: No database')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders warning message when no repositories are omitted', async () => {
|
||||
render({
|
||||
reason: 'no_access',
|
||||
alertTitle: 'No access',
|
||||
alertMessage: 'The following repositories could not be scanned because you do not have read access.',
|
||||
skippedRepositoryGroup: {
|
||||
repositoryCount: 1,
|
||||
repositories: [
|
||||
@@ -48,7 +38,8 @@ describe(VariantAnalysisSkippedRepositoriesTab.name, () => {
|
||||
|
||||
it('renders warning message when there are repositories omitted and only one shown', async () => {
|
||||
render({
|
||||
reason: 'no_access',
|
||||
alertTitle: 'No access',
|
||||
alertMessage: 'The following repositories could not be scanned because you do not have read access.',
|
||||
skippedRepositoryGroup: {
|
||||
repositoryCount: 44,
|
||||
repositories: [
|
||||
@@ -64,7 +55,8 @@ describe(VariantAnalysisSkippedRepositoriesTab.name, () => {
|
||||
|
||||
it('renders warning message when there are repositories omitted and multiple shown', async () => {
|
||||
render({
|
||||
reason: 'no_access',
|
||||
alertTitle: 'No access',
|
||||
alertMessage: 'The following repositories could not be scanned because you do not have read access.',
|
||||
skippedRepositoryGroup: {
|
||||
repositoryCount: 44,
|
||||
repositories: [
|
||||
@@ -83,7 +75,8 @@ describe(VariantAnalysisSkippedRepositoriesTab.name, () => {
|
||||
|
||||
it('renders multiple skipped repository rows', async () => {
|
||||
render({
|
||||
reason: 'no_database',
|
||||
alertTitle: 'No database',
|
||||
alertMessage: 'The following repositories could not be scanned because they do not have an available CodeQL database.',
|
||||
skippedRepositoryGroup: {
|
||||
repositoryCount: 1,
|
||||
repositories: [
|
||||
|
||||
Reference in New Issue
Block a user