From 0c34f29418151f6bf772143cfd175d4dfff269c8 Mon Sep 17 00:00:00 2001
From: "Michael S. Molina" <70410625+michael-s-molina@users.noreply.github.com>
Date: Thu, 6 Apr 2023 16:00:47 -0300
Subject: [PATCH] fix: Disables email reports for unsaved charts (#23588)
(cherry picked from commit 290920c4fb1fec85bf6f95e23f3c91b2681cfcbe)
---
.../HeaderReportDropdown/index.tsx | 67 +++++++++++--------
.../src/components/ReportModal/index.tsx | 8 ++-
.../src/reports/actions/reports.js | 4 +-
.../src/reports/reducers/reports.js | 19 +++++-
superset-frontend/src/views/CRUD/hooks.ts | 2 +-
5 files changed, 69 insertions(+), 31 deletions(-)
diff --git a/superset-frontend/src/components/ReportModal/HeaderReportDropdown/index.tsx b/superset-frontend/src/components/ReportModal/HeaderReportDropdown/index.tsx
index f7bb9ba55cf2f..db5964e2d24db 100644
--- a/superset-frontend/src/components/ReportModal/HeaderReportDropdown/index.tsx
+++ b/superset-frontend/src/components/ReportModal/HeaderReportDropdown/index.tsx
@@ -19,6 +19,7 @@
import React, { useState, useEffect } from 'react';
import { usePrevious } from 'src/hooks/usePrevious';
import { useSelector, useDispatch } from 'react-redux';
+import { isEmpty } from 'lodash';
import {
t,
SupersetTheme,
@@ -103,6 +104,9 @@ export interface HeaderReportProps {
showReportSubMenu?: boolean;
}
+// Same instance to be used in useEffects
+const EMPTY_OBJECT = {};
+
export default function HeaderReportDropDown({
dashboardId,
chart,
@@ -116,7 +120,10 @@ export default function HeaderReportDropDown({
const resourceType = dashboardId
? CreationMethod.DASHBOARDS
: CreationMethod.CHARTS;
- return reportSelector(state, resourceType, dashboardId || chart?.id);
+ return (
+ reportSelector(state, resourceType, dashboardId || chart?.id) ||
+ EMPTY_OBJECT
+ );
});
const isReportActive: boolean = report?.active || false;
@@ -133,6 +140,12 @@ export default function HeaderReportDropDown({
// this is in the case that there is an anonymous user.
return false;
}
+
+ // Cannot add reports if the resource is not saved
+ if (!(dashboardId || chart?.id)) {
+ return false;
+ }
+
const roles = Object.keys(user.roles || []);
const permissions = roles.map(key =>
user.roles[key].filter(
@@ -200,7 +213,21 @@ export default function HeaderReportDropDown({
};
const textMenu = () =>
- report ? (
+ isEmpty(report) ? (
+
+ ) : (
isDropdownVisible && (
)
- ) : (
-
);
const menu = () => (