You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by el...@apache.org on 2021/08/20 17:12:01 UTC

[superset] branch refactorReports updated (64434e3 -> efccf0c)

This is an automated email from the ASF dual-hosted git repository.

elizabeth pushed a change to branch refactorReports
in repository https://gitbox.apache.org/repos/asf/superset.git.


 discard 64434e3  code dry (#16358)
    omit 1b07b66  fix: Header Actions test refactor (#16336)
    omit 0b4f1b8  refactor progress (#16339)
    omit 44e6aa3  pexdax refactor (#16333)
     add efe850b  adjust initial state (#16329)
     add afb8bd5  feat: improve embedded data table in text reports (#16335)
     add ec8d3b0  fix: send CSV pivoted in reports (#16347)
     add 42cd21e  chore: bump superset-ui to v0.17.85 (#16350)
     add d75da74  docs: add VkusVill and TechAudit to users list (#16113)
     add c5c2861  fix: Blank space in Change dataset modal without warning message (#16324)
     add 86f4e69  chore(viz): bump deckgl plugin to 0.4.11 (#16353)
     add 37f09bd  fix: columns/index rebuild (#16355)
     add 50d896f  fix: Fix parsing onSaving reports toast when user hasn't saved chart (#16330)
     add 575ee24  fix: call external metadata endpoint with correct rison object (#16369)
     add ea803c3  feat: Add new dev commands to Makefile (#16327)
     add 13a2ee3  docs: document FLASK_APP_MUTATOR (#16286)
     add adebc09  fix: update table ID in query context on chart import (#16374)
     add 518c3c9  test: Functional RTL for email report modal II (#16148)
     new 018ff6c  pexdax refactor (#16333)
     new 4c90364  refactor progress (#16339)
     new c3e3cfe  fix: Header Actions test refactor (#16336)
     new efccf0c  code dry (#16358)

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (64434e3)
            \
             N -- N -- N   refs/heads/refactorReports (efccf0c)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 Makefile                                           |   8 +-
 RESOURCES/INTHEWILD.md                             |   3 +-
 docs/src/pages/docs/installation/configuring.mdx   |  19 +
 setup.cfg                                          |   2 +-
 superset-frontend/package-lock.json                | 497 ++++++++++-----------
 superset-frontend/package.json                     |  56 +--
 .../spec/fixtures/mockReportState.js               |  32 +-
 .../{mockState.js => mockStateWithoutUser.tsx}     |  16 +-
 superset-frontend/spec/helpers/reducerIndex.ts     |   2 +
 .../explore/components/ExploreChartHeader_spec.jsx |  87 ----
 .../src/components/ReportModal/index.test.tsx      |  25 +-
 .../src/components/ReportModal/index.tsx           |  11 +-
 .../src/components/TableView/TableView.tsx         |   7 +-
 .../dashboard/components/Header/Header.test.tsx    | 155 ++++++-
 .../src/datasource/ChangeDatasourceModal.tsx       |  11 +-
 .../src/datasource/DatasourceEditor.jsx            |  11 +-
 superset-frontend/src/reports/actions/reports.js   |   5 +-
 superset/charts/api.py                             |   5 +-
 superset/charts/commands/importers/v1/__init__.py  |   7 +
 superset/charts/post_processing.py                 |  59 ++-
 superset/common/query_actions.py                   |   2 +
 superset/examples/deck.py                          |   1 +
 superset/reports/commands/base.py                  |  14 +
 superset/reports/commands/exceptions.py            |  34 ++
 superset/reports/commands/execute.py               |  82 ++--
 superset/reports/notifications/email.py            |  44 +-
 superset/reports/notifications/slack.py            |  21 +-
 superset/utils/csv.py                              |  23 +
 tests/integration_tests/charts/commands_tests.py   |  28 ++
 tests/integration_tests/fixtures/importexport.py   |   1 +
 tests/integration_tests/reports/api_tests.py       |  56 +++
 tests/integration_tests/reports/commands_tests.py  |  63 ++-
 tests/unit_tests/charts/test_post_processing.py    | 429 ++++--------------
 33 files changed, 981 insertions(+), 835 deletions(-)
 copy docs/doczrc.js => superset-frontend/spec/fixtures/mockReportState.js (67%)
 copy superset-frontend/spec/fixtures/{mockState.js => mockStateWithoutUser.tsx} (74%)
 delete mode 100644 superset-frontend/spec/javascripts/explore/components/ExploreChartHeader_spec.jsx

[superset] 04/04: code dry (#16358)

Posted by el...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

elizabeth pushed a commit to branch refactorReports
in repository https://gitbox.apache.org/repos/asf/superset.git

commit efccf0c7e121f073a8945354ab23fbb73c93b152
Author: AAfghahi <48...@users.noreply.github.com>
AuthorDate: Fri Aug 20 13:09:40 2021 -0400

    code dry (#16358)
---
 .../HeaderReportActionsDropdown/index.tsx          | 24 ++++++++--
 .../src/components/ReportModal/index.tsx           | 22 ++-------
 .../src/dashboard/components/Header/index.jsx      | 44 +----------------
 .../explore/components/DataTableControl/index.tsx  |  1 +
 .../explore/components/DataTablesPane/index.tsx    |  2 +-
 .../src/explore/components/ExploreChartHeader.jsx  | 56 +---------------------
 superset-frontend/src/reports/actions/reports.js   | 12 ++---
 7 files changed, 35 insertions(+), 126 deletions(-)

diff --git a/superset-frontend/src/components/ReportModal/HeaderReportActionsDropdown/index.tsx b/superset-frontend/src/components/ReportModal/HeaderReportActionsDropdown/index.tsx
index 026a262..cf2ae7f 100644
--- a/superset-frontend/src/components/ReportModal/HeaderReportActionsDropdown/index.tsx
+++ b/superset-frontend/src/components/ReportModal/HeaderReportActionsDropdown/index.tsx
@@ -16,18 +16,19 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-import React, { useState } from 'react';
-import { useSelector } from 'react-redux';
+import React, { useState, useEffect } from 'react';
+import { useSelector, useDispatch } from 'react-redux';
 import { t, SupersetTheme, css, useTheme } from '@superset-ui/core';
 import Icons from 'src/components/Icons';
 import { Switch } from 'src/components/Switch';
 import { AlertObject } from 'src/views/CRUD/alert/types';
 import { Menu, NoAnimationDropdown } from 'src/common/components';
 import { isFeatureEnabled, FeatureFlag } from 'src/featureFlags';
-
 import DeleteModal from 'src/components/DeleteModal';
 import ReportModal from 'src/components/ReportModal';
+import { ChartState } from 'src/explore/types';
 import { UserWithPermissionsAndRoles } from 'src/types/bootstrapTypes';
+import { fetchUISpecificReport } from 'src/reports/actions/reports';
 
 const deleteColor = (theme: SupersetTheme) => css`
   color: ${theme.colors.error.base};
@@ -37,11 +38,14 @@ export default function HeaderReportActionsDropDown({
   toggleActive,
   deleteActiveReport,
   dashboardId,
+  chart,
 }: {
   toggleActive: (data: AlertObject, checked: boolean) => void;
   deleteActiveReport: (data: AlertObject) => void;
   dashboardId?: number;
+  chart?: ChartState;
 }) {
+  const dispatch = useDispatch();
   const reports: Record<number, AlertObject> = useSelector<any, AlertObject>(
     state => state.reports,
   );
@@ -86,6 +90,19 @@ export default function HeaderReportActionsDropDown({
     return permissions[0].length > 0;
   };
 
+  useEffect(() => {
+    if (canAddReports()) {
+      dispatch(
+        fetchUISpecificReport({
+          userId: user.userId,
+          filterField: dashboardId ? 'dashboard_id' : 'chart_id',
+          creationMethod: dashboardId ? 'dashboards' : 'charts',
+          resourceId: dashboardId || chart?.id,
+        }),
+      );
+    }
+  }, []);
+
   const menu = () => (
     <Menu selectable={false} css={{ width: '200px' }}>
       <Menu.Item>
@@ -119,6 +136,7 @@ export default function HeaderReportActionsDropDown({
           userId={user.userId}
           userEmail={user.email}
           dashboardId={dashboardId}
+          chart={chart}
         />
         {report ? (
           <>
diff --git a/superset-frontend/src/components/ReportModal/index.tsx b/superset-frontend/src/components/ReportModal/index.tsx
index 2bf0f61..4f4b8c9 100644
--- a/superset-frontend/src/components/ReportModal/index.tsx
+++ b/superset-frontend/src/components/ReportModal/index.tsx
@@ -36,6 +36,7 @@ import Icons from 'src/components/Icons';
 import withToasts from 'src/messageToasts/enhancers/withToasts';
 import { CronError } from 'src/components/CronPicker';
 import { RadioChangeEvent } from 'src/common/components';
+import { ChartState } from 'src/explore/types';
 import {
   StyledModal,
   StyledTopSection,
@@ -72,20 +73,6 @@ export interface ReportObject {
   working_timeout: number;
   creation_method: string;
 }
-
-interface ChartObject {
-  id: number;
-  chartAlert: string;
-  chartStatus: string;
-  chartUpdateEndTime: number;
-  chartUpdateStartTime: number;
-  latestQueryFormData: object;
-  queryController: { abort: () => {} };
-  queriesResponse: object;
-  triggerQuery: boolean;
-  lastRendered: number;
-}
-
 interface ReportProps {
   addDangerToast: (msg: string) => void;
   addSuccessToast: (msg: string) => void;
@@ -96,7 +83,7 @@ interface ReportProps {
   userId: number;
   userEmail: string;
   dashboardId?: number;
-  chart?: ChartObject;
+  chart?: ChartState;
   props: any;
 }
 
@@ -172,12 +159,11 @@ const ReportModal: FunctionComponent<ReportProps> = ({
   chart,
   userId,
   userEmail,
-  ...props
 }) => {
   const vizType = chart?.sliceFormData?.viz_type;
   const isChart = !!chart;
   const defaultNotificationFormat =
-    isChart && TEXT_BASED_VISUALIZATION_TYPES.includes(vizType)
+    vizType && TEXT_BASED_VISUALIZATION_TYPES.includes(vizType)
       ? NOTIFICATION_FORMATS.TEXT
       : NOTIFICATION_FORMATS.PNG;
   const [currentReport, setCurrentReport] = useReducer<
@@ -287,7 +273,7 @@ const ReportModal: FunctionComponent<ReportProps> = ({
           }}
           value={currentReport?.report_format || defaultNotificationFormat}
         >
-          {TEXT_BASED_VISUALIZATION_TYPES.includes(vizType) && (
+          {vizType && TEXT_BASED_VISUALIZATION_TYPES.includes(vizType) && (
             <StyledRadio value={NOTIFICATION_FORMATS.TEXT}>
               {t('Text embedded in email')}
             </StyledRadio>
diff --git a/superset-frontend/src/dashboard/components/Header/index.jsx b/superset-frontend/src/dashboard/components/Header/index.jsx
index c4cb015..f462b9c 100644
--- a/superset-frontend/src/dashboard/components/Header/index.jsx
+++ b/superset-frontend/src/dashboard/components/Header/index.jsx
@@ -28,8 +28,6 @@ import {
   LOG_ACTIONS_FORCE_REFRESH_DASHBOARD,
   LOG_ACTIONS_TOGGLE_EDIT_DASHBOARD,
 } from 'src/logger/LogUtils';
-import { isFeatureEnabled, FeatureFlag } from 'src/featureFlags';
-
 import Icons from 'src/components/Icons';
 import Button from 'src/components/Button';
 import EditableTitle from 'src/components/EditableTitle';
@@ -165,21 +163,11 @@ class Header extends React.PureComponent {
   }
 
   componentDidMount() {
-    const { refreshFrequency, user, dashboardInfo } = this.props;
+    const { refreshFrequency } = this.props;
     this.startPeriodicRender(refreshFrequency * 1000);
-    if (this.canAddReports()) {
-      // this is in case there is an anonymous user.
-      this.props.fetchUISpecificReport(
-        user.userId,
-        'dashboard_id',
-        'dashboards',
-        dashboardInfo.id,
-      );
-    }
   }
 
   UNSAFE_componentWillReceiveProps(nextProps) {
-    const { user } = this.props;
     if (
       UNDO_LIMIT - nextProps.undoLength <= 0 &&
       !this.state.didNotifyMaxUndoHistoryToast
@@ -193,18 +181,6 @@ class Header extends React.PureComponent {
     ) {
       this.props.setMaxUndoHistoryExceeded();
     }
-    if (
-      this.canAddReports() &&
-      nextProps.dashboardInfo.id !== this.props.dashboardInfo.id
-    ) {
-      // this is in case there is an anonymous user.
-      this.props.fetchUISpecificReport(
-        user.userId,
-        'dashboard_id',
-        'dashboards',
-        nextProps.dashboardInfo.id,
-      );
-    }
   }
 
   componentWillUnmount() {
@@ -387,24 +363,6 @@ class Header extends React.PureComponent {
     this.setState({ showingPropertiesModal: false });
   }
 
-  canAddReports() {
-    if (!isFeatureEnabled(FeatureFlag.ALERT_REPORTS)) {
-      return false;
-    }
-    const { user } = this.props;
-    if (!user) {
-      // this is in the case that there is an anonymous user.
-      return false;
-    }
-    const roles = Object.keys(user.roles || []);
-    const permissions = roles.map(key =>
-      user.roles[key].filter(
-        perms => perms[0] === 'menu_access' && perms[1] === 'Manage',
-      ),
-    );
-    return permissions[0].length > 0;
-  }
-
   render() {
     const {
       dashboardTitle,
diff --git a/superset-frontend/src/explore/components/DataTableControl/index.tsx b/superset-frontend/src/explore/components/DataTableControl/index.tsx
index 16a6c64..3e2d4c1 100644
--- a/superset-frontend/src/explore/components/DataTableControl/index.tsx
+++ b/superset-frontend/src/explore/components/DataTableControl/index.tsx
@@ -125,6 +125,7 @@ export const useTableColumns = (
                 accessor: row => row[key],
                 Header: key,
                 Cell: ({ value }) => {
+                  console.log(data);
                   if (value === true) {
                     return BOOL_TRUE_DISPLAY;
                   }
diff --git a/superset-frontend/src/explore/components/DataTablesPane/index.tsx b/superset-frontend/src/explore/components/DataTablesPane/index.tsx
index 3d83089..a25b773 100644
--- a/superset-frontend/src/explore/components/DataTablesPane/index.tsx
+++ b/superset-frontend/src/explore/components/DataTablesPane/index.tsx
@@ -201,7 +201,7 @@ export const DataTablesPane = ({
     },
     [queryFormData],
   );
-
+  console.log(queryFormData);
   useEffect(() => {
     setInLocalStorage(STORAGE_KEYS.isOpen, panelOpen);
   }, [panelOpen]);
diff --git a/superset-frontend/src/explore/components/ExploreChartHeader.jsx b/superset-frontend/src/explore/components/ExploreChartHeader.jsx
index 1f2bb10..77bf6c3 100644
--- a/superset-frontend/src/explore/components/ExploreChartHeader.jsx
+++ b/superset-frontend/src/explore/components/ExploreChartHeader.jsx
@@ -22,13 +22,11 @@ import { bindActionCreators } from 'redux';
 import PropTypes from 'prop-types';
 import { styled, t } from '@superset-ui/core';
 import { Tooltip } from 'src/components/Tooltip';
-import ReportModal from 'src/components/ReportModal';
 import {
   fetchUISpecificReport,
   toggleActive,
   deleteActiveReport,
 } from 'src/reports/actions/reports';
-import { isFeatureEnabled, FeatureFlag } from 'src/featureFlags';
 import HeaderReportActionsDropdown from 'src/components/ReportModal/HeaderReportActionsDropdown';
 import { chartPropShape } from '../../dashboard/util/propShapes';
 import ExploreActionButtons from './ExploreActionButtons';
@@ -106,25 +104,9 @@ export class ExploreChartHeader extends React.PureComponent {
     super(props);
     this.state = {
       isPropertiesModalOpen: false,
-      showingReportModal: false,
     };
     this.openPropertiesModal = this.openPropertiesModal.bind(this);
     this.closePropertiesModal = this.closePropertiesModal.bind(this);
-    this.showReportModal = this.showReportModal.bind(this);
-    this.hideReportModal = this.hideReportModal.bind(this);
-  }
-
-  componentDidMount() {
-    if (this.canAddReports()) {
-      const { user, chart } = this.props;
-      // this is in the case that there is an anonymous user.
-      this.props.fetchUISpecificReport(
-        user.userId,
-        'chart_id',
-        'charts',
-        chart.id,
-      );
-    }
   }
 
   getSliceName() {
@@ -153,32 +135,6 @@ export class ExploreChartHeader extends React.PureComponent {
     });
   }
 
-  showReportModal() {
-    this.setState({ showingReportModal: true });
-  }
-
-  hideReportModal() {
-    this.setState({ showingReportModal: false });
-  }
-
-  canAddReports() {
-    if (!isFeatureEnabled(FeatureFlag.ALERT_REPORTS)) {
-      return false;
-    }
-    const { user } = this.props;
-    if (!user) {
-      // this is in the case that there is an anonymous user.
-      return false;
-    }
-    const roles = Object.keys(user.roles || []);
-    const permissions = roles.map(key =>
-      user.roles[key].filter(
-        perms => perms[0] === 'menu_access' && perms[1] === 'Manage',
-      ),
-    );
-    return permissions[0].length > 0;
-  }
-
   render() {
     const { user, form_data: formData } = this.props;
     const {
@@ -262,20 +218,10 @@ export class ExploreChartHeader extends React.PureComponent {
             status={CHART_STATUS_MAP[chartStatus]}
           />
           <HeaderReportActionsDropdown
-            showReportModal={this.showReportModal}
+            chart={this.props.chart}
             toggleActive={this.props.toggleActive}
             deleteActiveReport={this.props.deleteActiveReport}
           />
-          <ReportModal
-            show={this.state.showingReportModal}
-            onHide={this.hideReportModal}
-            props={{
-              userId: this.props.user.userId,
-              userEmail: this.props.user.email,
-              chart: this.props.chart,
-              creationMethod: 'charts',
-            }}
-          />
           <ExploreActionButtons
             actions={{
               ...this.props.actions,
diff --git a/superset-frontend/src/reports/actions/reports.js b/superset-frontend/src/reports/actions/reports.js
index 28600df..03620ed 100644
--- a/superset-frontend/src/reports/actions/reports.js
+++ b/superset-frontend/src/reports/actions/reports.js
@@ -27,23 +27,23 @@ export function setReport(report) {
   return { type: SET_REPORT, report };
 }
 
-export function fetchUISpecificReport(
+export function fetchUISpecificReport({
   userId,
-  filter_field,
-  creation_method,
+  filterField,
+  creationMethod,
   resourceId,
-) {
+}) {
   const queryParams = rison.encode({
     filters: [
       {
-        col: filter_field,
+        col: filterField,
         opr: 'eq',
         value: resourceId,
       },
       {
         col: 'creation_method',
         opr: 'eq',
-        value: creation_method,
+        value: creationMethod,
       },
       {
         col: 'created_by',

[superset] 03/04: fix: Header Actions test refactor (#16336)

Posted by el...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

elizabeth pushed a commit to branch refactorReports
in repository https://gitbox.apache.org/repos/asf/superset.git

commit c3e3cfe3aa8443f05cd9a48837928d856442e21c
Author: AAfghahi <48...@users.noreply.github.com>
AuthorDate: Thu Aug 19 13:23:42 2021 -0400

    fix: Header Actions test refactor (#16336)
    
    * fixed tests
    
    * Update index.tsx
    
    Co-authored-by: Elizabeth Thompson <es...@gmail.com>
---
 .../HeaderReportActionsDropdown/index.tsx          |  4 +-
 .../dashboard/components/Header/Header.test.tsx    | 47 +++++++++++-----------
 2 files changed, 26 insertions(+), 25 deletions(-)

diff --git a/superset-frontend/src/components/ReportModal/HeaderReportActionsDropdown/index.tsx b/superset-frontend/src/components/ReportModal/HeaderReportActionsDropdown/index.tsx
index bbc30c8..026a262 100644
--- a/superset-frontend/src/components/ReportModal/HeaderReportActionsDropdown/index.tsx
+++ b/superset-frontend/src/components/ReportModal/HeaderReportActionsDropdown/index.tsx
@@ -49,8 +49,8 @@ export default function HeaderReportActionsDropDown({
     any,
     UserWithPermissionsAndRoles
   >(state => state.user || state.explore?.user);
-  const reportsIds = Object.keys(reports);
-  const report: AlertObject = reports[reportsIds[0]];
+  const reportsIds = Object.keys(reports || []);
+  const report: AlertObject = reports?.[reportsIds[0]];
   const [
     currentReportDeleting,
     setCurrentReportDeleting,
diff --git a/superset-frontend/src/dashboard/components/Header/Header.test.tsx b/superset-frontend/src/dashboard/components/Header/Header.test.tsx
index 8a9ecdb..1ff6e48 100644
--- a/superset-frontend/src/dashboard/components/Header/Header.test.tsx
+++ b/superset-frontend/src/dashboard/components/Header/Header.test.tsx
@@ -58,6 +58,7 @@ const createProps = () => ({
   dashboardTitle: 'Dashboard Title',
   charts: {},
   layout: {},
+  reports: {},
   expandedSlices: {},
   css: '',
   customCss: '',
@@ -134,23 +135,23 @@ async function openActionsDropdown() {
 
 test('should render', () => {
   const mockedProps = createProps();
-  const { container } = render(setup(mockedProps));
+  const { container } = render(setup(mockedProps), { useRedux: true });
   expect(container).toBeInTheDocument();
 });
 
 test('should render the title', () => {
   const mockedProps = createProps();
-  render(setup(mockedProps));
+  render(setup(mockedProps), { useRedux: true });
   expect(screen.getByText('Dashboard Title')).toBeInTheDocument();
 });
 
 test('should render the editable title', () => {
-  render(setup(editableProps));
+  render(setup(editableProps), { useRedux: true });
   expect(screen.getByDisplayValue('Dashboard Title')).toBeInTheDocument();
 });
 
 test('should edit the title', () => {
-  render(setup(editableProps));
+  render(setup(editableProps), { useRedux: true });
   const editableTitle = screen.getByDisplayValue('Dashboard Title');
   expect(editableProps.onChange).not.toHaveBeenCalled();
   userEvent.click(editableTitle);
@@ -163,12 +164,12 @@ test('should edit the title', () => {
 
 test('should render the "Draft" status', () => {
   const mockedProps = createProps();
-  render(setup(mockedProps));
+  render(setup(mockedProps), { useRedux: true });
   expect(screen.getByText('Draft')).toBeInTheDocument();
 });
 
 test('should publish', () => {
-  render(setup(editableProps));
+  render(setup(editableProps), { useRedux: true });
   const draft = screen.getByText('Draft');
   expect(editableProps.savePublished).not.toHaveBeenCalled();
   userEvent.click(draft);
@@ -176,12 +177,12 @@ test('should publish', () => {
 });
 
 test('should render the "Undo" action as disabled', () => {
-  render(setup(editableProps));
+  render(setup(editableProps), { useRedux: true });
   expect(screen.getByTitle('Undo').parentElement).toBeDisabled();
 });
 
 test('should undo', () => {
-  render(setup(undoProps));
+  render(setup(undoProps), { useRedux: true });
   const undo = screen.getByTitle('Undo');
   expect(undoProps.onUndo).not.toHaveBeenCalled();
   userEvent.click(undo);
@@ -190,19 +191,19 @@ test('should undo', () => {
 
 test('should undo with key listener', () => {
   undoProps.onUndo.mockReset();
-  render(setup(undoProps));
+  render(setup(undoProps), { useRedux: true });
   expect(undoProps.onUndo).not.toHaveBeenCalled();
   fireEvent.keyDown(document.body, { key: 'z', code: 'KeyZ', ctrlKey: true });
   expect(undoProps.onUndo).toHaveBeenCalledTimes(1);
 });
 
 test('should render the "Redo" action as disabled', () => {
-  render(setup(editableProps));
+  render(setup(editableProps), { useRedux: true });
   expect(screen.getByTitle('Redo').parentElement).toBeDisabled();
 });
 
 test('should redo', () => {
-  render(setup(redoProps));
+  render(setup(redoProps), { useRedux: true });
   const redo = screen.getByTitle('Redo');
   expect(redoProps.onRedo).not.toHaveBeenCalled();
   userEvent.click(redo);
@@ -211,19 +212,19 @@ test('should redo', () => {
 
 test('should redo with key listener', () => {
   redoProps.onRedo.mockReset();
-  render(setup(redoProps));
+  render(setup(redoProps), { useRedux: true });
   expect(redoProps.onRedo).not.toHaveBeenCalled();
   fireEvent.keyDown(document.body, { key: 'y', code: 'KeyY', ctrlKey: true });
   expect(redoProps.onRedo).toHaveBeenCalledTimes(1);
 });
 
 test('should render the "Discard changes" button', () => {
-  render(setup(editableProps));
+  render(setup(editableProps), { useRedux: true });
   expect(screen.getByText('Discard changes')).toBeInTheDocument();
 });
 
 test('should render the "Save" button as disabled', () => {
-  render(setup(editableProps));
+  render(setup(editableProps), { useRedux: true });
   expect(screen.getByText('Save').parentElement).toBeDisabled();
 });
 
@@ -232,7 +233,7 @@ test('should save', () => {
     ...editableProps,
     hasUnsavedChanges: true,
   };
-  render(setup(unsavedProps));
+  render(setup(unsavedProps), { useRedux: true });
   const save = screen.getByText('Save');
   expect(unsavedProps.onSave).not.toHaveBeenCalled();
   userEvent.click(save);
@@ -245,13 +246,13 @@ test('should NOT render the "Draft" status', () => {
     ...mockedProps,
     isPublished: true,
   };
-  render(setup(publishedProps));
+  render(setup(publishedProps), { useRedux: true });
   expect(screen.queryByText('Draft')).not.toBeInTheDocument();
 });
 
 test('should render the unselected fave icon', () => {
   const mockedProps = createProps();
-  render(setup(mockedProps));
+  render(setup(mockedProps), { useRedux: true });
   expect(mockedProps.fetchFaveStar).toHaveBeenCalled();
   expect(
     screen.getByRole('img', { name: 'favorite-unselected' }),
@@ -264,7 +265,7 @@ test('should render the selected fave icon', () => {
     ...mockedProps,
     isStarred: true,
   };
-  render(setup(favedProps));
+  render(setup(favedProps), { useRedux: true });
   expect(
     screen.getByRole('img', { name: 'favorite-selected' }),
   ).toBeInTheDocument();
@@ -276,7 +277,7 @@ test('should NOT render the fave icon on anonymous user', () => {
     ...mockedProps,
     user: undefined,
   };
-  render(setup(anonymousUserProps));
+  render(setup(anonymousUserProps), { useRedux: true });
   expect(() =>
     screen.getByRole('img', { name: 'favorite-unselected' }),
   ).toThrowError('Unable to find');
@@ -287,7 +288,7 @@ test('should NOT render the fave icon on anonymous user', () => {
 
 test('should fave', async () => {
   const mockedProps = createProps();
-  render(setup(mockedProps));
+  render(setup(mockedProps), { useRedux: true });
   const fave = screen.getByRole('img', { name: 'favorite-unselected' });
   expect(mockedProps.saveFaveStar).not.toHaveBeenCalled();
   userEvent.click(fave);
@@ -303,7 +304,7 @@ test('should toggle the edit mode', () => {
       dash_edit_perm: true,
     },
   };
-  render(setup(canEditProps));
+  render(setup(canEditProps), { useRedux: true });
   const editDashboard = screen.getByTitle('Edit dashboard');
   expect(screen.queryByTitle('Edit dashboard')).toBeInTheDocument();
   userEvent.click(editDashboard);
@@ -312,13 +313,13 @@ test('should toggle the edit mode', () => {
 
 test('should render the dropdown icon', () => {
   const mockedProps = createProps();
-  render(setup(mockedProps));
+  render(setup(mockedProps), { useRedux: true });
   expect(screen.getByRole('img', { name: 'more-horiz' })).toBeInTheDocument();
 });
 
 test('should refresh the charts', async () => {
   const mockedProps = createProps();
-  render(setup(mockedProps));
+  render(setup(mockedProps), { useRedux: true });
   await openActionsDropdown();
   userEvent.click(screen.getByText('Refresh dashboard'));
   expect(mockedProps.onRefresh).toHaveBeenCalledTimes(1);

[superset] 02/04: refactor progress (#16339)

Posted by el...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

elizabeth pushed a commit to branch refactorReports
in repository https://gitbox.apache.org/repos/asf/superset.git

commit 4c903640907fc08a6d1cd5fd95cd0bd40e763a08
Author: Lyndsi Kay Williams <55...@users.noreply.github.com>
AuthorDate: Thu Aug 19 12:19:33 2021 -0500

    refactor progress (#16339)
---
 .../HeaderReportActionsDropdown/index.tsx          | 97 +++++++++++++---------
 .../src/components/ReportModal/index.tsx           | 19 +++--
 .../src/dashboard/components/Header/index.jsx      | 14 +---
 superset-frontend/src/reports/actions/reports.js   |  4 +-
 4 files changed, 70 insertions(+), 64 deletions(-)

diff --git a/superset-frontend/src/components/ReportModal/HeaderReportActionsDropdown/index.tsx b/superset-frontend/src/components/ReportModal/HeaderReportActionsDropdown/index.tsx
index 4d9ceb8..bbc30c8 100644
--- a/superset-frontend/src/components/ReportModal/HeaderReportActionsDropdown/index.tsx
+++ b/superset-frontend/src/components/ReportModal/HeaderReportActionsDropdown/index.tsx
@@ -26,6 +26,7 @@ import { Menu, NoAnimationDropdown } from 'src/common/components';
 import { isFeatureEnabled, FeatureFlag } from 'src/featureFlags';
 
 import DeleteModal from 'src/components/DeleteModal';
+import ReportModal from 'src/components/ReportModal';
 import { UserWithPermissionsAndRoles } from 'src/types/bootstrapTypes';
 
 const deleteColor = (theme: SupersetTheme) => css`
@@ -33,13 +34,13 @@ const deleteColor = (theme: SupersetTheme) => css`
 `;
 
 export default function HeaderReportActionsDropDown({
-  showReportModal,
   toggleActive,
   deleteActiveReport,
+  dashboardId,
 }: {
-  showReportModal: () => void;
   toggleActive: (data: AlertObject, checked: boolean) => void;
   deleteActiveReport: (data: AlertObject) => void;
+  dashboardId?: number;
 }) {
   const reports: Record<number, AlertObject> = useSelector<any, AlertObject>(
     state => state.reports,
@@ -55,6 +56,7 @@ export default function HeaderReportActionsDropDown({
     setCurrentReportDeleting,
   ] = useState<AlertObject | null>(null);
   const theme = useTheme();
+  const [showModal, setShowModal] = useState(false);
 
   const toggleActiveKey = async (data: AlertObject, checked: boolean) => {
     if (data?.id) {
@@ -96,7 +98,9 @@ export default function HeaderReportActionsDropDown({
           css={{ marginLeft: theme.gridUnit * 2 }}
         />
       </Menu.Item>
-      <Menu.Item onClick={showReportModal}>{t('Edit email report')}</Menu.Item>
+      <Menu.Item onClick={() => setShowModal(true)}>
+        {t('Edit email report')}
+      </Menu.Item>
       <Menu.Item
         onClick={() => setCurrentReportDeleting(report)}
         css={deleteColor}
@@ -106,48 +110,59 @@ export default function HeaderReportActionsDropDown({
     </Menu>
   );
 
-  return canAddReports() ? (
-    report ? (
+  return (
+    canAddReports() && (
       <>
-        <NoAnimationDropdown
-          // ref={ref}
-          overlay={menu()}
-          trigger={['click']}
-          getPopupContainer={(triggerNode: any) =>
-            triggerNode.closest('.action-button')
-          }
-        >
-          <span role="button" className="action-button" tabIndex={0}>
+        <ReportModal
+          show={showModal}
+          onHide={() => setShowModal(false)}
+          userId={user.userId}
+          userEmail={user.email}
+          dashboardId={dashboardId}
+        />
+        {report ? (
+          <>
+            <NoAnimationDropdown
+              // ref={ref}
+              overlay={menu()}
+              trigger={['click']}
+              getPopupContainer={(triggerNode: any) =>
+                triggerNode.closest('.action-button')
+              }
+            >
+              <span role="button" className="action-button" tabIndex={0}>
+                <Icons.Calendar />
+              </span>
+            </NoAnimationDropdown>
+            {currentReportDeleting && (
+              <DeleteModal
+                description={t(
+                  'This action will permanently delete %s.',
+                  currentReportDeleting.name,
+                )}
+                onConfirm={() => {
+                  if (currentReportDeleting) {
+                    handleReportDelete(currentReportDeleting);
+                  }
+                }}
+                onHide={() => setCurrentReportDeleting(null)}
+                open
+                title={t('Delete Report?')}
+              />
+            )}
+          </>
+        ) : (
+          <span
+            role="button"
+            title={t('Schedule email report')}
+            tabIndex={0}
+            className="action-button"
+            onClick={() => setShowModal(true)}
+          >
             <Icons.Calendar />
           </span>
-        </NoAnimationDropdown>
-        {currentReportDeleting && (
-          <DeleteModal
-            description={t(
-              'This action will permanently delete %s.',
-              currentReportDeleting.name,
-            )}
-            onConfirm={() => {
-              if (currentReportDeleting) {
-                handleReportDelete(currentReportDeleting);
-              }
-            }}
-            onHide={() => setCurrentReportDeleting(null)}
-            open
-            title={t('Delete Report?')}
-          />
         )}
       </>
-    ) : (
-      <span
-        role="button"
-        title={t('Schedule email report')}
-        tabIndex={0}
-        className="action-button"
-        onClick={showReportModal}
-      >
-        <Icons.Calendar />
-      </span>
     )
-  ) : null;
+  );
 }
diff --git a/superset-frontend/src/components/ReportModal/index.tsx b/superset-frontend/src/components/ReportModal/index.tsx
index e24d1d7..2bf0f61 100644
--- a/superset-frontend/src/components/ReportModal/index.tsx
+++ b/superset-frontend/src/components/ReportModal/index.tsx
@@ -97,7 +97,6 @@ interface ReportProps {
   userEmail: string;
   dashboardId?: number;
   chart?: ChartObject;
-  creationMethod: string;
   props: any;
 }
 
@@ -169,10 +168,14 @@ const ReportModal: FunctionComponent<ReportProps> = ({
   onReportAdd,
   onHide,
   show = false,
+  dashboardId,
+  chart,
+  userId,
+  userEmail,
   ...props
 }) => {
-  const vizType = props.props.chart?.sliceFormData?.viz_type;
-  const isChart = !!props.props.chart;
+  const vizType = chart?.sliceFormData?.viz_type;
+  const isChart = !!chart;
   const defaultNotificationFormat =
     isChart && TEXT_BASED_VISUALIZATION_TYPES.includes(vizType)
       ? NOTIFICATION_FORMATS.TEXT
@@ -211,19 +214,19 @@ const ReportModal: FunctionComponent<ReportProps> = ({
     // Create new Report
     const newReportValues: Partial<ReportObject> = {
       crontab: currentReport?.crontab,
-      dashboard: props.props.dashboardId,
-      chart: props.props.chart?.id,
+      dashboard: dashboardId,
+      chart: chart?.id,
       description: currentReport?.description,
       name: currentReport?.name,
-      owners: [props.props.userId],
+      owners: [userId],
       recipients: [
         {
-          recipient_config_json: { target: props.props.userEmail },
+          recipient_config_json: { target: userEmail },
           type: 'Email',
         },
       ],
       type: 'Report',
-      creation_method: props.props.creationMethod,
+      creation_method: dashboardId ? 'dashboards' : 'charts',
       active: true,
       report_format: currentReport?.report_format || defaultNotificationFormat,
       timezone: currentReport?.timezone,
diff --git a/superset-frontend/src/dashboard/components/Header/index.jsx b/superset-frontend/src/dashboard/components/Header/index.jsx
index d47f619..c4cb015 100644
--- a/superset-frontend/src/dashboard/components/Header/index.jsx
+++ b/superset-frontend/src/dashboard/components/Header/index.jsx
@@ -162,8 +162,6 @@ class Header extends React.PureComponent {
     this.overwriteDashboard = this.overwriteDashboard.bind(this);
     this.showPropertiesModal = this.showPropertiesModal.bind(this);
     this.hidePropertiesModal = this.hidePropertiesModal.bind(this);
-    this.showReportModal = this.showReportModal.bind(this);
-    this.hideReportModal = this.hideReportModal.bind(this);
   }
 
   componentDidMount() {
@@ -176,7 +174,6 @@ class Header extends React.PureComponent {
         'dashboard_id',
         'dashboards',
         dashboardInfo.id,
-        user.email,
       );
     }
   }
@@ -206,7 +203,6 @@ class Header extends React.PureComponent {
         'dashboard_id',
         'dashboards',
         nextProps.dashboardInfo.id,
-        user.email,
       );
     }
   }
@@ -391,14 +387,6 @@ class Header extends React.PureComponent {
     this.setState({ showingPropertiesModal: false });
   }
 
-  showReportModal() {
-    this.setState({ showingReportModal: true });
-  }
-
-  hideReportModal() {
-    this.setState({ showingReportModal: false });
-  }
-
   canAddReports() {
     if (!isFeatureEnabled(FeatureFlag.ALERT_REPORTS)) {
       return false;
@@ -562,9 +550,9 @@ class Header extends React.PureComponent {
                 </span>
               )}
               <HeaderReportActionsDropdown
-                showReportModal={this.showReportModal}
                 toggleActive={this.props.toggleActive}
                 deleteActiveReport={this.props.deleteActiveReport}
+                dashboardId={dashboardInfo.id}
               />
             </>
           )}
diff --git a/superset-frontend/src/reports/actions/reports.js b/superset-frontend/src/reports/actions/reports.js
index 7b3bc81..28600df 100644
--- a/superset-frontend/src/reports/actions/reports.js
+++ b/superset-frontend/src/reports/actions/reports.js
@@ -31,14 +31,14 @@ export function fetchUISpecificReport(
   userId,
   filter_field,
   creation_method,
-  dashboardId,
+  resourceId,
 ) {
   const queryParams = rison.encode({
     filters: [
       {
         col: filter_field,
         opr: 'eq',
-        value: dashboardId,
+        value: resourceId,
       },
       {
         col: 'creation_method',

[superset] 01/04: pexdax refactor (#16333)

Posted by el...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

elizabeth pushed a commit to branch refactorReports
in repository https://gitbox.apache.org/repos/asf/superset.git

commit 018ff6c1d558658192e25d6b3b0feee940b938a0
Author: AAfghahi <48...@users.noreply.github.com>
AuthorDate: Wed Aug 18 15:58:10 2021 -0400

    pexdax refactor (#16333)
---
 .../HeaderReportActionsDropdown/index.tsx          | 100 ++++++++++++++-------
 .../src/dashboard/components/Header/index.jsx      |  57 ++++--------
 .../src/explore/components/ExploreChartHeader.jsx  |  32 ++-----
 3 files changed, 91 insertions(+), 98 deletions(-)

diff --git a/superset-frontend/src/components/ReportModal/HeaderReportActionsDropdown/index.tsx b/superset-frontend/src/components/ReportModal/HeaderReportActionsDropdown/index.tsx
index 2ffc6f2..4d9ceb8 100644
--- a/superset-frontend/src/components/ReportModal/HeaderReportActionsDropdown/index.tsx
+++ b/superset-frontend/src/components/ReportModal/HeaderReportActionsDropdown/index.tsx
@@ -26,6 +26,7 @@ import { Menu, NoAnimationDropdown } from 'src/common/components';
 import { isFeatureEnabled, FeatureFlag } from 'src/featureFlags';
 
 import DeleteModal from 'src/components/DeleteModal';
+import { UserWithPermissionsAndRoles } from 'src/types/bootstrapTypes';
 
 const deleteColor = (theme: SupersetTheme) => css`
   color: ${theme.colors.error.base};
@@ -40,9 +41,15 @@ export default function HeaderReportActionsDropDown({
   toggleActive: (data: AlertObject, checked: boolean) => void;
   deleteActiveReport: (data: AlertObject) => void;
 }) {
-  const reports = useSelector<any, AlertObject>(state => state.reports);
+  const reports: Record<number, AlertObject> = useSelector<any, AlertObject>(
+    state => state.reports,
+  );
+  const user: UserWithPermissionsAndRoles = useSelector<
+    any,
+    UserWithPermissionsAndRoles
+  >(state => state.user || state.explore?.user);
   const reportsIds = Object.keys(reports);
-  const report = reports[reportsIds[0]];
+  const report: AlertObject = reports[reportsIds[0]];
   const [
     currentReportDeleting,
     setCurrentReportDeleting,
@@ -60,6 +67,23 @@ export default function HeaderReportActionsDropDown({
     setCurrentReportDeleting(null);
   };
 
+  const canAddReports = () => {
+    if (!isFeatureEnabled(FeatureFlag.ALERT_REPORTS)) {
+      return false;
+    }
+    if (!user) {
+      // this is in the case that there is an anonymous user.
+      return false;
+    }
+    const roles = Object.keys(user.roles || []);
+    const permissions = roles.map(key =>
+      user.roles[key].filter(
+        perms => perms[0] === 'menu_access' && perms[1] === 'Manage',
+      ),
+    );
+    return permissions[0].length > 0;
+  };
+
   const menu = () => (
     <Menu selectable={false} css={{ width: '200px' }}>
       <Menu.Item>
@@ -82,36 +106,48 @@ export default function HeaderReportActionsDropDown({
     </Menu>
   );
 
-  return isFeatureEnabled(FeatureFlag.ALERT_REPORTS) ? (
-    <>
-      <NoAnimationDropdown
-        // ref={ref}
-        overlay={menu()}
-        trigger={['click']}
-        getPopupContainer={(triggerNode: any) =>
-          triggerNode.closest('.action-button')
-        }
+  return canAddReports() ? (
+    report ? (
+      <>
+        <NoAnimationDropdown
+          // ref={ref}
+          overlay={menu()}
+          trigger={['click']}
+          getPopupContainer={(triggerNode: any) =>
+            triggerNode.closest('.action-button')
+          }
+        >
+          <span role="button" className="action-button" tabIndex={0}>
+            <Icons.Calendar />
+          </span>
+        </NoAnimationDropdown>
+        {currentReportDeleting && (
+          <DeleteModal
+            description={t(
+              'This action will permanently delete %s.',
+              currentReportDeleting.name,
+            )}
+            onConfirm={() => {
+              if (currentReportDeleting) {
+                handleReportDelete(currentReportDeleting);
+              }
+            }}
+            onHide={() => setCurrentReportDeleting(null)}
+            open
+            title={t('Delete Report?')}
+          />
+        )}
+      </>
+    ) : (
+      <span
+        role="button"
+        title={t('Schedule email report')}
+        tabIndex={0}
+        className="action-button"
+        onClick={showReportModal}
       >
-        <span role="button" className="action-button" tabIndex={0}>
-          <Icons.Calendar />
-        </span>
-      </NoAnimationDropdown>
-      {currentReportDeleting && (
-        <DeleteModal
-          description={t(
-            'This action will permanently delete %s.',
-            currentReportDeleting.name,
-          )}
-          onConfirm={() => {
-            if (currentReportDeleting) {
-              handleReportDelete(currentReportDeleting);
-            }
-          }}
-          onHide={() => setCurrentReportDeleting(null)}
-          open
-          title={t('Delete Report?')}
-        />
-      )}
-    </>
+        <Icons.Calendar />
+      </span>
+    )
   ) : null;
 }
diff --git a/superset-frontend/src/dashboard/components/Header/index.jsx b/superset-frontend/src/dashboard/components/Header/index.jsx
index 9198601..d47f619 100644
--- a/superset-frontend/src/dashboard/components/Header/index.jsx
+++ b/superset-frontend/src/dashboard/components/Header/index.jsx
@@ -164,7 +164,6 @@ class Header extends React.PureComponent {
     this.hidePropertiesModal = this.hidePropertiesModal.bind(this);
     this.showReportModal = this.showReportModal.bind(this);
     this.hideReportModal = this.hideReportModal.bind(this);
-    this.renderReportModal = this.renderReportModal.bind(this);
   }
 
   componentDidMount() {
@@ -400,29 +399,6 @@ class Header extends React.PureComponent {
     this.setState({ showingReportModal: false });
   }
 
-  renderReportModal() {
-    const attachedReportExists = !!Object.keys(this.props.reports).length;
-    return attachedReportExists ? (
-      <HeaderReportActionsDropdown
-        showReportModal={this.showReportModal}
-        toggleActive={this.props.toggleActive}
-        deleteActiveReport={this.props.deleteActiveReport}
-      />
-    ) : (
-      <>
-        <span
-          role="button"
-          title={t('Schedule email report')}
-          tabIndex={0}
-          className="action-button"
-          onClick={this.showReportModal}
-        >
-          <Icons.Calendar />
-        </span>
-      </>
-    );
-  }
-
   canAddReports() {
     if (!isFeatureEnabled(FeatureFlag.ALERT_REPORTS)) {
       return false;
@@ -472,7 +448,6 @@ class Header extends React.PureComponent {
     const userCanEdit = dashboardInfo.dash_edit_perm;
     const userCanShare = dashboardInfo.dash_share_perm;
     const userCanSaveAs = dashboardInfo.dash_save_perm;
-    const shouldShowReport = !editMode && this.canAddReports();
     const refreshLimit =
       dashboardInfo.common.conf.SUPERSET_DASHBOARD_PERIODICAL_REFRESH_LIMIT;
     const refreshWarning =
@@ -568,27 +543,31 @@ class Header extends React.PureComponent {
               )}
             </div>
           )}
-          {editMode && (
+          {editMode ? (
             <UndoRedoKeyListeners
               onUndo={this.handleCtrlZ}
               onRedo={this.handleCtrlY}
             />
-          )}
-
-          {!editMode && userCanEdit && (
+          ) : (
             <>
-              <span
-                role="button"
-                title={t('Edit dashboard')}
-                tabIndex={0}
-                className="action-button"
-                onClick={this.toggleEditMode}
-              >
-                <Icons.EditAlt />
-              </span>
+              {userCanEdit && (
+                <span
+                  role="button"
+                  title={t('Edit dashboard')}
+                  tabIndex={0}
+                  className="action-button"
+                  onClick={this.toggleEditMode}
+                >
+                  <Icons.EditAlt />
+                </span>
+              )}
+              <HeaderReportActionsDropdown
+                showReportModal={this.showReportModal}
+                toggleActive={this.props.toggleActive}
+                deleteActiveReport={this.props.deleteActiveReport}
+              />
             </>
           )}
-          {shouldShowReport && this.renderReportModal()}
 
           {this.state.showingPropertiesModal && (
             <PropertiesModal
diff --git a/superset-frontend/src/explore/components/ExploreChartHeader.jsx b/superset-frontend/src/explore/components/ExploreChartHeader.jsx
index 5d057ca..1f2bb10 100644
--- a/superset-frontend/src/explore/components/ExploreChartHeader.jsx
+++ b/superset-frontend/src/explore/components/ExploreChartHeader.jsx
@@ -20,7 +20,6 @@ import React from 'react';
 import { connect } from 'react-redux';
 import { bindActionCreators } from 'redux';
 import PropTypes from 'prop-types';
-import Icons from 'src/components/Icons';
 import { styled, t } from '@superset-ui/core';
 import { Tooltip } from 'src/components/Tooltip';
 import ReportModal from 'src/components/ReportModal';
@@ -113,7 +112,6 @@ export class ExploreChartHeader extends React.PureComponent {
     this.closePropertiesModal = this.closePropertiesModal.bind(this);
     this.showReportModal = this.showReportModal.bind(this);
     this.hideReportModal = this.hideReportModal.bind(this);
-    this.renderReportModal = this.renderReportModal.bind(this);
   }
 
   componentDidMount() {
@@ -163,30 +161,6 @@ export class ExploreChartHeader extends React.PureComponent {
     this.setState({ showingReportModal: false });
   }
 
-  renderReportModal() {
-    const attachedReportExists = !!Object.keys(this.props.reports).length;
-    return attachedReportExists ? (
-      <HeaderReportActionsDropdown
-        showReportModal={this.showReportModal}
-        hideReportModal={this.hideReportModal}
-        toggleActive={this.props.toggleActive}
-        deleteActiveReport={this.props.deleteActiveReport}
-      />
-    ) : (
-      <>
-        <span
-          role="button"
-          title={t('Schedule email report')}
-          tabIndex={0}
-          className="action-button"
-          onClick={this.showReportModal}
-        >
-          <Icons.Calendar />
-        </span>
-      </>
-    );
-  }
-
   canAddReports() {
     if (!isFeatureEnabled(FeatureFlag.ALERT_REPORTS)) {
       return false;
@@ -287,7 +261,11 @@ export class ExploreChartHeader extends React.PureComponent {
             isRunning={chartStatus === 'loading'}
             status={CHART_STATUS_MAP[chartStatus]}
           />
-          {this.canAddReports() && this.renderReportModal()}
+          <HeaderReportActionsDropdown
+            showReportModal={this.showReportModal}
+            toggleActive={this.props.toggleActive}
+            deleteActiveReport={this.props.deleteActiveReport}
+          />
           <ReportModal
             show={this.state.showingReportModal}
             onHide={this.hideReportModal}