/* * SonarQube * Copyright (C) 2009-2023 SonarSource SA * mailto:info AT sonarsource DOT com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import styled from '@emotion/styled'; import { themeBorder } from 'design-system'; import * as React from 'react'; import EllipsisIcon from '../../components/icons/EllipsisIcon'; import { translate } from '../../helpers/l10n'; import { getBaseUrl } from '../../helpers/system'; import { AlmKeys, AlmSettingsInstance, ProjectAlmBindingResponse } from '../../types/alm-settings'; import { Component } from '../../types/types'; import { LoggedInUser } from '../../types/users'; import { Alert } from '../ui/Alert'; import AzurePipelinesTutorial from './azure-pipelines/AzurePipelinesTutorial'; import BitbucketPipelinesTutorial from './bitbucket-pipelines/BitbucketPipelinesTutorial'; import GitHubActionTutorial from './github-action/GitHubActionTutorial'; import GitLabCITutorial from './gitlabci/GitLabCITutorial'; import JenkinsTutorial from './jenkins/JenkinsTutorial'; import OtherTutorial from './other/OtherTutorial'; import { TutorialModes } from './types'; export interface TutorialSelectionRendererProps { almBinding?: AlmSettingsInstance; baseUrl: string; component: Component; currentUser: LoggedInUser; currentUserCanScanProject: boolean; loading: boolean; mainBranchName: string; onSelectTutorial: (mode: TutorialModes) => void; projectBinding?: ProjectAlmBindingResponse; selectedTutorial?: TutorialModes; willRefreshAutomatically?: boolean; } const DEFAULT_ICON_SIZE = 60; const GH_ACTION_ICON_SIZE = 46; function renderButton( mode: TutorialModes, onSelectTutorial: (mode: TutorialModes) => void, icon: React.ReactNode ) { return ( onSelectTutorial(mode)} type="button" > {icon}
{translate('onboarding.tutorial.choose_method', mode)}
); } export default function TutorialSelectionRenderer(props: TutorialSelectionRendererProps) { const { almBinding, baseUrl, component, currentUser, currentUserCanScanProject, loading, mainBranchName, projectBinding, selectedTutorial, willRefreshAutomatically, } = props; if (loading) { return ; } if (!currentUserCanScanProject) { return {translate('onboarding.tutorial.no_scan_rights')}; } let showGitHubActions = true; let showGitLabCICD = true; let showBitbucketPipelines = true; let showAzurePipelines = true; let showJenkins = true; if (projectBinding !== undefined) { showGitHubActions = projectBinding.alm === AlmKeys.GitHub; showGitLabCICD = projectBinding.alm === AlmKeys.GitLab; showBitbucketPipelines = projectBinding.alm === AlmKeys.BitbucketCloud; showAzurePipelines = [AlmKeys.Azure, AlmKeys.GitHub].includes(projectBinding.alm); showJenkins = [ AlmKeys.BitbucketCloud, AlmKeys.BitbucketServer, AlmKeys.GitHub, AlmKeys.GitLab, ].includes(projectBinding.alm); } return ( <> {selectedTutorial === undefined && ( <>

{translate('onboarding.tutorial.choose_method')}

{translate('onboarding.tutorial.choose_method.devops_platform.description')}

{showJenkins && renderButton( TutorialModes.Jenkins, props.onSelectTutorial, )} {showGitHubActions && renderButton( TutorialModes.GitHubActions, props.onSelectTutorial, )} {showBitbucketPipelines && renderButton( TutorialModes.BitbucketPipelines, props.onSelectTutorial, )} {showGitLabCICD && renderButton( TutorialModes.GitLabCI, props.onSelectTutorial, )} {showAzurePipelines && renderButton( TutorialModes.AzurePipelines, props.onSelectTutorial, )} {renderButton( TutorialModes.OtherCI, props.onSelectTutorial, )}

{translate('onboarding.tutorial.choose_method.local.description')}

{renderButton( TutorialModes.Local, props.onSelectTutorial, )}
)} {selectedTutorial === TutorialModes.Local && ( )} {selectedTutorial === TutorialModes.OtherCI && ( )} {selectedTutorial === TutorialModes.BitbucketPipelines && ( )} {selectedTutorial === TutorialModes.GitHubActions && ( )} {selectedTutorial === TutorialModes.Jenkins && ( )} {selectedTutorial === TutorialModes.GitLabCI && ( )} {selectedTutorial === TutorialModes.AzurePipelines && ( )} ); } const StyledTutorialButtons = styled.button` border: ${themeBorder('default', 'projectCardBorder')}; &:hover, &:focus, &:focus-visible, &:active { border: ${themeBorder('default', 'tabBorder')}; outline: none; } `;