You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by kg...@apache.org on 2024/10/18 13:13:03 UTC
(superset) branch master updated: chore: Enable suppressing default chart context menu (#30613)
This is an automated email from the ASF dual-hosted git repository.
kgabryje pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/master by this push:
new 47c5334502 chore: Enable suppressing default chart context menu (#30613)
47c5334502 is described below
commit 47c533450215cdba8ab9bf0963f6b9389f1c7b65
Author: Kamil Gabryjelski <ka...@gmail.com>
AuthorDate: Fri Oct 18 15:12:54 2024 +0200
chore: Enable suppressing default chart context menu (#30613)
---
.../src/chart/models/ChartMetadata.ts | 7 +++++
.../src/components/Chart/ChartRenderer.jsx | 4 +++
.../src/components/Chart/ChartRenderer.test.jsx | 32 +++++++++++++++++++++-
3 files changed, 42 insertions(+), 1 deletion(-)
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 dcb1de62a5..9a9716a22b 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 b9cd6caf4f..df228104cb 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 53b35b6cf4..12556eef77 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(
<ChartRenderer {...requiredProps} chartIsStale={false} />,
@@ -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(<ChartRenderer {...requiredProps} />);
+ 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(
+ <ChartRenderer {...requiredProps} vizType="chart_without_context_menu" />,
+ );
+ expect(queryByTestId('mock-chart-context-menu')).not.toBeInTheDocument();
+});