diff --git a/superset-frontend/packages/superset-ui-core/src/chart/models/ChartMetadata.ts b/superset-frontend/packages/superset-ui-core/src/chart/models/ChartMetadata.ts
index dcb1de62a..9a9716a22 100644
--- a/superset-frontend/packages/superset-ui-core/src/chart/models/ChartMetadata.ts
+++ b/superset-frontend/packages/superset-ui-core/src/chart/models/ChartMetadata.ts
@@ -50,6 +50,9 @@ export interface ChartMetadataConfig {
labelExplanation?: string | null;
queryObjectCount?: number;
parseMethod?: ParseMethod;
+ // suppressContextMenu: true hides the default context menu for the chart.
+ // This is useful for viz plugins that define their own context menu.
+ suppressContextMenu?: boolean;
}
export default class ChartMetadata {
@@ -91,6 +94,8 @@ export default class ChartMetadata {
parseMethod: ParseMethod;
+ suppressContextMenu?: boolean;
+
constructor(config: ChartMetadataConfig) {
const {
name,
@@ -111,6 +116,7 @@ export default class ChartMetadata {
labelExplanation = null,
queryObjectCount = 1,
parseMethod = 'json-bigint',
+ suppressContextMenu = false,
} = config;
this.name = name;
@@ -140,6 +146,7 @@ export default class ChartMetadata {
this.labelExplanation = labelExplanation;
this.queryObjectCount = queryObjectCount;
this.parseMethod = parseMethod;
+ this.suppressContextMenu = suppressContextMenu;
}
canBeAnnotationType(type: string): boolean {
diff --git a/superset-frontend/src/components/Chart/ChartRenderer.jsx b/superset-frontend/src/components/Chart/ChartRenderer.jsx
index b9cd6caf4..df228104c 100644
--- a/superset-frontend/src/components/Chart/ChartRenderer.jsx
+++ b/superset-frontend/src/components/Chart/ChartRenderer.jsx
@@ -84,9 +84,13 @@ const defaultProps = {
class ChartRenderer extends Component {
constructor(props) {
super(props);
+ const suppressContextMenu = getChartMetadataRegistry().get(
+ props.formData.viz_type ?? props.vizType,
+ )?.suppressContextMenu;
this.state = {
showContextMenu:
props.source === ChartSource.Dashboard &&
+ !suppressContextMenu &&
(isFeatureEnabled(FeatureFlag.DrillToDetail) ||
isFeatureEnabled(FeatureFlag.DashboardCrossFilters)),
inContextMenu: false,
diff --git a/superset-frontend/src/components/Chart/ChartRenderer.test.jsx b/superset-frontend/src/components/Chart/ChartRenderer.test.jsx
index 53b35b6cf..12556eef7 100644
--- a/superset-frontend/src/components/Chart/ChartRenderer.test.jsx
+++ b/superset-frontend/src/components/Chart/ChartRenderer.test.jsx
@@ -17,8 +17,9 @@
* under the License.
*/
import { render } from 'spec/helpers/testing-library';
-
+import { ChartMetadata, getChartMetadataRegistry } from '@superset-ui/core';
import ChartRenderer from 'src/components/Chart/ChartRenderer';
+import { ChartSource } from 'src/types/ChartSource';
jest.mock('@superset-ui/core', () => ({
...jest.requireActual('@superset-ui/core'),
@@ -40,8 +41,16 @@ const requiredProps = {
testControl: 'bar',
},
vizType: 'table',
+ source: ChartSource.Dashboard,
};
+beforeAll(() => {
+ window.featureFlags = { DRILL_TO_DETAIL: true };
+});
+afterAll(() => {
+ window.featureFlags = {};
+});
+
test('should render SuperChart', () => {
const { getByTestId } = render(
,
@@ -57,3 +66,24 @@ test('should use latestQueryFormData instead of formData when chartIsStale is tr
JSON.stringify({ testControl: 'bar' }),
);
});
+
+test('should render chart context menu', () => {
+ const { getByTestId } = render();
+ expect(getByTestId('mock-chart-context-menu')).toBeInTheDocument();
+});
+
+test('should not render chart context menu if the context menu is suppressed for given viz plugin', () => {
+ getChartMetadataRegistry().registerValue(
+ 'chart_without_context_menu',
+ new ChartMetadata({
+ name: 'chart with suppressed context menu',
+ thumbnail: '.png',
+ useLegacyApi: false,
+ suppressContextMenu: true,
+ }),
+ );
+ const { queryByTestId } = render(
+ ,
+ );
+ expect(queryByTestId('mock-chart-context-menu')).not.toBeInTheDocument();
+});