The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
UXW-1778 remove chart hover effects when exporting to png (#66200)
Denis Berezin08770c8e8ff8
diff --git a/frontend/src/metabase-types/store/downloads.ts b/frontend/src/metabase-types/store/downloads.tsindex 0dce27bf789..b5066207487 100644--- a/frontend/src/metabase-types/store/downloads.ts+++ b/frontend/src/metabase-types/store/downloads.ts@@ -5,4 +5,7 @@ export interface Download {error?: string;}-export type DownloadsState = Download[];+export type DownloadsState = {+ isDownloadingToImage: boolean;+ datasetRequests: Download[];+};diff --git a/frontend/src/metabase/redux/downloads.ts b/frontend/src/metabase/redux/downloads.tsindex 5bb243380f9..13d32498c98 100644--- a/frontend/src/metabase/redux/downloads.ts+++ b/frontend/src/metabase/redux/downloads.ts@@ -1,4 +1,4 @@-import { createSlice } from "@reduxjs/toolkit";+import { createAction, createSlice } from "@reduxjs/toolkit";import { t } from "ttag";import _ from "underscore";@@ -137,6 +137,9 @@ const getDownloadedResourceType = ({};};+export const DOWNLOAD_TO_IMAGE = "metabase/downloads/DOWNLOAD_TO_IMAGE";+export const downloadToImage = createAction<boolean>(DOWNLOAD_TO_IMAGE);+export const downloadQueryResults = createAsyncThunk("metabase/downloads/downloadQueryResults",async (opts: DownloadQueryResultsOpts, { dispatch, getState }) => {@@ -148,9 +151,15 @@ export const downloadQueryResults = createAsyncThunk(});if (opts.type === Urls.exportFormatPng) {+ dispatch(downloadToImage(true));+const isWhitelabeled = getTokenFeature(getState(), "whitelabel");const includeBranding = !isWhitelabeled;- downloadChart({ opts, includeBranding });+ try {+ await downloadChart({ opts, includeBranding });+ } finally {+ dispatch(downloadToImage(false));+ }} else {dispatch(downloadDataset({ opts, id: Date.now() }));}@@ -537,11 +546,19 @@ export const getChartFileName = (question: Question, branded: boolean) => {return branded ? `Metabase-${fileName}` : fileName;};-export const getDownloads = (state: State) => state.downloads;+export const getDownloads = (state: State) => state.downloads.datasetRequests;export const hasActiveDownloads = (state: State) =>- state.downloads.some((download) => download.status === "in-progress");+ state.downloads.datasetRequests.some(+ (download) => download.status === "in-progress",+ );++export const getIsDownloadingToImage = (state: State) =>+ state.downloads.isDownloadingToImage;-const initialState: DownloadsState = [];+const initialState: DownloadsState = {+ isDownloadingToImage: false,+ datasetRequests: [],+};const downloads = createSlice({name: "metabase/downloads",@@ -555,27 +572,35 @@ const downloads = createSlice({const title = t`Results for ${action.meta.arg.opts.question.card().name}`;- state.push({+ state.datasetRequests.push({id: action.meta.arg.id,title,status: "in-progress",});}).addCase(downloadDataset.fulfilled, (state, action) => {- const download = state.find((item) => item.id === action.meta.arg.id);+ const download = state.datasetRequests.find(+ (item) => item.id === action.meta.arg.id,+ );if (download) {download.status = "complete";download.title = action.payload.name;}}).addCase(downloadDataset.rejected, (state, action) => {- const download = state.find((item) => item.id === action.meta.arg.id);+ const download = state.datasetRequests.find(+ (item) => item.id === action.meta.arg.id,+ );if (download) {download.status = "error";download.error =action.error.message ?? t`Could not download the file`;}});++ builder.addCase(downloadToImage, (state, action) => {+ state.isDownloadingToImage = action.payload;+ });},});diff --git a/frontend/src/metabase/status/components/DownloadsStatus/DownloadsStatus.unit.spec.tsx b/frontend/src/metabase/status/components/DownloadsStatus/DownloadsStatus.unit.spec.tsxindex 6207e61a416..e9c492478f3 100644--- a/frontend/src/metabase/status/components/DownloadsStatus/DownloadsStatus.unit.spec.tsx+++ b/frontend/src/metabase/status/components/DownloadsStatus/DownloadsStatus.unit.spec.tsx@@ -6,7 +6,7 @@ import { downloadDataset } from "metabase/redux/downloads";import { HIDE_DELAY } from "metabase/status/hooks/use-status-visibility";import Question from "metabase-lib/v1/Question";import { createMockCard, createMockDataset } from "metabase-types/api/mocks";-import type { Dispatch, Download } from "metabase-types/store";+import type { Dispatch, DownloadsState } from "metabase-types/store";import { createMockState } from "metabase-types/store/mocks";import { DownloadsStatus } from "./DownloadsStatus";@@ -30,10 +30,15 @@ const getDownloadDatasetAction = () =>});interface SetupOpts {- downloads?: Download[];+ downloads?: DownloadsState;}-const setup = ({ downloads = [] }: SetupOpts = {}) => {+const setup = ({+ downloads = {+ datasetRequests: [],+ isDownloadingToImage: false,+ },+}: SetupOpts = {}) => {const state = createMockState({downloads,});diff --git a/frontend/src/metabase/status/components/StatusListing/StatusListing.unit.spec.tsx b/frontend/src/metabase/status/components/StatusListing/StatusListing.unit.spec.tsxindex 23cd8f23da6..01608654a28 100644--- a/frontend/src/metabase/status/components/StatusListing/StatusListing.unit.spec.tsx+++ b/frontend/src/metabase/status/components/StatusListing/StatusListing.unit.spec.tsx@@ -2,7 +2,7 @@ import { callMockEvent } from "__support__/events";import { setupCollectionsEndpoints } from "__support__/server-mocks";import { renderWithProviders, screen } from "__support__/ui";import { createMockCollection, createMockUser } from "metabase-types/api/mocks";-import type { Download, DownloadsState } from "metabase-types/store";+import type { DownloadsState } from "metabase-types/store";import {createMockDownload,createMockState,@@ -25,7 +25,7 @@ interface setupProps {const setup = ({isAdmin = false,upload = {},- downloads = [],+ downloads = { datasetRequests: [], isDownloadingToImage: false },}: setupProps = {}) => {setupCollectionsEndpoints({ collections: [createMockCollection({})] });@@ -87,7 +87,12 @@ describe("StatusListing", () => {it("should alert when user navigates away from the page during an export", () => {const mockEventListener = jest.spyOn(window, "addEventListener");- setup({ downloads: [createMockDownload()] });+ setup({+ downloads: {+ datasetRequests: [createMockDownload()],+ isDownloadingToImage: false,+ },+ });const mockEvent = callMockEvent(mockEventListener, "beforeunload");expect(mockEvent.returnValue).toEqual(@@ -97,12 +102,22 @@ describe("StatusListing", () => {});it.each([- [[]],- [[createMockDownload({ status: "complete" })]],- [[createMockDownload({ status: "error" })]],+ [{ datasetRequests: [], isDownloadingToImage: false }],+ [+ {+ datasetRequests: [createMockDownload({ status: "complete" })],+ isDownloadingToImage: false,+ },+ ],+ [+ {+ datasetRequests: [createMockDownload({ status: "error" })],+ isDownloadingToImage: false,+ },+ ],])("should not alert when user navigates away when there is no export in progress",- (downloadsState: Download[]) => {+ (downloadsState: DownloadsState) => {const mockEventListener = jest.spyOn(window, "addEventListener");setup({diff --git a/frontend/src/metabase/visualizations/components/Visualization/Visualization.tsx b/frontend/src/metabase/visualizations/components/Visualization/Visualization.tsxindex 8340285f7a5..09126e0ec20 100644--- a/frontend/src/metabase/visualizations/components/Visualization/Visualization.tsx+++ b/frontend/src/metabase/visualizations/components/Visualization/Visualization.tsx@@ -27,6 +27,7 @@ import {getIsShowingRawTable,getUiControls,} from "metabase/query_builder/selectors";+import { getIsDownloadingToImage } from "metabase/redux/downloads";import { getTokenFeature } from "metabase/setup/selectors";import { getFont } from "metabase/styled-components/selectors";import type { IconName, IconProps } from "metabase/ui";@@ -103,6 +104,7 @@ type StateProps = {isRawTable: boolean;isEmbeddingSdk: boolean;scrollToLastColumn: boolean;+ isDownloadingToImage: boolean;};type ForwardedRefProps = {@@ -205,6 +207,7 @@ const mapStateToProps = (state: State): StateProps => ({isRawTable: getIsShowingRawTable(state),isEmbeddingSdk: isEmbeddingSdk(),scrollToLastColumn: getUiControls(state)?.scrollToLastColumn,+ isDownloadingToImage: getIsDownloadingToImage(state),});const SMALL_CARD_WIDTH_THRESHOLD = 150;@@ -660,6 +663,7 @@ class Visualization extends PureComponent<isShowingDetailsOnlyColumns,isShowingSummarySidebar,isSlow,+ isDownloadingToImage,metadata,mode,onEditSummary,@@ -713,6 +717,11 @@ class Visualization extends PureComponent<hovered = null;}+ // disable hover when exporting chart as an image (png download)+ if (isDownloadingToImage) {+ hovered = null;+ }+let error = this.props.error || this.state.error;let noResults = false;let isPlaceholder = false;diff --git a/frontend/src/metabase/visualizations/lib/save-chart-image.ts b/frontend/src/metabase/visualizations/lib/save-chart-image.tsindex 00cc9886973..fe6d7e17793 100644--- a/frontend/src/metabase/visualizations/lib/save-chart-image.ts+++ b/frontend/src/metabase/visualizations/lib/save-chart-image.ts@@ -1,10 +1,3 @@-// eslint-disable-next-line no-restricted-imports-import { css } from "@emotion/react";--import GlobalDashboardS from "metabase/css/dashboard.module.css";-import DashboardGridS from "metabase/dashboard/components/DashboardGrid.module.css";-import { DASHBOARD_PARAMETERS_PDF_EXPORT_NODE_CLASSNAME } from "metabase/dashboard/constants";-import { isEmbeddingSdk } from "metabase/embedding-sdk/config";import { isStorybookActive } from "metabase/env";import { openImageBlobOnStorybook } from "metabase/lib/loki-utils";import EmbedFrameS from "metabase/public/components/EmbedFrame/EmbedFrame.module.css";@@ -17,42 +10,6 @@ import {export const SAVING_DOM_IMAGE_CLASS = "saving-dom-image";export const SAVING_DOM_IMAGE_HIDDEN_CLASS = "saving-dom-image-hidden";-export const SAVING_DOM_IMAGE_DISPLAY_NONE_CLASS =- "saving-dom-image-display-none";--export const saveDomImageStyles = css`- .${SAVING_DOM_IMAGE_CLASS} {- .${SAVING_DOM_IMAGE_HIDDEN_CLASS} {- visibility: hidden;- }- .${SAVING_DOM_IMAGE_DISPLAY_NONE_CLASS} {- display: none;- }-- .${DASHBOARD_PARAMETERS_PDF_EXPORT_NODE_CLASSNAME} {- legend {- top: -9px;- }- }-- .${DashboardGridS.DashboardCardContainer} .${GlobalDashboardS.Card} {- /* the renderer we use for saving to image/pdf doesn't support box-shadow- so we replace it with a border */- box-shadow: none;- border: 1px solid var(--mb-color-border);- }-- /* the renderer for saving to image/pdf does not support text overflow- with line height in custom themes in the embedding sdk.- this is a workaround to make sure the text is not clipped vertically */- ${isEmbeddingSdk() &&- css`- .${DashboardGridS.DashboardCardContainer} .${GlobalDashboardS.Card} * {- overflow: visible !important;- }- `};- }-`;interface Opts {selector: string;