From a39698d0cd444d4e9c56fafb8da4171a3e3454bf Mon Sep 17 00:00:00 2001 From: Mathieu Suen Date: Wed, 23 Mar 2022 12:16:35 +0100 Subject: SONAR-16085 Change the bulk change quality profile select. --- .../coding-rules/components/BulkChangeModal.tsx | 30 ++++---- .../components/__tests__/BulkChangeModal-test.tsx | 13 +++- .../__snapshots__/BulkChangeModal-test.tsx.snap | 18 +++-- .../src/main/js/components/controls/Select.tsx | 87 ++++++++++++++++++---- .../__tests__/__snapshots__/Select-test.tsx.snap | 6 ++ 5 files changed, 114 insertions(+), 40 deletions(-) (limited to 'server/sonar-web/src') diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/BulkChangeModal.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/BulkChangeModal.tsx index 700e29367d7..32c3b9b691d 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/BulkChangeModal.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/BulkChangeModal.tsx @@ -22,7 +22,7 @@ import { bulkActivateRules, bulkDeactivateRules, Profile } from '../../../api/qu import withLanguagesContext from '../../../app/components/languages/withLanguagesContext'; import { ResetButtonLink, SubmitButton } from '../../../components/controls/buttons'; import Modal from '../../../components/controls/Modal'; -import SelectLegacy from '../../../components/controls/SelectLegacy'; +import Select from '../../../components/controls/Select'; import { Alert } from '../../../components/ui/Alert'; import { translate, translateWithParameters } from '../../../helpers/l10n'; import { formatMeasure } from '../../../helpers/measures'; @@ -49,7 +49,7 @@ interface ActivationResult { interface State { finished: boolean; results: ActivationResult[]; - selectedProfiles: any[]; + selectedProfiles: Profile[]; submitting: boolean; } @@ -63,7 +63,7 @@ export class BulkChangeModal extends React.PureComponent { const selectedProfiles = []; const availableProfiles = this.getAvailableQualityProfiles(props); if (availableProfiles.length === 1) { - selectedProfiles.push(availableProfiles[0].key); + selectedProfiles.push(availableProfiles[0]); } this.state = { finished: false, results: [], selectedProfiles, submitting: false }; @@ -77,8 +77,7 @@ export class BulkChangeModal extends React.PureComponent { this.mounted = false; } - handleProfileSelect = (options: { value: string }[]) => { - const selectedProfiles = options.map(option => option.value); + handleProfileSelect = (selectedProfiles: Profile[]) => { this.setState({ selectedProfiles }); }; @@ -116,7 +115,7 @@ export class BulkChangeModal extends React.PureComponent { // otherwise take all profiles selected in the dropdown const profiles: string[] = this.props.profile ? [this.props.profile.key] - : this.state.selectedProfiles; + : this.state.selectedProfiles.map(p => p.key); for (const profile of profiles) { looper = looper @@ -180,15 +179,18 @@ export class BulkChangeModal extends React.PureComponent { renderProfileSelect = () => { const profiles = this.getAvailableQualityProfiles(); - const options = profiles.map(profile => ({ - label: `${profile.name} - ${profile.languageName}`, - value: profile.key - })); + return ( - translate('coding_rules.bulk_change.no_quality_profile')} + getOptionLabel={profile => `${profile.name} - ${profile.languageName}`} + getOptionValue={profile => profile.key} onChange={this.handleProfileSelect} - options={options} + options={profiles} value={this.state.selectedProfiles} /> ); @@ -220,7 +222,7 @@ export class BulkChangeModal extends React.PureComponent { {!this.state.finished && !this.state.submitting && (

-