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:42 UTC

[superset] 08/14: refactor progress (#16339)

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 eee7b5155f70a3b2f15e9fe5a7ecf65393d9338c
Author: Lyndsi Kay Williams <55...@users.noreply.github.com>
AuthorDate: Thu Aug 19 12:19:33 2021 -0500

    refactor progress (#16339)
---
 .../HeaderReportActionsDropdown/index.tsx          | 92 ++++++++++++----------
 .../src/components/ReportModal/index.tsx           |  3 +-
 .../src/dashboard/components/Header/index.jsx      | 48 ++++++++++-
 3 files changed, 98 insertions(+), 45 deletions(-)

diff --git a/superset-frontend/src/components/ReportModal/HeaderReportActionsDropdown/index.tsx b/superset-frontend/src/components/ReportModal/HeaderReportActionsDropdown/index.tsx
index c43fbf6..f89eefb 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 { ChartState } from 'src/explore/types';
+import ReportModal from 'src/components/ReportModal';
 import { UserWithPermissionsAndRoles } from 'src/types/bootstrapTypes';
 
 const deleteColor = (theme: SupersetTheme) => css`
@@ -36,13 +37,10 @@ export default function HeaderReportActionsDropDown({
   toggleActive,
   deleteActiveReport,
   dashboardId,
-  showReportModal,
 }: {
-  showReportModal: () => void;
   toggleActive: (data: AlertObject, checked: boolean) => void;
   deleteActiveReport: (data: AlertObject) => void;
   dashboardId?: number;
-  chart?: ChartState;
 }) {
   const reports: Record<number, AlertObject> = useSelector<any, AlertObject>(
     state => state.reports,
@@ -59,7 +57,6 @@ export default function HeaderReportActionsDropDown({
   ] = useState<AlertObject | null>(null);
   const theme = useTheme();
   const [showModal, setShowModal] = useState(false);
-  const dashboardIdRef = useRef(dashboardId);
   const toggleActiveKey = async (data: AlertObject, checked: boolean) => {
     if (data?.id) {
       toggleActive(data, checked);
@@ -112,48 +109,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 20fecdc..8bc79f6 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?: ChartState;
+  chart?: ChartObject;
   props: any;
 }
 
@@ -159,6 +159,7 @@ 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 586eb3e..c8204fc 100644
--- a/superset-frontend/src/dashboard/components/Header/index.jsx
+++ b/superset-frontend/src/dashboard/components/Header/index.jsx
@@ -161,13 +161,23 @@ 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() {
     const { refreshFrequency } = this.props;
     this.startPeriodicRender(refreshFrequency * 1000);
+<<<<<<< HEAD
+=======
+    if (this.canAddReports()) {
+      // this is in case there is an anonymous user.
+      this.props.fetchUISpecificReport(
+        user.userId,
+        'dashboard_id',
+        'dashboards',
+        dashboardInfo.id,
+      );
+    }
+>>>>>>> refactor progress (#16339)
   }
 
   componentDidUpdate(prevProps) {
@@ -191,6 +201,21 @@ class Header extends React.PureComponent {
     ) {
       this.props.setMaxUndoHistoryExceeded();
     }
+<<<<<<< HEAD
+=======
+    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,
+      );
+    }
+>>>>>>> refactor progress (#16339)
   }
 
   componentWillUnmount() {
@@ -372,12 +397,31 @@ class Header extends React.PureComponent {
     this.setState({ showingPropertiesModal: false });
   }
 
+<<<<<<< HEAD
   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;
+>>>>>>> refactor progress (#16339)
   }
 
   render() {