/* * SonarQube * Copyright (C) 2009-2022 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 * as React from 'react'; import { Helmet } from 'react-helmet-async'; import { FormattedMessage } from 'react-intl'; import { components, OptionProps } from 'react-select'; import A11ySkipTarget from '../../components/a11y/A11ySkipTarget'; import DisableableSelectOption from '../../components/common/DisableableSelectOption'; import Link from '../../components/common/Link'; import { SubmitButton } from '../../components/controls/buttons'; import HelpTooltip from '../../components/controls/HelpTooltip'; import Radio from '../../components/controls/Radio'; import Select, { BasicSelectOption } from '../../components/controls/Select'; import Suggestions from '../../components/embed-docs-modal/Suggestions'; import { Alert } from '../../components/ui/Alert'; import { translate } from '../../helpers/l10n'; import { isDiffMetric } from '../../helpers/measures'; import { QualityGate } from '../../types/types'; import BuiltInQualityGateBadge from '../quality-gates/components/BuiltInQualityGateBadge'; import { USE_SYSTEM_DEFAULT } from './constants'; export interface ProjectQualityGateAppRendererProps { allQualityGates?: QualityGate[]; currentQualityGate?: QualityGate; loading: boolean; onSelect: (id: string) => void; onSubmit: () => void; selectedQualityGateId: string; submitting: boolean; } function hasConditionOnNewCode(qualityGate: QualityGate): boolean { return !!qualityGate.conditions?.some(condition => isDiffMetric(condition.metric)); } interface QualityGateOption extends BasicSelectOption { isDisabled: boolean; } function renderQualitygateOption(props: OptionProps) { return (
( {translate('project_quality_gate.no_condition.link')} ) }} /> )} />
); } export default function ProjectQualityGateAppRenderer(props: ProjectQualityGateAppRendererProps) { const { allQualityGates, currentQualityGate, loading, selectedQualityGateId, submitting } = props; const defaultQualityGate = allQualityGates?.find(g => g.isDefault); if (loading) { return ; } if ( allQualityGates === undefined || defaultQualityGate === undefined || currentQualityGate === undefined ) { return null; } const usesDefault = selectedQualityGateId === USE_SYSTEM_DEFAULT; const needsReanalysis = usesDefault ? // currentQualityGate.isDefault is not always up to date. We need to check // against defaultQualityGate explicitly. defaultQualityGate.id !== currentQualityGate.id : selectedQualityGateId !== currentQualityGate.id; const selectedQualityGate = allQualityGates.find(qg => qg.id === selectedQualityGateId); const options: QualityGateOption[] = allQualityGates.map(g => ({ isDisabled: g.conditions === undefined || g.conditions.length === 0, label: g.name, value: g.id })); return (

{translate('project_quality_gate.page')}

{translate('quality_gates.projects.help')}
} />

{translate('project_quality_gate.subtitle')}

{ e.preventDefault(); props.onSubmit(); }}>

{translate('project_quality_gate.page.description')}

props.onSelect(USE_SYSTEM_DEFAULT)} value={USE_SYSTEM_DEFAULT}>
{translate('project_quality_gate.always_use_default')}
{translate('current_noun')}: {defaultQualityGate.name} {defaultQualityGate.isBuiltIn && ( )}
{ if (usesDefault) { props.onSelect(value); } }} value={!usesDefault ? selectedQualityGateId : currentQualityGate.id}>
{translate('project_quality_gate.always_use_specific')}