Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Dashboard fullscreen is removing custom URL params #25028

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading