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: replace datamask with key from new key value api #17680

Merged
merged 32 commits into from
Dec 21, 2021
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
5655338
afirst stage to ccheck to get initial datamask
pkdotson Dec 7, 2021
94db318
clean up code and update typescript
pkdotson Dec 8, 2021
38461bb
remove consoles
pkdotson Dec 8, 2021
b08a472
fix ts and update copy dashboard url
pkdotson Dec 8, 2021
6420292
use key when one doesn't exists
pkdotson Dec 8, 2021
3ce45d1
lint clean up
pkdotson Dec 9, 2021
dfb050f
fix errors
pkdotson Dec 10, 2021
e7ccfb7
add suggested changes
pkdotson Dec 14, 2021
e4b3830
remove line
pkdotson Dec 14, 2021
548a5bb
add tests and add changes for copydashboard
pkdotson Dec 15, 2021
abd4a86
fix lint
pkdotson Dec 15, 2021
cac4bea
fix lint
pkdotson Dec 15, 2021
cc443ef
fix lint
pkdotson Dec 15, 2021
0ce2bae
Update superset-frontend/src/dashboard/components/Header/index.jsx
pkdotson Dec 15, 2021
d87db08
Merge branch 'master' of https://github.com/preset-io/superset into f…
pkdotson Dec 15, 2021
cc3dd9c
add timeout
pkdotson Dec 15, 2021
d12b370
fix test
pkdotson Dec 16, 2021
ee2982c
Merge branch 'master' of https://github.com/preset-io/superset into f…
pkdotson Dec 16, 2021
2af1863
fix test, add qs to cypress and add suggestions
pkdotson Dec 17, 2021
ba64b39
add suggestions
pkdotson Dec 17, 2021
b3db570
fix lint
pkdotson Dec 17, 2021
9c58035
more suggested changes for backwards comapat
pkdotson Dec 17, 2021
63672e8
fix lint
pkdotson Dec 17, 2021
67193e1
cleanup naming and add qs parse to tests
pkdotson Dec 17, 2021
957fe20
Update superset-frontend/src/dashboard/components/menu/ShareMenuItems…
pkdotson Dec 17, 2021
a9dfb14
Update superset-frontend/src/dashboard/components/menu/ShareMenuItems…
pkdotson Dec 17, 2021
fc7ef7b
more changes and fix lint
pkdotson Dec 17, 2021
c74b8d5
Merge branch 'frontend-dashboard-longurl-2' of https://github.com/pre…
pkdotson Dec 17, 2021
a683b2d
remove nativefiler param
pkdotson Dec 17, 2021
0c9163a
fix path
pkdotson Dec 17, 2021
8e19e18
remove con
pkdotson Dec 17, 2021
40d7343
simplify logic
pkdotson Dec 20, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import qs from 'querystringify';
import {
WORLD_HEALTH_DASHBOARD,
WORLD_HEALTH_CHARTS,
waitForChartLoad,
} from './dashboard.helper';

interface QueryString {
native_filters_key: string;
}

describe('nativefiler url param key', () => {
// const urlParams = { param1: '123', param2: 'abc' };
before(() => {
cy.login();
cy.visit(WORLD_HEALTH_DASHBOARD);
WORLD_HEALTH_CHARTS.forEach(waitForChartLoad);
});
beforeEach(() => {
cy.login();
});
let initialFilterKey: string;
it('should have cachekey in nativefilter param', () => {
cy.location().then(loc => {
const queryParams = qs.parse(loc.search) as QueryString;
expect(typeof queryParams.native_filters_key).eq('string');
});
});

it('should have different key when page reloads', () => {
cy.location().then(loc => {
const queryParams = qs.parse(loc.search) as QueryString;
expect(queryParams.native_filters_key).not.equal(initialFilterKey);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import qs from 'querystring';
import { dashboardView, nativeFilters } from 'cypress/support/directories';
import { testItems } from './dashboard.helper';
import { DASHBOARD_LIST } from '../dashboard_list/dashboard_list.helper';
Expand Down Expand Up @@ -93,6 +94,15 @@ describe('Nativefilters Sanity test', () => {
cy.get(nativeFilters.modal.container).should('be.visible');
});
it('User can add a new native filter', () => {
let filterKey: string;
const removeFirstChar = (search: string) =>
search.split('').slice(1, search.length).join('');
cy.wait(3000);
cy.location().then(loc => {
const queryParams = qs.parse(removeFirstChar(loc.search));
filterKey = queryParams.native_filters_key as string;
expect(typeof filterKey).eq('string');
});
cy.get(nativeFilters.filterFromDashboardView.expand).click({ force: true });
cy.get(nativeFilters.createFilterButton).should('be.visible').click();
cy.get(nativeFilters.modal.container)
Expand All @@ -115,7 +125,7 @@ describe('Nativefilters Sanity test', () => {
cy.wait(5000);
cy.get(nativeFilters.filtersPanel.filterInfoInput)
.last()
.should('be.visible')
.should('be.visible', { timeout: 30000 })
.click({ force: true });
cy.get(nativeFilters.filtersPanel.filterInfoInput)
.last()
Expand All @@ -128,6 +138,13 @@ describe('Nativefilters Sanity test', () => {
.contains('Save')
.should('be.visible')
.click();
cy.wait(3000);
cy.location().then(loc => {
const queryParams = qs.parse(removeFirstChar(loc.search));
const newfilterKey = queryParams.native_filters_key;
expect(newfilterKey).not.eq(filterKey);
});
cy.wait(3000);
cy.get(nativeFilters.modal.container).should('not.exist');
});
it('User can delete a native filter', () => {
Expand Down
24 changes: 24 additions & 0 deletions superset-frontend/cypress-base/package-lock.json

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

2 changes: 2 additions & 0 deletions superset-frontend/cypress-base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
"dependencies": {
"@cypress/code-coverage": "^3.9.11",
"@superset-ui/core": "^0.18.8",
"querystringify": "^2.2.0",
"react-dom": "^16.13.0",
"rison": "^0.1.1",
"shortid": "^2.2.15"
},
"devDependencies": {
"@types/querystringify": "^2.0.0",
"cypress": "^7.0.0",
"eslint-plugin-cypress": "^2.12.1"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,25 +73,21 @@ describe('getChartIdsFromLayout', () => {
);
});

it('should encode native filters', () => {
it('should process native filters key', () => {
const windowSpy = jest.spyOn(window, 'window', 'get');
windowSpy.mockImplementation(() => ({
location: {
origin: 'https://localhost',
search:
'?preselect_filters=%7B%7D&native_filters_key=024380498jdkjf-2094838',
},
}));

const urlWithNativeFilters = getDashboardUrl({
pathname: 'path',
dataMask: {
'NATIVE_FILTER-foo123': {
filterState: {
label: 'custom label',
value: ['a', 'b'],
},
},
'NATIVE_FILTER-bar456': {
filterState: {
value: undefined,
},
},
},
});
expect(urlWithNativeFilters).toBe(
'path?preselect_filters=%7B%7D&native_filters=%28NATIVE_FILTER-bar456%3A%28filterState%3A%28value%3A%21n%29%29%2CNATIVE_FILTER-foo123%3A%28filterState%3A%28label%3A%27custom+label%27%2Cvalue%3A%21%28a%2Cb%29%29%29%29',
'path?preselect_filters=%7B%7D&native_filters_key=024380498jdkjf-2094838',
);
});
});
4 changes: 2 additions & 2 deletions superset-frontend/src/common/hooks/useUrlShortener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ export function useUrlShortener(url: string): Function {
const [update, setUpdate] = useState(false);
const [shortUrl, setShortUrl] = useState('');

async function getShortUrl() {
async function getShortUrl(urlOverride?: string) {
if (update) {
const newShortUrl = await getShortUrlUtil(url);
const newShortUrl = await getShortUrlUtil(urlOverride || url);
setShortUrl(newShortUrl);
setUpdate(false);
return newShortUrl;
Expand Down
4 changes: 4 additions & 0 deletions superset-frontend/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ export const URL_PARAMS = {
name: 'native_filters',
type: 'rison',
},
nativeFiltersKey: {
name: 'native_filters_key',
type: 'string',
},
filterSet: {
name: 'filter_set',
type: 'string',
Expand Down
6 changes: 4 additions & 2 deletions superset-frontend/src/dashboard/actions/hydrate.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export const hydrateDashboard =
dashboardData,
chartData,
filterboxMigrationState = FILTER_BOX_MIGRATION_STATES.NOOP,
dataMaskApplied,
) =>
(dispatch, getState) => {
const { user, common } = getState();
Expand Down Expand Up @@ -378,10 +379,11 @@ export const hydrateDashboard =
slice_can_edit: findPermission('can_slice', 'Superset', roles),
common: {
// legacy, please use state.common instead
flash_messages: common.flash_messages,
conf: common.conf,
flash_messages: common?.flash_messages,
conf: common?.conf,
},
},
dataMask: dataMaskApplied,
dashboardFilters,
nativeFilters,
dashboardState: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ const DashboardBuilder: FC<DashboardBuilderProps> = () => {
);

const dashboardRoot = dashboardLayout[DASHBOARD_ROOT_ID];
const rootChildId = dashboardRoot.children[0];
const rootChildId = dashboardRoot?.children[0];
const topLevelTabs =
rootChildId !== DASHBOARD_GRID_ID
? dashboardLayout[rootChildId]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import findTabIndexByComponentId from 'src/dashboard/util/findTabIndexByComponen

export const getRootLevelTabsComponent = (dashboardLayout: DashboardLayout) => {
const dashboardRoot = dashboardLayout[DASHBOARD_ROOT_ID];
const rootChildId = dashboardRoot.children[0];
const rootChildId = dashboardRoot?.children[0];
return rootChildId === DASHBOARD_GRID_ID
? dashboardLayout[DASHBOARD_ROOT_ID]
: dashboardLayout[rootChildId];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ class HeaderActionsDropdown extends React.PureComponent {
dashboardTitle,
dashboardId,
dashboardInfo,
dataMask,
refreshFrequency,
shouldPersistRefreshFrequency,
editMode,
Expand All @@ -220,7 +219,6 @@ class HeaderActionsDropdown extends React.PureComponent {
const emailBody = t('Check out this dashboard: ');

const url = getDashboardUrl({
dataMask,
pathname: window.location.pathname,
filters: getActiveFilters(),
hash: window.location.hash,
Expand Down Expand Up @@ -266,6 +264,7 @@ class HeaderActionsDropdown extends React.PureComponent {
emailBody={emailBody}
addSuccessToast={addSuccessToast}
addDangerToast={addDangerToast}
dashboardId={dashboardId}
/>
)}
<Menu.Item
Expand Down
30 changes: 16 additions & 14 deletions superset-frontend/src/dashboard/components/Header/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,15 @@ class Header extends React.PureComponent {
this.startPeriodicRender(refreshFrequency * 1000);
if (this.canAddReports()) {
// this is in case there is an anonymous user.
this.props.fetchUISpecificReport(
user.userId,
'dashboard_id',
'dashboards',
dashboardInfo.id,
user.email,
);
if (Object.entries(dashboardInfo).length) {
this.props.fetchUISpecificReport(
user.userId,
'dashboard_id',
'dashboards',
dashboardInfo.id,
user.email,
);
}
}
}

Expand Down Expand Up @@ -211,11 +213,11 @@ class Header extends React.PureComponent {
) {
// this is in case there is an anonymous user.
this.props.fetchUISpecificReport(
user.userId,
user?.userId,
'dashboard_id',
'dashboards',
nextProps.dashboardInfo.id,
user.email,
nextProps?.dashboardInfo?.id,
user?.email,
);
}
}
Expand Down Expand Up @@ -488,10 +490,10 @@ class Header extends React.PureComponent {
filterboxMigrationState !== FILTER_BOX_MIGRATION_STATES.REVIEWING;
const shouldShowReport = !editMode && this.canAddReports();
const refreshLimit =
dashboardInfo.common.conf.SUPERSET_DASHBOARD_PERIODICAL_REFRESH_LIMIT;
dashboardInfo.common?.conf?.SUPERSET_DASHBOARD_PERIODICAL_REFRESH_LIMIT;
const refreshWarning =
dashboardInfo.common.conf
.SUPERSET_DASHBOARD_PERIODICAL_REFRESH_WARNING_MESSAGE;
dashboardInfo.common?.conf
?.SUPERSET_DASHBOARD_PERIODICAL_REFRESH_WARNING_MESSAGE;

const handleOnPropertiesChange = updates => {
const { dashboardInfoChanged, dashboardTitleChanged } = this.props;
Expand Down Expand Up @@ -529,7 +531,7 @@ class Header extends React.PureComponent {
canEdit={userCanEdit}
canSave={userCanSaveAs}
/>
{user?.userId && (
{user?.userId && dashboardInfo?.id && (
<FaveStar
itemId={dashboardInfo.id}
fetchFaveStar={this.props.fetchFaveStar}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@ import ShareMenuItems from '.';

const spy = jest.spyOn(copyTextToClipboard, 'default');

const DASHBOARD_ID = '26';
pkdotson marked this conversation as resolved.
Show resolved Hide resolved
const createProps = () => ({
addDangerToast: jest.fn(),
addSuccessToast: jest.fn(),
url: '/superset/dashboard/26/?preselect_filters=%7B%7D',
url: `/superset/dashboard/${DASHBOARD_ID}/?preselect_filters=%7B%7D`,
copyMenuItemTitle: 'Copy dashboard URL',
emailMenuItemTitle: 'Share dashboard by email',
emailSubject: 'Superset dashboard COVID Vaccine Dashboard',
emailBody: 'Check out this dashboard: ',
dashboardId: DASHBOARD_ID,
});

const { location } = window;
Expand Down