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/11/24 18:46:44 UTC

[superset] 10/14: code dry (#16358)

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 8169789207ba98789037ee31209d125f9bcac564
Author: AAfghahi <48...@users.noreply.github.com>
AuthorDate: Fri Aug 20 13:09:40 2021 -0400

    code dry (#16358)
---
 .../HeaderReportActionsDropdown/index.tsx            | 20 +++++++++++++++++++-
 .../src/components/ReportModal/index.tsx             |  3 +--
 .../src/dashboard/components/Header/index.jsx        |  9 +++++++++
 3 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/superset-frontend/src/components/ReportModal/HeaderReportActionsDropdown/index.tsx b/superset-frontend/src/components/ReportModal/HeaderReportActionsDropdown/index.tsx
index 2b5f891..08e2f1e 100644
--- a/superset-frontend/src/components/ReportModal/HeaderReportActionsDropdown/index.tsx
+++ b/superset-frontend/src/components/ReportModal/HeaderReportActionsDropdown/index.tsx
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-import React, { useState, useEffect, useRef } from 'react';
+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';
@@ -28,6 +28,7 @@ import DeleteModal from 'src/components/DeleteModal';
 import { ChartState } from 'src/explore/types';
 import ReportModal from 'src/components/ReportModal';
 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,
   );
@@ -85,6 +89,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>
@@ -118,6 +135,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 8bc79f6..20fecdc 100644
--- a/superset-frontend/src/components/ReportModal/index.tsx
+++ b/superset-frontend/src/components/ReportModal/index.tsx
@@ -83,7 +83,7 @@ interface ReportProps {
   userId: number;
   userEmail: string;
   dashboardId?: number;
-  chart?: ChartObject;
+  chart?: ChartState;
   props: any;
 }
 
@@ -159,7 +159,6 @@ const ReportModal: FunctionComponent<ReportProps> = ({
   chart,
   userId,
   userEmail,
-  ...props
 }) => {
   const vizType = chart?.sliceFormData?.viz_type;
   const isChart = !!chart;
diff --git a/superset-frontend/src/dashboard/components/Header/index.jsx b/superset-frontend/src/dashboard/components/Header/index.jsx
index c8204fc..308b147 100644
--- a/superset-frontend/src/dashboard/components/Header/index.jsx
+++ b/superset-frontend/src/dashboard/components/Header/index.jsx
@@ -167,6 +167,7 @@ class Header extends React.PureComponent {
     const { refreshFrequency } = this.props;
     this.startPeriodicRender(refreshFrequency * 1000);
 <<<<<<< HEAD
+<<<<<<< HEAD
 =======
     if (this.canAddReports()) {
       // this is in case there is an anonymous user.
@@ -178,6 +179,8 @@ class Header extends React.PureComponent {
       );
     }
 >>>>>>> refactor progress (#16339)
+=======
+>>>>>>> code dry (#16358)
   }
 
   componentDidUpdate(prevProps) {
@@ -202,6 +205,7 @@ class Header extends React.PureComponent {
       this.props.setMaxUndoHistoryExceeded();
     }
 <<<<<<< HEAD
+<<<<<<< HEAD
 =======
     if (
       this.canAddReports() &&
@@ -216,6 +220,8 @@ class Header extends React.PureComponent {
       );
     }
 >>>>>>> refactor progress (#16339)
+=======
+>>>>>>> code dry (#16358)
   }
 
   componentWillUnmount() {
@@ -398,6 +404,7 @@ class Header extends React.PureComponent {
   }
 
 <<<<<<< HEAD
+<<<<<<< HEAD
   showReportModal() {
     this.setState({ showingReportModal: true });
   }
@@ -424,6 +431,8 @@ class Header extends React.PureComponent {
 >>>>>>> refactor progress (#16339)
   }
 
+=======
+>>>>>>> code dry (#16358)
   render() {
     const {
       dashboardTitle,