aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web
diff options
context:
space:
mode:
authorGrégoire Aubert <gregoire.aubert@sonarsource.com>2017-10-18 12:23:17 +0200
committerGrégoire Aubert <gregoire.aubert@sonarsource.com>2017-10-23 08:01:13 -0700
commitacfe2c272eb11a08eac296ba50fd57c632d6cec3 (patch)
tree6feb1810b8dee67ed312571e851cf79abf743f0a /server/sonar-web
parente013b2b9a6f1afb120722eaf422081a136eb0cfd (diff)
downloadsonarqube-acfe2c272eb11a08eac296ba50fd57c632d6cec3.tar.gz
sonarqube-acfe2c272eb11a08eac296ba50fd57c632d6cec3.zip
LICENSE-72 Update set license component to work without an edition
Diffstat (limited to 'server/sonar-web')
-rw-r--r--server/sonar-web/src/main/js/apps/marketplace/EditionBoxes.tsx4
-rw-r--r--server/sonar-web/src/main/js/apps/marketplace/components/LicenseEditionForm.tsx8
-rw-r--r--server/sonar-web/src/main/js/apps/marketplace/components/LicenseEditionSet.tsx60
-rw-r--r--server/sonar-web/src/main/js/apps/marketplace/components/__tests__/LicenseEditionForm-test.tsx1
-rw-r--r--server/sonar-web/src/main/js/apps/marketplace/components/__tests__/LicenseEditionSet-test.tsx7
-rw-r--r--server/sonar-web/src/main/js/apps/marketplace/components/__tests__/__snapshots__/LicenseEditionForm-test.tsx.snap14
-rw-r--r--server/sonar-web/src/main/js/apps/marketplace/components/__tests__/__snapshots__/LicenseEditionSet-test.tsx.snap3
7 files changed, 67 insertions, 30 deletions
diff --git a/server/sonar-web/src/main/js/apps/marketplace/EditionBoxes.tsx b/server/sonar-web/src/main/js/apps/marketplace/EditionBoxes.tsx
index e1f5f373f1f..88fc6f4cebc 100644
--- a/server/sonar-web/src/main/js/apps/marketplace/EditionBoxes.tsx
+++ b/server/sonar-web/src/main/js/apps/marketplace/EditionBoxes.tsx
@@ -108,9 +108,11 @@ export default class EditionBoxes extends React.PureComponent<Props, State> {
))
)}
- {installEdition && (
+ {editions &&
+ installEdition && (
<LicenseEditionForm
edition={installEdition}
+ editions={editions}
onClose={this.handleCloseLicenseForm}
updateEditionStatus={this.props.updateEditionStatus}
/>
diff --git a/server/sonar-web/src/main/js/apps/marketplace/components/LicenseEditionForm.tsx b/server/sonar-web/src/main/js/apps/marketplace/components/LicenseEditionForm.tsx
index fb513eba0bc..857a40e4058 100644
--- a/server/sonar-web/src/main/js/apps/marketplace/components/LicenseEditionForm.tsx
+++ b/server/sonar-web/src/main/js/apps/marketplace/components/LicenseEditionForm.tsx
@@ -25,6 +25,7 @@ import { translate, translateWithParameters } from '../../../helpers/l10n';
export interface Props {
edition: Edition;
+ editions: Edition[];
onClose: () => void;
updateEditionStatus: (editionStatus: EditionStatus) => void;
}
@@ -79,7 +80,7 @@ export default class LicenseEditionForm extends React.PureComponent<Props, State
render() {
const { edition } = this.props;
- const { status } = this.state;
+ const { loading, status } = this.state;
const header = translateWithParameters('marketplace.install_x', edition.name);
return (
<Modal
@@ -95,14 +96,15 @@ export default class LicenseEditionForm extends React.PureComponent<Props, State
<LicenseEditionSet
className="modal-body"
edition={edition}
+ editions={this.props.editions}
updateLicense={this.handleLicenseChange}
/>
<footer className="modal-foot">
- {this.state.loading && <i className="spinner spacer-right" />}
+ {loading && <i className="spinner spacer-right" />}
{status &&
['NO_INSTALL', 'AUTOMATIC_INSTALL'].includes(status) && (
- <button className="js-confirm" onClick={this.handleConfirmClick}>
+ <button className="js-confirm" onClick={this.handleConfirmClick} disabled={loading}>
{status === 'NO_INSTALL' ? translate('save') : translate('marketplace.install')}
</button>
)}
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 7b74d6b6bcf..76cbc297483 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
@@ -25,12 +25,14 @@ import { translate, translateWithParameters } from '../../../helpers/l10n';
export interface Props {
className?: string;
- edition: Edition;
+ edition?: Edition;
+ editions: Edition[];
updateLicense: (license?: string, status?: string) => void;
}
interface State {
license: string;
+ licenseEdition?: Edition;
loading: boolean;
previewStatus?: string;
}
@@ -41,7 +43,7 @@ export default class LicenseEditionSet extends React.PureComponent<Props, State>
constructor(props: Props) {
super(props);
this.state = { license: '', loading: false };
- this.fetchLicensePreview = debounce(this.fetchLicensePreview, 250);
+ this.fetchLicensePreview = debounce(this.fetchLicensePreview, 100);
}
componentDidMount() {
@@ -54,14 +56,18 @@ export default class LicenseEditionSet extends React.PureComponent<Props, State>
fetchLicensePreview = (license: string) =>
getLicensePreview({ license }).then(
- r => {
+ ({ previewStatus, nextEditionKey }) => {
if (this.mounted) {
- this.updateLicense(license, r.previewStatus);
+ this.updateLicense(
+ license,
+ this.props.editions.find(edition => edition.key === nextEditionKey),
+ previewStatus
+ );
}
},
() => {
if (this.mounted) {
- this.updateLicense(license, undefined);
+ this.updateLicense(license, undefined, undefined);
}
}
);
@@ -72,35 +78,39 @@ export default class LicenseEditionSet extends React.PureComponent<Props, State>
this.fetchLicensePreview(license);
this.setState({ license });
} else {
- this.updateLicense(license, undefined);
+ this.updateLicense(license, undefined, undefined);
}
};
- updateLicense = (license: string, previewStatus?: string) => {
- this.setState({ license, previewStatus });
+ updateLicense = (license: string, licenseEdition?: Edition, previewStatus?: string) => {
+ this.setState({ license, licenseEdition, previewStatus });
this.props.updateLicense(license, previewStatus);
};
render() {
const { className, edition } = this.props;
- const { license, previewStatus } = this.state;
+ const { license, licenseEdition, previewStatus } = this.state;
+
return (
<div className={className}>
- <label htmlFor="set-license">
- {translateWithParameters('marketplace.enter_license_for_x', edition.name)}
- <em className="mandatory">*</em>
- </label>
+ {edition && (
+ <label className="spacer-bottom" htmlFor="set-license">
+ {translateWithParameters('marketplace.enter_license_for_x', edition.name)}
+ <em className="mandatory">*</em>
+ </label>
+ )}
<textarea
autoFocus={true}
id="set-license"
- className="spacer-top display-block"
+ className="display-block"
cols={62}
onChange={this.handleLicenseChange}
required={true}
rows={6}
value={license}
/>
- {previewStatus && (
+ {previewStatus &&
+ licenseEdition && (
<p
className={classNames('alert spacer-top', {
'alert-warning': previewStatus === 'AUTOMATIC_INSTALL',
@@ -109,14 +119,14 @@ export default class LicenseEditionSet extends React.PureComponent<Props, State>
})}>
{translateWithParameters(
'marketplace.license_preview_status.' + previewStatus,
- edition.name
+ licenseEdition.name
)}
{previewStatus === 'MANUAL_INSTALL' && (
<p className="spacer-top">
<a
className="button"
- download={`sonarqube-${edition.name}.zip`}
- href={edition.download_link}
+ download={`sonarqube-${licenseEdition.name}.zip`}
+ href={licenseEdition.download_link}
target="_blank">
{translate('marketplace.download_package')}
</a>
@@ -130,12 +140,14 @@ export default class LicenseEditionSet extends React.PureComponent<Props, State>
)}
</p>
)}
- <a
- className="display-inline-block spacer-top"
- href={edition.request_license_link}
- target="_blank">
- {translate('marketplace.i_need_a_license')}
- </a>
+ {edition && (
+ <a
+ className="display-inline-block spacer-top"
+ href={edition.request_license_link}
+ target="_blank">
+ {translate('marketplace.i_need_a_license')}
+ </a>
+ )}
</div>
);
}
diff --git a/server/sonar-web/src/main/js/apps/marketplace/components/__tests__/LicenseEditionForm-test.tsx b/server/sonar-web/src/main/js/apps/marketplace/components/__tests__/LicenseEditionForm-test.tsx
index a08b002a718..f1b0952650d 100644
--- a/server/sonar-web/src/main/js/apps/marketplace/components/__tests__/LicenseEditionForm-test.tsx
+++ b/server/sonar-web/src/main/js/apps/marketplace/components/__tests__/LicenseEditionForm-test.tsx
@@ -77,6 +77,7 @@ function getWrapper(props = {}) {
return shallow(
<LicenseEditionForm
edition={DEFAULT_EDITION}
+ editions={[DEFAULT_EDITION]}
onClose={jest.fn()}
updateEditionStatus={jest.fn()}
{...props}
diff --git a/server/sonar-web/src/main/js/apps/marketplace/components/__tests__/LicenseEditionSet-test.tsx b/server/sonar-web/src/main/js/apps/marketplace/components/__tests__/LicenseEditionSet-test.tsx
index 3e1d45ac3e0..4e682893968 100644
--- a/server/sonar-web/src/main/js/apps/marketplace/components/__tests__/LicenseEditionSet-test.tsx
+++ b/server/sonar-web/src/main/js/apps/marketplace/components/__tests__/LicenseEditionSet-test.tsx
@@ -63,7 +63,12 @@ it('should correctly display status message after checking license', async () =>
function getWrapper(props = {}) {
return shallow(
- <LicenseEditionSet edition={DEFAULT_EDITION} updateLicense={jest.fn()} {...props} />
+ <LicenseEditionSet
+ edition={DEFAULT_EDITION}
+ editions={[DEFAULT_EDITION]}
+ updateLicense={jest.fn()}
+ {...props}
+ />
);
}
diff --git a/server/sonar-web/src/main/js/apps/marketplace/components/__tests__/__snapshots__/LicenseEditionForm-test.tsx.snap b/server/sonar-web/src/main/js/apps/marketplace/components/__tests__/__snapshots__/LicenseEditionForm-test.tsx.snap
index e6dde0fb6ed..e657d2c1ee2 100644
--- a/server/sonar-web/src/main/js/apps/marketplace/components/__tests__/__snapshots__/LicenseEditionForm-test.tsx.snap
+++ b/server/sonar-web/src/main/js/apps/marketplace/components/__tests__/__snapshots__/LicenseEditionForm-test.tsx.snap
@@ -3,6 +3,7 @@
exports[`should correctly change the button based on the status 1`] = `
<button
className="js-confirm"
+ disabled={false}
onClick={[Function]}
>
save
@@ -12,6 +13,7 @@ exports[`should correctly change the button based on the status 1`] = `
exports[`should correctly change the button based on the status 2`] = `
<button
className="js-confirm"
+ disabled={false}
onClick={[Function]}
>
marketplace.install
@@ -51,6 +53,18 @@ exports[`should display correctly 1`] = `
"request_license_link": "license_url",
}
}
+ editions={
+ Array [
+ Object {
+ "desc": "Foo desc",
+ "download_link": "download_url",
+ "key": "foo",
+ "more_link": "more_url",
+ "name": "Foo",
+ "request_license_link": "license_url",
+ },
+ ]
+ }
updateLicense={[Function]}
/>
<footer
diff --git a/server/sonar-web/src/main/js/apps/marketplace/components/__tests__/__snapshots__/LicenseEditionSet-test.tsx.snap b/server/sonar-web/src/main/js/apps/marketplace/components/__tests__/__snapshots__/LicenseEditionSet-test.tsx.snap
index 9b89e852330..6ba3dd639b2 100644
--- a/server/sonar-web/src/main/js/apps/marketplace/components/__tests__/__snapshots__/LicenseEditionSet-test.tsx.snap
+++ b/server/sonar-web/src/main/js/apps/marketplace/components/__tests__/__snapshots__/LicenseEditionSet-test.tsx.snap
@@ -46,6 +46,7 @@ exports[`should correctly display status message after checking license 3`] = `
exports[`should display correctly 1`] = `
<div>
<label
+ className="spacer-bottom"
htmlFor="set-license"
>
marketplace.enter_license_for_x.Foo
@@ -57,7 +58,7 @@ exports[`should display correctly 1`] = `
</label>
<textarea
autoFocus={true}
- className="spacer-top display-block"
+ className="display-block"
cols={62}
id="set-license"
onChange={[Function]}