Skip to content

Commit

Permalink
feat: Improve state key generation for dashboards and charts (#18576)
Browse files Browse the repository at this point in the history
* feat: Improve state key generation for dashboards and charts
  • Loading branch information
michael-s-molina committed Feb 14, 2022
1 parent 801091b commit 48a8095
Show file tree
Hide file tree
Showing 29 changed files with 694 additions and 234 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ describe('nativefiler url param key', () => {
cy.login();
cy.visit(WORLD_HEALTH_DASHBOARD);
WORLD_HEALTH_CHARTS.forEach(waitForChartLoad);
});
beforeEach(() => {
cy.login();
cy.wait(1000); // wait for key to be published (debounced)
});
let initialFilterKey: string;
it('should have cachekey in nativefilter param', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ describe('Nativefilters Sanity test', () => {
cy.location().then(loc => {
const queryParams = qs.parse(removeFirstChar(loc.search));
const newfilterKey = queryParams.native_filters_key;
expect(newfilterKey).not.eq(filterKey);
expect(newfilterKey).eq(filterKey);
});
cy.wait(3000);
cy.get(nativeFilters.modal.container).should('not.exist');
Expand Down
132 changes: 112 additions & 20 deletions superset-frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions superset-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
"bootstrap": "^3.4.1",
"bootstrap-slider": "^10.0.0",
"brace": "^0.11.1",
"broadcast-channel": "^4.10.0",
"chrono-node": "^2.2.6",
"classnames": "^2.2.5",
"core-js": "^3.6.5",
Expand Down
7 changes: 7 additions & 0 deletions superset-frontend/spec/helpers/shim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,10 @@ g.$ = jQuery(g.window);

configureTranslation();
setupSupersetClient();

// The useTabId hook depends on BroadcastChannel. Jest has a memory leak problem when
// dealing with native modules. See https://chanind.github.io/javascript/2019/10/12/jest-tests-memory-leak.html
// and https://github.com/facebook/jest/issues/6814 for more information.
jest.mock('src/hooks/useTabId', () => ({
useTabId: () => 1,
}));
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,15 @@ export default class Chart extends React.Component {

onExploreChart = async () => {
try {
const lastTabId = window.localStorage.getItem('last_tab_id');
const nextTabId = lastTabId
? String(Number.parseInt(lastTabId, 10) + 1)
: undefined;
const key = await postFormData(
this.props.datasource.id,
this.props.formData,
this.props.slice.slice_id,
nextTabId,
);
const url = mountExploreUrl(null, {
[URL_PARAMS.formDataKey.name]: key,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { t, logging } from '@superset-ui/core';
import { Menu } from 'src/common/components';
import { getUrlParam } from 'src/utils/urlUtils';
import { postFormData } from 'src/explore/exploreUtils/formData';
import { useTabId } from 'src/hooks/useTabId';
import { URL_PARAMS } from 'src/constants';
import { mountExploreUrl } from 'src/explore/exploreUtils';
import {
Expand Down Expand Up @@ -56,6 +57,8 @@ const ShareMenuItems = (props: ShareMenuItemProps) => {
...rest
} = props;

const tabId = useTabId();

const getShortUrl = useUrlShortener(url || '');

async function getCopyUrl() {
Expand All @@ -68,6 +71,7 @@ const ShareMenuItems = (props: ShareMenuItemProps) => {
const newDataMaskKey = await createFilterKey(
dashboardId,
JSON.stringify(prevData),
tabId,
);
const newUrl = new URL(`${window.location.origin}${url}`);
newUrl.searchParams.set(URL_PARAMS.nativeFilters.name, newDataMaskKey);
Expand All @@ -80,6 +84,7 @@ const ShareMenuItems = (props: ShareMenuItemProps) => {
parseInt(formData.datasource.split('_')[0], 10),
formData,
formData.slice_id,
tabId,
);
return `${window.location.origin}${mountExploreUrl(null, {
[URL_PARAMS.formDataKey.name]: key,
Expand Down
Loading

0 comments on commit 48a8095

Please sign in to comment.