]> source.dussan.org Git - sonarqube.git/commitdiff
LICENSE-72 Update set license component to work without an edition
authorGrégoire Aubert <gregoire.aubert@sonarsource.com>
Wed, 18 Oct 2017 10:23:17 +0000 (12:23 +0200)
committerGrégoire Aubert <gregoire.aubert@sonarsource.com>
Mon, 23 Oct 2017 15:01:13 +0000 (08:01 -0700)
server/sonar-web/src/main/js/apps/marketplace/EditionBoxes.tsx
server/sonar-web/src/main/js/apps/marketplace/components/LicenseEditionForm.tsx
server/sonar-web/src/main/js/apps/marketplace/components/LicenseEditionSet.tsx
server/sonar-web/src/main/js/apps/marketplace/components/__tests__/LicenseEditionForm-test.tsx
server/sonar-web/src/main/js/apps/marketplace/components/__tests__/LicenseEditionSet-test.tsx
server/sonar-web/src/main/js/apps/marketplace/components/__tests__/__snapshots__/LicenseEditionForm-test.tsx.snap
server/sonar-web/src/main/js/apps/marketplace/components/__tests__/__snapshots__/LicenseEditionSet-test.tsx.snap

index e1f5f373f1f7b0c02fd9edfe3bc6ab737e4a11e0..88fc6f4cebcb221607a7fa82d351d12872adef82 100644 (file)
@@ -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}
           />
index fb513eba0bc58d2b2e4afa7bc8b063bd629d56ab..857a40e40581ea0c34e8d8dcda17801292b571ec 100644 (file)
@@ -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>
           )}
index 7b74d6b6bcf2d5334f8dfe6c8ba82305f5ed4ebd..76cbc297483fa8b218206c553ce896e7c9dd5607 100644 (file)
@@ -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>
     );
   }
index a08b002a718a735b737a5225d66e794c2d9be233..f1b0952650d2fb50fd79fa1b944eed3924ece15b 100644 (file)
@@ -77,6 +77,7 @@ function getWrapper(props = {}) {
   return shallow(
     <LicenseEditionForm
       edition={DEFAULT_EDITION}
+      editions={[DEFAULT_EDITION]}
       onClose={jest.fn()}
       updateEditionStatus={jest.fn()}
       {...props}
index 3e1d45ac3e01ce411b19f482cfc9c97a417353a8..4e6828939685c978e9d0af7246cc9835fc4b0cce 100644 (file)
@@ -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}
+    />
   );
 }
 
index e6dde0fb6ede056b2d02a33188458cabf79093b4..e657d2c1ee2980ba32ed1e564f22b433d746177e 100644 (file)
@@ -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
index 9b89e852330d05a9795758041556053aae9a3c6c..6ba3dd639b29ff83922594e389544337d590965e 100644 (file)
@@ -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]}