From 91dc71dea47fa6e04063d807ebbcb807aca24ca1 Mon Sep 17 00:00:00 2001 From: Mike Bridge Date: Wed, 18 Nov 2026 14:11:17 -0600 Subject: [PATCH] fix(explore): hide SQL Lab links for semantic views --- .../ExploreChartHeader.test.tsx | 26 +++++++++++++++++++ .../DatasourceControl.test.tsx | 25 ++++++++++++++++++ .../controls/DatasourceControl/index.tsx | 6 ++++- .../useExploreAdditionalActionsMenu/index.tsx | 6 ++++- 4 files changed, 61 insertions(+), 2 deletions(-) diff --git a/superset-frontend/src/explore/components/ExploreChartHeader/ExploreChartHeader.test.tsx b/superset-frontend/src/explore/components/ExploreChartHeader/ExploreChartHeader.test.tsx index 8c8f3792744b..d31f8256a42d 100644 --- a/superset-frontend/src/explore/components/ExploreChartHeader/ExploreChartHeader.test.tsx +++ b/superset-frontend/src/explore/components/ExploreChartHeader/ExploreChartHeader.test.tsx @@ -877,6 +877,32 @@ describe('Additional actions tests', () => { }); }); + test.each( + ['semantic_view', 'table', 'query'].flatMap(type => + [true, false].map(saved => ({ type, saved })), + ), + )( + 'Explore SQL Lab action respects datasource $type (saved=$saved)', + async ({ type, saved }) => { + const props = createProps(saved ? {} : { slice: null }); + props.chart.latestQueryFormData = { + ...props.chart.latestQueryFormData, + datasource: `49__${type}`, + slice_id: saved ? 318 : undefined, + }; + render(, { useRedux: true }); + await userEvent.click( + await screen.findByLabelText('Menu actions trigger'), + ); + expect(await screen.findByText('View query')).toBeInTheDocument(); + if (type === 'semantic_view') { + expect(screen.queryByText('Run in SQL Lab')).not.toBeInTheDocument(); + } else { + expect(screen.getByText('Run in SQL Lab')).toBeInTheDocument(); + } + }, + ); + test('Should render a button', async () => { const props = createProps(); render(, { useRedux: true }); diff --git a/superset-frontend/src/explore/components/controls/DatasourceControl/DatasourceControl.test.tsx b/superset-frontend/src/explore/components/controls/DatasourceControl/DatasourceControl.test.tsx index eb8317a2d1bf..49b182a205ef 100644 --- a/superset-frontend/src/explore/components/controls/DatasourceControl/DatasourceControl.test.tsx +++ b/superset-frontend/src/explore/components/controls/DatasourceControl/DatasourceControl.test.tsx @@ -764,3 +764,28 @@ test('should verify DatasourceControl callback fires on save', async () => { // Note: Cross-component integration test removed due to complex Redux/user context setup // The existing callback tests provide sufficient coverage for metric creation workflows // Future enhancement could add MetricsControl integration when test infrastructure supports it + +test.each( + ['semantic_view', 'table', 'query'].flatMap(type => + [true, false].map(saved => ({ type, saved })), + ), +)( + 'datasource SQL Lab action respects datasource $type (saved=$saved)', + async ({ type, saved }) => { + const props = createProps({ + value: `25__${type}`, + datasource: { ...mockDatasource, type }, + form_data: saved ? { slice_id: 318 } : {}, + }); + render(, { useRouter: true }); + await userEvent.click(await screen.findByTestId('datasource-menu-trigger')); + if (type !== 'query') { + expect(await screen.findByText('Swap dataset')).toBeInTheDocument(); + } + if (type === 'semantic_view') { + expect(screen.queryByText('View in SQL Lab')).not.toBeInTheDocument(); + } else { + expect(screen.getByText('View in SQL Lab')).toBeInTheDocument(); + } + }, +); diff --git a/superset-frontend/src/explore/components/controls/DatasourceControl/index.tsx b/superset-frontend/src/explore/components/controls/DatasourceControl/index.tsx index bd0468134f0c..c47a35fd2fcc 100644 --- a/superset-frontend/src/explore/components/controls/DatasourceControl/index.tsx +++ b/superset-frontend/src/explore/components/controls/DatasourceControl/index.tsx @@ -398,7 +398,11 @@ export default function DatasourceControl({ label: t('Swap %s', datasetLabelLower()), }); - if (!isMissingDatasource && canAccessSqlLab) { + if ( + !isMissingDatasource && + canAccessSqlLab && + datasource.type !== DatasourceType.SemanticView + ) { defaultDatasourceMenuItems.push({ key: VIEW_IN_SQL_LAB, label: ( diff --git a/superset-frontend/src/explore/components/useExploreAdditionalActionsMenu/index.tsx b/superset-frontend/src/explore/components/useExploreAdditionalActionsMenu/index.tsx index 904e0c31ef36..c6f9d63f506d 100644 --- a/superset-frontend/src/explore/components/useExploreAdditionalActionsMenu/index.tsx +++ b/superset-frontend/src/explore/components/useExploreAdditionalActionsMenu/index.tsx @@ -33,6 +33,7 @@ import { JsonObject, LatestQueryFormData, QueryFormData, + DatasourceType, Behavior, getChartMetadataRegistry, } from '@superset-ui/core'; @@ -1175,7 +1176,10 @@ export const useExploreAdditionalActionsMenu = ( }); // Run in SQL Lab - if (datasource) { + if ( + datasource && + !datasource.endsWith(`__${DatasourceType.SemanticView}`) + ) { menuItems.push({ key: MENU_KEYS.RUN_IN_SQL_LAB, label: t('Run in SQL Lab'),