From dccad2bcd99c0bf006010c0bb8530310d1f4b812 Mon Sep 17 00:00:00 2001 From: Mehmet Salih Yavuz Date: Wed, 29 Oct 2025 16:03:39 +0300 Subject: [PATCH 1/6] fix(permalink): exclude edit mode from dashboard permalink --- superset-frontend/src/utils/urlUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/superset-frontend/src/utils/urlUtils.ts b/superset-frontend/src/utils/urlUtils.ts index 80e8948d22c1..0557d94515cf 100644 --- a/superset-frontend/src/utils/urlUtils.ts +++ b/superset-frontend/src/utils/urlUtils.ts @@ -179,7 +179,7 @@ export function getDashboardPermalink({ }) { // only encode filter state if non-empty return getPermalink(`/api/v1/dashboard/${dashboardId}/permalink`, { - urlParams: getDashboardUrlParams(), + urlParams: getDashboardUrlParams(['edit']), dataMask, activeTabs, anchor, From 8da9cba52eb4fdd012e9e7b6c50d27eb7cd5fe85 Mon Sep 17 00:00:00 2001 From: Mehmet Salih Yavuz Date: Mon, 10 Nov 2025 14:44:40 +0300 Subject: [PATCH 2/6] test: add tests --- superset-frontend/src/utils/urlUtils.test.ts | 69 +++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) diff --git a/superset-frontend/src/utils/urlUtils.test.ts b/superset-frontend/src/utils/urlUtils.test.ts index d6f981fff677..869d3f943cfb 100644 --- a/superset-frontend/src/utils/urlUtils.test.ts +++ b/superset-frontend/src/utils/urlUtils.test.ts @@ -17,7 +17,7 @@ * 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 +95,70 @@ 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 include edit parameter when not explicitly excluded', () => { + // Mock window.location.search to include edit parameter + const originalLocation = window.location; + Object.defineProperty(window, 'location', { + value: { + ...originalLocation, + search: '?edit=true&standalone=false', + }, + writable: true, + }); + + // Call without excluding edit parameter + const urlParams = getDashboardUrlParams([]); + const paramNames = urlParams.map(([key]) => key); + + expect(paramNames).toContain('edit'); + expect(paramNames).toContain('standalone'); + + // 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; +}); From d6b9e46b12f05de1015cc157095fef9dc776a9cb Mon Sep 17 00:00:00 2001 From: Mehmet Salih Yavuz Date: Mon, 10 Nov 2025 16:23:15 +0300 Subject: [PATCH 3/6] fix: format --- superset-frontend/src/utils/urlUtils.test.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/superset-frontend/src/utils/urlUtils.test.ts b/superset-frontend/src/utils/urlUtils.test.ts index 869d3f943cfb..c854d109928d 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, getDashboardUrlParams } from './urlUtils'; +import { + isUrlExternal, + parseUrl, + toQueryString, + getDashboardUrlParams, +} from './urlUtils'; test('isUrlExternal', () => { expect(isUrlExternal('http://google.com')).toBeTruthy(); @@ -109,7 +114,7 @@ test('getDashboardUrlParams should exclude edit parameter by default', () => { const urlParams = getDashboardUrlParams(['edit']); const paramNames = urlParams.map(([key]) => key); - + expect(paramNames).not.toContain('edit'); expect(paramNames).toContain('standalone'); expect(paramNames).toContain('expand_filters'); @@ -132,7 +137,7 @@ test('getDashboardUrlParams should include edit parameter when not explicitly ex // Call without excluding edit parameter const urlParams = getDashboardUrlParams([]); const paramNames = urlParams.map(([key]) => key); - + expect(paramNames).toContain('edit'); expect(paramNames).toContain('standalone'); @@ -153,7 +158,7 @@ test('getDashboardUrlParams should exclude multiple parameters when provided', ( 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'); From 7b457d31c2b4a9489a7c2659dc015d1cbc4e3812 Mon Sep 17 00:00:00 2001 From: Mehmet Salih Yavuz Date: Mon, 10 Nov 2025 21:09:06 +0300 Subject: [PATCH 4/6] refactor: use existing functionality --- superset-frontend/src/constants.ts | 5 +++++ .../src/dashboard/hooks/useDownloadScreenshot.ts | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) 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 }) => { From e340912aee41d4098acbf238c399ada5de538ead Mon Sep 17 00:00:00 2001 From: Mehmet Salih Yavuz Date: Mon, 10 Nov 2025 21:09:57 +0300 Subject: [PATCH 5/6] fix: remove leftover --- superset-frontend/src/utils/urlUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/superset-frontend/src/utils/urlUtils.ts b/superset-frontend/src/utils/urlUtils.ts index 13d4db5973e1..7b094b848403 100644 --- a/superset-frontend/src/utils/urlUtils.ts +++ b/superset-frontend/src/utils/urlUtils.ts @@ -188,7 +188,7 @@ export function getDashboardPermalink({ includeChartState?: boolean; }) { const payload: JsonObject = { - urlParams: getDashboardUrlParams(['edit']), + urlParams: getDashboardUrlParams(), dataMask, activeTabs, anchor, From 6f747625d6df09e4c8d655815279409d2c74cf41 Mon Sep 17 00:00:00 2001 From: Mehmet Salih Yavuz Date: Mon, 10 Nov 2025 22:34:19 +0300 Subject: [PATCH 6/6] chore: remove test --- superset-frontend/src/utils/urlUtils.test.ts | 22 -------------------- 1 file changed, 22 deletions(-) diff --git a/superset-frontend/src/utils/urlUtils.test.ts b/superset-frontend/src/utils/urlUtils.test.ts index c854d109928d..e81d890d8738 100644 --- a/superset-frontend/src/utils/urlUtils.test.ts +++ b/superset-frontend/src/utils/urlUtils.test.ts @@ -123,28 +123,6 @@ test('getDashboardUrlParams should exclude edit parameter by default', () => { window.location = originalLocation; }); -test('getDashboardUrlParams should include edit parameter when not explicitly excluded', () => { - // Mock window.location.search to include edit parameter - const originalLocation = window.location; - Object.defineProperty(window, 'location', { - value: { - ...originalLocation, - search: '?edit=true&standalone=false', - }, - writable: true, - }); - - // Call without excluding edit parameter - const urlParams = getDashboardUrlParams([]); - const paramNames = urlParams.map(([key]) => key); - - expect(paramNames).toContain('edit'); - expect(paramNames).toContain('standalone'); - - // 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;