Ver código fonte

HUE-5528 [responsive] Remove type URL parameter when navigating away from the editor

Enrico Berti 9 anos atrás
pai
commit
e1aa39c

+ 8 - 2
desktop/core/src/desktop/static/desktop/js/hue.utils.js

@@ -205,15 +205,21 @@ if (!String.prototype.includes) {
           newSearch += p;
         }
       });
-      newSearch += (newSearch !== '?' ? '&' : '') + param + '=' + value;
+      if (value){
+        newSearch += (newSearch !== '?' ? '&' : '') + param + '=' + value;
+      }
     }
     else {
-      newSearch = window.location.search + (window.location.search.indexOf('?') > -1 ? '&' : '?') + param + '=' + value;
+      newSearch = window.location.search + (value ? (window.location.search.indexOf('?') > -1 ? '&' : '?') + param + '=' + value : '' );
     }
 
     hueUtils.changeURL(window.location.pathname + newSearch);
   }
 
+  hueUtils.removeURLParameter = function (param) {
+    hueUtils.changeURLParameter(param, null);
+  }
+
   /**
    * @param {string} pseudoJson
    * @constructor

+ 7 - 0
desktop/core/src/desktop/static/desktop/spec/hueUtilsSpec.js

@@ -49,5 +49,12 @@
       hueUtils.changeURL('/jasmine');
     });
 
+    it("should remove a parameter in the URL", function () {
+      hueUtils.changeURL('/banana?peeled=no');
+      hueUtils.removeURLParameter('peeled');
+      expect(window.location.search).toEqual('');
+      hueUtils.changeURL('/jasmine');
+    });
+
   });
 })();

+ 3 - 0
desktop/core/src/desktop/templates/responsive.mako

@@ -543,6 +543,9 @@ ${ assist.assistPanel() }
 
         self.currentApp.subscribe(function (newVal) {
           hueUtils.changeURLParameter('app', newVal);
+          if (newVal !== 'editor') {
+            hueUtils.removeURLParameter('type');
+          }
           self.isLoadingEmbeddable(true);
           if (typeof self.embeddable_cache[newVal] === 'undefined') {
             $.ajax({