From: Wouter Admiraal Date: Tue, 8 Jan 2019 14:22:02 +0000 (+0100) Subject: SONAR-9392 Add option to choose parent when creating new profile X-Git-Tag: 7.6~41 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b0be9375e8065a5d2b3a7b04d9392d8998f5c6b9;p=sonarqube.git SONAR-9392 Add option to choose parent when creating new profile --- diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/home/CreateProfileForm.tsx b/server/sonar-web/src/main/js/apps/quality-profiles/home/CreateProfileForm.tsx index cb315fb9400..56d1032bd40 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/home/CreateProfileForm.tsx +++ b/server/sonar-web/src/main/js/apps/quality-profiles/home/CreateProfileForm.tsx @@ -19,17 +19,23 @@ */ import * as React from 'react'; import { sortBy } from 'lodash'; -import { getImporters, createQualityProfile } from '../../../api/quality-profiles'; +import { + changeProfileParent, + createQualityProfile, + getImporters +} from '../../../api/quality-profiles'; import Modal from '../../../components/controls/Modal'; import Select from '../../../components/controls/Select'; import { SubmitButton, ResetButtonLink } from '../../../components/ui/buttons'; import { translate } from '../../../helpers/l10n'; +import { Profile } from '../types'; interface Props { languages: Array<{ key: string; name: string }>; onClose: () => void; onCreate: Function; organization: string | null; + profiles: Profile[]; } interface State { @@ -37,6 +43,7 @@ interface State { language?: string; loading: boolean; name: string; + parent?: string; preloading: boolean; } @@ -76,6 +83,10 @@ export default class CreateProfileForm extends React.PureComponent this.setState({ language: option.value }); }; + handleParentChange = (option: { value: string } | null) => { + this.setState({ parent: option ? option.value : undefined }); + }; + handleFormSubmit = (event: React.SyntheticEvent) => { event.preventDefault(); @@ -87,7 +98,19 @@ export default class CreateProfileForm extends React.PureComponent } createQualityProfile(data).then( - (response: any) => this.props.onCreate(response.profile), + ({ profile }: { profile: Profile }) => { + if (this.state.parent) { + // eslint-disable-next-line promise/no-nesting + changeProfileParent(profile.key, this.state.parent).then( + () => { + this.props.onCreate(profile); + }, + () => {} + ); + } else { + this.props.onCreate(profile); + } + }, () => { if (this.mounted) { this.setState({ loading: false }); @@ -98,13 +121,27 @@ export default class CreateProfileForm extends React.PureComponent render() { const header = translate('quality_profiles.new_profile'); - const languages = sortBy(this.props.languages, 'name'); + let profiles: Array<{ label: string; value: string }> = []; + const selectedLanguage = this.state.language || languages[0].key; const importers = this.state.importers.filter(importer => importer.languages.includes(selectedLanguage) ); + if (selectedLanguage) { + const languageProfiles = this.props.profiles.filter(p => p.language === selectedLanguage); + profiles = [ + { label: translate('none'), value: '' }, + ...sortBy(languageProfiles, 'name').map(profile => ({ + label: profile.isBuiltIn + ? `${profile.name} (${translate('quality_profiles.built_in')})` + : profile.name, + value: profile.key + })) + ]; + } + return (
@@ -152,6 +189,22 @@ export default class CreateProfileForm extends React.PureComponent value={selectedLanguage} /> + {selectedLanguage && + profiles.length && ( +
+ +