Skip to content

Commit 87bad35

Browse files
authored
fix(explore): hide SQL Lab links for semantic views (#46336)
1 parent 5c9ba60 commit 87bad35

4 files changed

Lines changed: 61 additions & 2 deletions

File tree

‎superset-frontend/src/explore/components/ExploreChartHeader/ExploreChartHeader.test.tsx‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,32 @@ describe('Additional actions tests', () => {
877877
});
878878
});
879879

880+
test.each(
881+
['semantic_view', 'table', 'query'].flatMap(type =>
882+
[true, false].map(saved => ({ type, saved })),
883+
),
884+
)(
885+
'Explore SQL Lab action respects datasource $type (saved=$saved)',
886+
async ({ type, saved }) => {
887+
const props = createProps(saved ? {} : { slice: null });
888+
props.chart.latestQueryFormData = {
889+
...props.chart.latestQueryFormData,
890+
datasource: `49__${type}`,
891+
slice_id: saved ? 318 : undefined,
892+
};
893+
render(<ExploreHeader {...props} />, { useRedux: true });
894+
await userEvent.click(
895+
await screen.findByLabelText('Menu actions trigger'),
896+
);
897+
expect(await screen.findByText('View query')).toBeInTheDocument();
898+
if (type === 'semantic_view') {
899+
expect(screen.queryByText('Run in SQL Lab')).not.toBeInTheDocument();
900+
} else {
901+
expect(screen.getByText('Run in SQL Lab')).toBeInTheDocument();
902+
}
903+
},
904+
);
905+
880906
test('Should render a button', async () => {
881907
const props = createProps();
882908
render(<ExploreHeader {...props} />, { useRedux: true });

‎superset-frontend/src/explore/components/controls/DatasourceControl/DatasourceControl.test.tsx‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,3 +764,28 @@ test('should verify DatasourceControl callback fires on save', async () => {
764764
// Note: Cross-component integration test removed due to complex Redux/user context setup
765765
// The existing callback tests provide sufficient coverage for metric creation workflows
766766
// Future enhancement could add MetricsControl integration when test infrastructure supports it
767+
768+
test.each(
769+
['semantic_view', 'table', 'query'].flatMap(type =>
770+
[true, false].map(saved => ({ type, saved })),
771+
),
772+
)(
773+
'datasource SQL Lab action respects datasource $type (saved=$saved)',
774+
async ({ type, saved }) => {
775+
const props = createProps({
776+
value: `25__${type}`,
777+
datasource: { ...mockDatasource, type },
778+
form_data: saved ? { slice_id: 318 } : {},
779+
});
780+
render(<DatasourceControl {...props} />, { useRouter: true });
781+
await userEvent.click(await screen.findByTestId('datasource-menu-trigger'));
782+
if (type !== 'query') {
783+
expect(await screen.findByText('Swap dataset')).toBeInTheDocument();
784+
}
785+
if (type === 'semantic_view') {
786+
expect(screen.queryByText('View in SQL Lab')).not.toBeInTheDocument();
787+
} else {
788+
expect(screen.getByText('View in SQL Lab')).toBeInTheDocument();
789+
}
790+
},
791+
);

‎superset-frontend/src/explore/components/controls/DatasourceControl/index.tsx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,11 @@ export default function DatasourceControl({
398398
label: t('Swap %s', datasetLabelLower()),
399399
});
400400

401-
if (!isMissingDatasource && canAccessSqlLab) {
401+
if (
402+
!isMissingDatasource &&
403+
canAccessSqlLab &&
404+
datasource.type !== DatasourceType.SemanticView
405+
) {
402406
defaultDatasourceMenuItems.push({
403407
key: VIEW_IN_SQL_LAB,
404408
label: (

‎superset-frontend/src/explore/components/useExploreAdditionalActionsMenu/index.tsx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
JsonObject,
3434
LatestQueryFormData,
3535
QueryFormData,
36+
DatasourceType,
3637
Behavior,
3738
getChartMetadataRegistry,
3839
} from '@superset-ui/core';
@@ -1175,7 +1176,10 @@ export const useExploreAdditionalActionsMenu = (
11751176
});
11761177

11771178
// Run in SQL Lab
1178-
if (datasource) {
1179+
if (
1180+
datasource &&
1181+
!datasource.endsWith(`__${DatasourceType.SemanticView}`)
1182+
) {
11791183
menuItems.push({
11801184
key: MENU_KEYS.RUN_IN_SQL_LAB,
11811185
label: t('Run in SQL Lab'),

0 commit comments

Comments
 (0)