From: Grégoire Aubert Date: Thu, 22 Feb 2018 16:35:02 +0000 (+0100) Subject: SONAR-10053 Display error message when entering license of unknown edition in marketplace X-Git-Tag: 7.5~1631 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2c7c8d8b0c1575f7e2235f5a7868d70bf914f3ba;p=sonarqube.git SONAR-10053 Display error message when entering license of unknown edition in marketplace --- diff --git a/server/sonar-web/src/main/js/apps/marketplace/components/LicenseEditionSet.tsx b/server/sonar-web/src/main/js/apps/marketplace/components/LicenseEditionSet.tsx index 6be68c1aa31..b8099a65079 100644 --- a/server/sonar-web/src/main/js/apps/marketplace/components/LicenseEditionSet.tsx +++ b/server/sonar-web/src/main/js/apps/marketplace/components/LicenseEditionSet.tsx @@ -37,14 +37,15 @@ export interface Props { interface State { acceptTerms: boolean; - license: string; - licenseEdition?: Edition; - loading: boolean; - previewStatus?: string; formData?: { serverId?: string; ncloc?: number; }; + license: string; + licenseEdition?: Edition; + loading: boolean; + previewStatus?: string; + wrongEdition: boolean; } export default class LicenseEditionSet extends React.PureComponent { @@ -52,7 +53,7 @@ export default class LicenseEditionSet extends React.PureComponent constructor(props: Props) { super(props); - this.state = { acceptTerms: false, license: '', loading: false }; + this.state = { acceptTerms: false, license: '', loading: false, wrongEdition: false }; this.fetchLicensePreview = debounce(this.fetchLicensePreview, 100); } @@ -71,16 +72,18 @@ export default class LicenseEditionSet extends React.PureComponent ({ previewStatus, nextEditionKey }) => { if (this.mounted) { const { edition } = this.props; - this.updateLicense( - license, - this.props.editions.find(edition => edition.key === nextEditionKey), - edition && edition.key !== nextEditionKey ? undefined : previewStatus + const licenseEdition = this.props.editions.find( + edition => edition.key === nextEditionKey + ); + const wrongEdition = Boolean( + !licenseEdition || (edition && edition.key !== nextEditionKey) ); + this.setLicense({ license, loading: false, licenseEdition, previewStatus, wrongEdition }); } }, () => { if (this.mounted) { - this.updateLicense(license, undefined, undefined); + this.resetLicense({ license, loading: false }); } } ); @@ -114,42 +117,59 @@ export default class LicenseEditionSet extends React.PureComponent this.fetchLicensePreview(license); this.setState({ license }); } else { - this.updateLicense(license, undefined, undefined); + this.resetLicense({}); } }; - handleTermsCheck = (checked: boolean) => - this.setState({ acceptTerms: checked }, () => - this.updateLicense(this.state.license, this.state.licenseEdition, this.state.previewStatus) + handleTermsCheck = (checked: boolean) => { + this.setLicense({ acceptTerms: checked }); + }; + + resetLicense(state: Pick) { + this.setLicense( + Object.assign( + { + license: '', + licenseEdition: undefined, + previewStatus: undefined, + wrongEdition: false + }, + state + ) ); + } + + setLicense(state: Pick) { + this.setState(state, this.updateParentLicense); + } - updateLicense = (license: string, licenseEdition?: Edition, previewStatus?: string) => { - this.setState({ license, licenseEdition, loading: false, previewStatus }); + updateParentLicense = () => { + const { acceptTerms, license, previewStatus, wrongEdition } = this.state; this.props.updateLicense( - previewStatus !== 'NO_INSTALL' && !this.state.acceptTerms ? undefined : license, - previewStatus + previewStatus !== 'NO_INSTALL' && !acceptTerms ? undefined : license, + wrongEdition ? undefined : previewStatus ); }; renderAlert() { - const { licenseEdition, previewStatus } = this.state; - if (!previewStatus) { + const { licenseEdition, previewStatus, wrongEdition } = this.state; + if (!previewStatus || wrongEdition) { const { edition } = this.props; - if (!edition) { - return undefined; - } return (
- {licenseEdition !== undefined && - edition.key !== licenseEdition.key && ( -

- {translateWithParameters('marketplace.wrong_license_type_x', edition.name)} -

- )} - - {translate('marketplace.i_need_a_license')} - + {wrongEdition && ( +

+ {edition + ? translateWithParameters('marketplace.wrong_license_type_x', edition.name) + : translate('marketplace.wrong_license_type')} +

+ )} + {edition && ( + + {translate('marketplace.i_need_a_license')} + + )}
); } @@ -177,6 +197,7 @@ export default class LicenseEditionSet extends React.PureComponent url: ( {licenseEdition.name} @@ -199,6 +220,7 @@ export default class LicenseEditionSet extends React.PureComponent {translate('marketplace.terms_and_conditions')} @@ -222,8 +244,8 @@ export default class LicenseEditionSet extends React.PureComponent )}