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 classNames from 'classnames';
21 import * as React from 'react';
22 import { BranchLike } from '../../../../../../types/branch-like';
23 import { getBranches } from '../../../../../../api/branches';
24 import { getRegulatoryReportUrl } from '../../../../../../api/regulatory-report';
25 import { ButtonLink } from '../../../../../../components/controls/buttons';
26 import Select, { BasicSelectOption } from '../../../../../../components/controls/Select';
28 getBranchLikeDisplayName,
31 } from '../../../../../../helpers/branch-like';
32 import { translate } from '../../../../../../helpers/l10n';
33 import { Component } from '../../../../../../types/types';
34 import { orderBy } from 'lodash';
37 component: Pick<Component, 'key' | 'name'>;
38 branchLike?: BranchLike;
43 downloadStarted: boolean;
44 selectedBranch: string;
45 branchLikesOptions: BasicSelectOption[];
48 export default class RegulatoryReport extends React.PureComponent<Props, State> {
49 constructor(props: Props) {
52 downloadStarted: false,
54 branchLikesOptions: [],
59 const { component, branchLike } = this.props;
60 getBranches(component.key)
62 const mainBranch = data.find(isMainBranch);
63 const otherBranchSorted = orderBy(
64 data.filter(isBranch).filter((b) => !isMainBranch(b)),
67 const sortedBranch = mainBranch ? [mainBranch, ...otherBranchSorted] : otherBranchSorted;
68 const options = sortedBranch
69 .filter((br) => br.excludedFromPurge)
72 value: getBranchLikeDisplayName(br),
73 label: getBranchLikeDisplayName(br),
77 let selectedBranch = '';
78 if (branchLike && isBranch(branchLike) && branchLike.excludedFromPurge) {
79 selectedBranch = getBranchLikeDisplayName(branchLike);
80 } else if (mainBranch) {
81 selectedBranch = getBranchLikeDisplayName(mainBranch);
83 this.setState({ selectedBranch, branchLikesOptions: options });
86 this.setState({ branchLikesOptions: [] });
90 onBranchSelect = (newOption: BasicSelectOption) => {
91 this.setState({ selectedBranch: newOption.value, downloadStarted: false });
95 const { component, onClose } = this.props;
96 const { downloadStarted, selectedBranch, branchLikesOptions } = this.state;
100 <div className="modal-head">
101 <h2>{translate('regulatory_report.page')}</h2>
103 <div className="modal-body">
104 <p>{translate('regulatory_report.description1')}</p>
105 <div className="markdown">
107 <li>{translate('regulatory_report.bullet_point1')}</li>
108 <li>{translate('regulatory_report.bullet_point2')}</li>
109 <li>{translate('regulatory_report.bullet_point3')}</li>
112 <p>{translate('regulatory_report.description2')}</p>
113 <div className="modal-field big-spacer-top">
114 <label htmlFor="regulatory-report-branch-select">
115 {translate('regulatory_page.select_branch')}
118 className="width-100"
119 inputId="regulatory-report-branch-select"
120 id="regulatory-report-branch-select-input"
121 onChange={this.onBranchSelect}
122 options={branchLikesOptions}
123 value={branchLikesOptions.find((o) => o.value === selectedBranch)}
126 <div className="modal-field big-spacer-top">
127 {downloadStarted && (
129 <p>{translate('regulatory_page.download_start.sentence')}</p>
134 <div className="modal-foot">
136 className={classNames('button button-primary big-spacer-right', {
137 disabled: downloadStarted,
139 download={[component.name, selectedBranch, 'regulatory report.zip']
142 onClick={() => this.setState({ downloadStarted: true })}
143 href={getRegulatoryReportUrl(component.key, selectedBranch)}
145 rel="noopener noreferrer"
147 {translate('download_verb')}
149 <ButtonLink onClick={onClose}>{translate('close')}</ButtonLink>