diff --git a/superset-frontend/src/constants.ts b/superset-frontend/src/constants.ts index 4d8d4590fed4..8bbd14e93c1e 100644 --- a/superset-frontend/src/constants.ts +++ b/superset-frontend/src/constants.ts @@ -103,6 +103,10 @@ export const URL_PARAMS = { name: 'focused_chart', type: 'number', }, + editMode: { + name: 'edit', + type: 'boolean', + }, } as const; export const RESERVED_CHART_URL_PARAMS: string[] = [ @@ -117,6 +121,7 @@ export const RESERVED_DASHBOARD_URL_PARAMS: string[] = [ URL_PARAMS.nativeFiltersKey.name, URL_PARAMS.permalinkKey.name, URL_PARAMS.preselectFilters.name, + URL_PARAMS.editMode.name, ]; export const DEFAULT_COMMON_BOOTSTRAP_DATA: CommonBootstrapData = { diff --git a/superset-frontend/src/dashboard/hooks/useDownloadScreenshot.ts b/superset-frontend/src/dashboard/hooks/useDownloadScreenshot.ts index f3b21691b39f..7453e46984a0 100644 --- a/superset-frontend/src/dashboard/hooks/useDownloadScreenshot.ts +++ b/superset-frontend/src/dashboard/hooks/useDownloadScreenshot.ts @@ -153,7 +153,7 @@ export const useDownloadScreenshot = ( anchor, activeTabs, dataMask, - urlParams: getDashboardUrlParams(['edit']), + urlParams: getDashboardUrlParams(), }, }) .then(({ json }) => { diff --git a/superset-frontend/src/utils/urlUtils.test.ts b/superset-frontend/src/utils/urlUtils.test.ts index d6f981fff677..e81d890d8738 100644 --- a/superset-frontend/src/utils/urlUtils.test.ts +++ b/superset-frontend/src/utils/urlUtils.test.ts @@ -17,7 +17,12 @@ * under the License. */ -import { isUrlExternal, parseUrl, toQueryString } from './urlUtils'; +import { + isUrlExternal, + parseUrl, + toQueryString, + getDashboardUrlParams, +} from './urlUtils'; test('isUrlExternal', () => { expect(isUrlExternal('http://google.com')).toBeTruthy(); @@ -95,3 +100,48 @@ test('toQueryString should handle special characters in keys and values', () => '?user%40domain=me%26you', ); }); + +test('getDashboardUrlParams should exclude edit parameter by default', () => { + // Mock window.location.search to include edit parameter + const originalLocation = window.location; + Object.defineProperty(window, 'location', { + value: { + ...originalLocation, + search: '?edit=true&standalone=false&expand_filters=1', + }, + writable: true, + }); + + const urlParams = getDashboardUrlParams(['edit']); + const paramNames = urlParams.map(([key]) => key); + + expect(paramNames).not.toContain('edit'); + expect(paramNames).toContain('standalone'); + expect(paramNames).toContain('expand_filters'); + + // Restore original location + window.location = originalLocation; +}); + +test('getDashboardUrlParams should exclude multiple parameters when provided', () => { + // Mock window.location.search with multiple parameters + const originalLocation = window.location; + Object.defineProperty(window, 'location', { + value: { + ...originalLocation, + search: '?edit=true&standalone=false&debug=true&test=value', + }, + writable: true, + }); + + const urlParams = getDashboardUrlParams(['edit', 'debug']); + const paramNames = urlParams.map(([key]) => key); + + expect(paramNames).not.toContain('edit'); + expect(paramNames).not.toContain('debug'); + expect(paramNames).toContain('standalone'); + expect(paramNames).toContain('test'); + + // Restore original location + window.location = originalLocation; +});