]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9936 Always allow to uninstall an edition except in cluster mode
authorGrégoire Aubert <gregoire.aubert@sonarsource.com>
Thu, 26 Oct 2017 07:07:48 +0000 (09:07 +0200)
committerGrégoire Aubert <gregoire.aubert@sonarsource.com>
Thu, 26 Oct 2017 09:38:26 +0000 (11:38 +0200)
server/sonar-web/src/main/js/apps/marketplace/App.tsx
server/sonar-web/src/main/js/apps/marketplace/EditionBoxes.tsx
server/sonar-web/src/main/js/apps/marketplace/__tests__/EditionBoxes-test.tsx
server/sonar-web/src/main/js/apps/marketplace/__tests__/__snapshots__/EditionBoxes-test.tsx.snap
server/sonar-web/src/main/js/apps/marketplace/components/EditionBox.tsx
server/sonar-web/src/main/js/apps/marketplace/components/__tests__/EditionBox-test.tsx

index 4d6f63fd28544de814ff64b92e799ef74606b33d..6ee7fd37bbc2e8711cb3e62a07e864a214b0b481 100644 (file)
@@ -168,10 +168,11 @@ export default class App extends React.PureComponent<Props, State> {
         </div>
         <Header />
         <EditionBoxes
+          canInstall={standaloneMode && !this.props.editionsReadOnly}
+          canUninstall={standaloneMode}
           editions={editions}
           loading={this.props.loadingEditions}
           editionStatus={editionStatus}
-          readOnly={!standaloneMode || this.props.editionsReadOnly}
           updateCenterActive={this.props.updateCenterActive}
           updateEditionStatus={this.props.setEditionStatus}
         />
index 4ff89c08e93802041c9d8e43ad1c531dfe0864c2..d8a0a5e353368598f63eb4da4e20584018b4eb6b 100644 (file)
@@ -26,10 +26,11 @@ import { Edition, EditionStatus } from '../../api/marketplace';
 import { translate } from '../../helpers/l10n';
 
 export interface Props {
+  canInstall: boolean;
+  canUninstall: boolean;
   editions?: Edition[];
   editionStatus?: EditionStatus;
   loading: boolean;
-  readOnly: boolean;
   updateCenterActive: boolean;
   updateEditionStatus: (editionStatus: EditionStatus) => void;
 }
@@ -49,7 +50,7 @@ export default class EditionBoxes extends React.PureComponent<Props, State> {
   handleCloseUninstallForm = () => this.setState({ openUninstallForm: false });
 
   render() {
-    const { editions, editionStatus, loading, readOnly } = this.props;
+    const { canInstall, canUninstall, editions, editionStatus, loading } = this.props;
     const { installEdition, openUninstallForm } = this.state;
     if (loading) {
       return <i className="big-spacer-bottom spinner" />;
@@ -79,16 +80,17 @@ export default class EditionBoxes extends React.PureComponent<Props, State> {
       <div className="spacer-bottom marketplace-editions">
         {editions.map(edition => (
           <EditionBox
+            canInstall={canInstall}
+            canUninstall={canUninstall}
             edition={edition}
             editionStatus={editionStatus}
             key={edition.key}
             onInstall={this.handleOpenLicenseForm}
             onUninstall={this.handleOpenUninstallForm}
-            readOnly={readOnly}
           />
         ))}
 
-        {!readOnly &&
+        {canInstall &&
         installEdition && (
           <LicenseEditionForm
             edition={installEdition}
@@ -98,7 +100,7 @@ export default class EditionBoxes extends React.PureComponent<Props, State> {
           />
         )}
 
-        {!readOnly &&
+        {canUninstall &&
         openUninstallForm &&
         editionStatus &&
         editionStatus.currentEditionKey && (
index c0347bf9ad496a22c92f0b121e8ce7c97da35437..fe3880cc9f0bcea1a0889b53b4f56dd1e0760f9f 100644 (file)
@@ -68,9 +68,10 @@ it('should open the license form', () => {
 function getWrapper(props = {}) {
   return shallow(
     <EditionBoxes
+      canInstall={true}
+      canUninstall={true}
       loading={false}
       editionStatus={DEFAULT_STATUS}
-      readOnly={false}
       updateCenterActive={true}
       updateEditionStatus={jest.fn()}
       {...props}
index ff2c1e86a34ddbd51b4fa928eee56b1460700084..f9b86d68f00b550b2080198d25bfc7bc95e6a268 100644 (file)
@@ -36,6 +36,8 @@ exports[`should display the edition boxes 2`] = `
   className="spacer-bottom marketplace-editions"
 >
   <EditionBox
+    canInstall={true}
+    canUninstall={true}
     edition={
       Object {
         "downloadUrl": "download_url",
@@ -55,9 +57,10 @@ exports[`should display the edition boxes 2`] = `
     }
     onInstall={[Function]}
     onUninstall={[Function]}
-    readOnly={false}
   />
   <EditionBox
+    canInstall={true}
+    canUninstall={true}
     edition={
       Object {
         "downloadUrl": "download_url",
@@ -77,7 +80,6 @@ exports[`should display the edition boxes 2`] = `
     }
     onInstall={[Function]}
     onUninstall={[Function]}
-    readOnly={false}
   />
 </div>
 `;
index 27130a159a4997e3798dce6972763e448f2fd77d..ca8457fe4d137e6fc531ea3dcad2bd0a5ace4c31 100644 (file)
@@ -23,11 +23,12 @@ import { Edition, EditionStatus } from '../../../api/marketplace';
 import { translate } from '../../../helpers/l10n';
 
 interface Props {
+  canInstall: boolean;
+  canUninstall: boolean;
   edition: Edition;
   editionStatus?: EditionStatus;
   onInstall: (edition: Edition) => void;
   onUninstall: () => void;
-  readOnly: boolean;
 }
 
 export default class EditionBox extends React.PureComponent<Props> {
@@ -57,7 +58,7 @@ export default class EditionBox extends React.PureComponent<Props> {
   }
 
   render() {
-    const { edition, editionStatus, readOnly } = this.props;
+    const { canInstall, canUninstall, edition, editionStatus } = this.props;
     const isInstalled = editionStatus && editionStatus.currentEditionKey === edition.key;
     const uninstallInProgress =
       editionStatus && editionStatus.installationStatus === 'UNINSTALL_IN_PROGRESS';
@@ -75,21 +76,23 @@ export default class EditionBox extends React.PureComponent<Props> {
           <a href={edition.homeUrl} target="_blank">
             {translate('marketplace.learn_more')}
           </a>
-          {!readOnly &&
-            (isInstalled ? (
-              <button
-                className="button-red"
-                disabled={installInProgress || uninstallInProgress}
-                onClick={this.props.onUninstall}>
-                {translate('marketplace.uninstall')}
-              </button>
-            ) : (
-              <button
-                disabled={installInProgress || uninstallInProgress}
-                onClick={this.handleInstall}>
-                {translate('marketplace.install')}
-              </button>
-            ))}
+          {canUninstall &&
+          isInstalled && (
+            <button
+              className="button-red"
+              disabled={installInProgress || uninstallInProgress}
+              onClick={this.props.onUninstall}>
+              {translate('marketplace.uninstall')}
+            </button>
+          )}
+          {canInstall &&
+          !isInstalled && (
+            <button
+              disabled={installInProgress || uninstallInProgress}
+              onClick={this.handleInstall}>
+              {translate('marketplace.install')}
+            </button>
+          )}
         </div>
       </div>
     );
index fbc88c1deb4ce30aeecf24f190ddba1a00dfef94..dbfa141f629f5dd510f09aeb6fd75b27413877d3 100644 (file)
@@ -113,11 +113,12 @@ it('should disable uninstall button', () => {
 function getWrapper(props = {}) {
   return shallow(
     <EditionBox
+      canInstall={true}
+      canUninstall={true}
       edition={DEFAULT_EDITION}
       editionStatus={DEFAULT_STATUS}
       onInstall={jest.fn()}
       onUninstall={jest.fn()}
-      readOnly={false}
       {...props}
     />
   );