diff options
author | Grégoire Aubert <gregoire.aubert@sonarsource.com> | 2018-06-28 17:21:09 +0200 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2018-07-05 20:21:54 +0200 |
commit | ef66ee089dbbda4441dab0d262a1b34727b1b445 (patch) | |
tree | 433be5b3c901da4a58721f9fe45242ff483ce603 /server/sonar-web/src/main/js/app/components/nav/component/ComponentNavLicenseNotif.tsx | |
parent | 76ff58d995313f600ec7ae5341a52e0a4150b70f (diff) | |
download | sonarqube-ef66ee089dbbda4441dab0d262a1b34727b1b445.tar.gz sonarqube-ef66ee089dbbda4441dab0d262a1b34727b1b445.zip |
SONAR-10937 Change ‘invalid license’ message after updating license
Diffstat (limited to 'server/sonar-web/src/main/js/app/components/nav/component/ComponentNavLicenseNotif.tsx')
-rw-r--r-- | server/sonar-web/src/main/js/app/components/nav/component/ComponentNavLicenseNotif.tsx | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavLicenseNotif.tsx b/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavLicenseNotif.tsx new file mode 100644 index 00000000000..9a251ce316d --- /dev/null +++ b/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavLicenseNotif.tsx @@ -0,0 +1,102 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import * as React from 'react'; +import { Link } from 'react-router'; +import * as PropTypes from 'prop-types'; +import NavBarNotif from '../../../../components/nav/NavBarNotif'; +import { translate } from '../../../../helpers/l10n'; +import { Task } from '../../../../api/ce'; +import { isValidLicense } from '../../../../api/marketplace'; + +interface Props { + currentTask?: Task; +} + +interface State { + isValidLicense?: boolean; + loading: boolean; +} + +export default class ComponentNavLicenseNotif extends React.PureComponent<Props, State> { + mounted = false; + + static contextTypes = { + canAdmin: PropTypes.bool.isRequired + }; + + state: State = { loading: false }; + + componentDidMount() { + this.mounted = true; + this.fetchIsValidLicense(); + } + + componentWillUnmount() { + this.mounted = false; + } + + fetchIsValidLicense = () => { + this.setState({ loading: true }); + isValidLicense().then( + ({ isValidLicense }) => { + if (this.mounted) { + this.setState({ isValidLicense, loading: false }); + } + }, + () => { + if (this.mounted) { + this.setState({ loading: false }); + } + } + ); + }; + + render() { + const { currentTask } = this.props; + const { isValidLicense, loading } = this.state; + + if (loading || !currentTask || !currentTask.errorType) { + return null; + } + + if (isValidLicense && currentTask.errorType !== 'LICENSING_LOC') { + return ( + <NavBarNotif className="alert alert-danger"> + <span className="little-spacer-right"> + {translate('component_navigation.status.last_blocked_due_to_bad_license')} + </span> + </NavBarNotif> + ); + } + + return ( + <NavBarNotif className="alert alert-danger"> + <span className="little-spacer-right">{currentTask.errorMessage}</span> + {this.context.canAdmin ? ( + <Link to="/admin/extension/license/app"> + {translate('license.component_navigation.button', currentTask.errorType)}. + </Link> + ) : ( + translate('please_contact_administrator') + )} + </NavBarNotif> + ); + } +} |