3 * Copyright (C) 2009-2023 SonarSource SA
4 * mailto:info AT sonarsource DOT com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 import { SelectionCard } from 'design-system';
21 import * as React from 'react';
22 import { components, OptionProps } from 'react-select';
23 import Select from '../../../components/controls/Select';
24 import Tooltip from '../../../components/controls/Tooltip';
25 import AlertErrorIcon from '../../../components/icons/AlertErrorIcon';
26 import MandatoryFieldMarker from '../../../components/ui/MandatoryFieldMarker';
27 import MandatoryFieldsExplanation from '../../../components/ui/MandatoryFieldsExplanation';
28 import { translate, translateWithParameters } from '../../../helpers/l10n';
29 import { NewCodeDefinitionType } from '../../../types/new-code-definition';
31 export interface BaselineSettingReferenceBranchProps {
32 branchList: BranchOption[];
35 onChangeReferenceBranch: (value: string) => void;
36 onSelect: (selection: NewCodeDefinitionType) => void;
37 referenceBranch: string;
39 settingLevel: 'project' | 'branch';
42 export interface BranchOption {
50 function renderBranchOption(props: OptionProps<BranchOption, false>) {
51 const { data: option } = props;
54 <components.Option {...props}>
57 overlay={translateWithParameters(
58 'baseline.reference_branch.does_not_exist',
63 {option.value} <AlertErrorIcon />
71 ? translate('baseline.reference_branch.cannot_be_itself')
78 <div className="badge spacer-left">{translate('branches.main_branch')}</div>
86 export default function NewCodeDefinitionSettingReferenceBranch(
87 props: BaselineSettingReferenceBranchProps
89 const { branchList, className, disabled, referenceBranch, selected, settingLevel } = props;
91 const currentBranch = branchList.find((b) => b.value === referenceBranch) || {
92 label: referenceBranch,
93 value: referenceBranch,
100 className={className}
102 onClick={() => props.onSelect(NewCodeDefinitionType.ReferenceBranch)}
104 title={translate('baseline.reference_branch')}
108 <p className="sw-mb-3">{translate('baseline.reference_branch.description')}</p>
109 <p className="sw-mb-4">{translate('baseline.reference_branch.usecase')}</p>
113 {settingLevel === 'project' && (
114 <p className="spacer-top">{translate('baseline.reference_branch.description2')}</p>
116 <div className="big-spacer-top display-flex-column">
117 <MandatoryFieldsExplanation className="spacer-bottom" />
118 <label className="text-middle" htmlFor="reference_branch">
119 <strong>{translate('baseline.reference_branch.choose')}</strong>
120 <MandatoryFieldMarker />
123 className="little-spacer-top spacer-bottom"
125 aria-label={translate('baseline.reference_branch.choose')}
126 onChange={(option: BranchOption) => props.onChangeReferenceBranch(option.value)}
127 value={currentBranch}
129 Option: renderBranchOption,