Skip to content

Commit

Permalink
fix: Dashboard fullscreen is removing custom URL params (#25028)
Browse files Browse the repository at this point in the history
(cherry picked from commit 0be1754)
  • Loading branch information
michael-s-molina committed Aug 21, 2023
1 parent fad872f commit a5a027d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
30 changes: 30 additions & 0 deletions superset-frontend/src/dashboard/util/getDashboardUrl.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => ({
Expand All @@ -89,5 +118,6 @@ describe('getChartIdsFromLayout', () => {
expect(urlWithNativeFilters).toBe(
'path?preselect_filters=%7B%7D&native_filters_key=024380498jdkjf-2094838',
);
windowSpy.mockRestore();
});
});
20 changes: 13 additions & 7 deletions superset-frontend/src/dashboard/util/getDashboardUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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(
Expand Down

0 comments on commit a5a027d

Please sign in to comment.