You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by mi...@apache.org on 2023/08/18 18:07:37 UTC

[superset] branch master updated: fix: Dashboard fullscreen is removing custom URL params (#25028)

This is an automated email from the ASF dual-hosted git repository.

michaelsmolina pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/master by this push:
     new 0be1754666 fix: Dashboard fullscreen is removing custom URL params (#25028)
0be1754666 is described below

commit 0be175466641c918564cc592b094c6861d088206
Author: Michael S. Molina <70...@users.noreply.github.com>
AuthorDate: Fri Aug 18 15:07:31 2023 -0300

    fix: Dashboard fullscreen is removing custom URL params (#25028)
---
 .../src/dashboard/util/getDashboardUrl.test.js     | 30 ++++++++++++++++++++++
 .../src/dashboard/util/getDashboardUrl.ts          | 20 ++++++++++-----
 2 files changed, 43 insertions(+), 7 deletions(-)

diff --git a/superset-frontend/src/dashboard/util/getDashboardUrl.test.js b/superset-frontend/src/dashboard/util/getDashboardUrl.test.js
index 653c17de89..c75f2c98b0 100644
--- a/superset-frontend/src/dashboard/util/getDashboardUrl.test.js
+++ b/superset-frontend/src/dashboard/util/getDashboardUrl.test.js
@@ -73,6 +73,35 @@ describe('getChartIdsFromLayout', () => {
     );
   });
 
+  it('should encode filters with missing filters', () => {
+    const urlWithStandalone = getDashboardUrl({
+      pathname: 'path',
+      filters: undefined,
+      standalone: DashboardStandaloneMode.HIDE_NAV,
+    });
+    expect(urlWithStandalone).toBe(
+      `path?standalone=${DashboardStandaloneMode.HIDE_NAV}`,
+    );
+  });
+
+  it('should preserve unknown filters', () => {
+    const windowSpy = jest.spyOn(window, 'window', 'get');
+    windowSpy.mockImplementation(() => ({
+      location: {
+        origin: 'https://localhost',
+        search: '?unkown_param=value',
+      },
+    }));
+    const urlWithStandalone = getDashboardUrl({
+      pathname: 'path',
+      standalone: DashboardStandaloneMode.HIDE_NAV,
+    });
+    expect(urlWithStandalone).toBe(
+      `path?unkown_param=value&standalone=${DashboardStandaloneMode.HIDE_NAV}`,
+    );
+    windowSpy.mockRestore();
+  });
+
   it('should process native filters key', () => {
     const windowSpy = jest.spyOn(window, 'window', 'get');
     windowSpy.mockImplementation(() => ({
@@ -89,5 +118,6 @@ describe('getChartIdsFromLayout', () => {
     expect(urlWithNativeFilters).toBe(
       'path?preselect_filters=%7B%7D&native_filters_key=024380498jdkjf-2094838',
     );
+    windowSpy.mockRestore();
   });
 });
diff --git a/superset-frontend/src/dashboard/util/getDashboardUrl.ts b/superset-frontend/src/dashboard/util/getDashboardUrl.ts
index 9c261e721d..bade710936 100644
--- a/superset-frontend/src/dashboard/util/getDashboardUrl.ts
+++ b/superset-frontend/src/dashboard/util/getDashboardUrl.ts
@@ -17,6 +17,7 @@
  * under the License.
  */
 import { JsonObject } from '@superset-ui/core';
+import { isEmpty } from 'lodash';
 import { URL_PARAMS } from 'src/constants';
 import { getUrlParam } from 'src/utils/urlUtils';
 import serializeActiveFilterValues from './serializeActiveFilterValues';
@@ -32,18 +33,23 @@ export default function getDashboardUrl({
   hash: string;
   standalone?: number | null;
 }) {
-  const newSearchParams = new URLSearchParams();
+  const newSearchParams = new URLSearchParams(window.location.search);
 
-  // convert flattened { [id_column]: values } object
-  // to nested filter object
-  newSearchParams.set(
-    URL_PARAMS.preselectFilters.name,
-    JSON.stringify(serializeActiveFilterValues(filters)),
-  );
+  if (!isEmpty(filters)) {
+    // convert flattened { [id_column]: values } object
+    // to nested filter object
+    newSearchParams.set(
+      URL_PARAMS.preselectFilters.name,
+      JSON.stringify(serializeActiveFilterValues(filters)),
+    );
+  }
 
   if (standalone) {
     newSearchParams.set(URL_PARAMS.standalone.name, standalone.toString());
+  } else {
+    newSearchParams.delete(URL_PARAMS.standalone.name);
   }
+
   const dataMaskKey = getUrlParam(URL_PARAMS.nativeFiltersKey);
   if (dataMaskKey) {
     newSearchParams.set(