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


The following commit(s) were added to refs/heads/refactorReports by this push:
     new 41a6751  refactor(reports):  Arash/again refactor reports (#16872)
41a6751 is described below

commit 41a67517c6b8c3909b631929469faa920f76713c
Author: AAfghahi <[email protected]>
AuthorDate: Tue Oct 5 16:09:40 2021 -0400

    refactor(reports):  Arash/again refactor reports (#16872)
    
    * pexdax refactor (#16333)
    
    * refactor progress (#16339)
    
    * fix: Header Actions test refactor (#16336)
    
    * fixed tests
    
    * Update index.tsx
    
    Co-authored-by: Elizabeth Thompson <[email protected]>
    
    * code dry (#16358)
    
    * Fetch bug fixed (#16376)
    
    * continued refactoring (#16377)
    
    * refactor: Reports - ReportModal (#16622)
    
    * refactoring progress
    
    * removed consoles
    
    * Working, but with 2 fetches
    
    * it is still not working
    
    Co-authored-by: Lyndsi Kay Williams 
<[email protected]>
    Co-authored-by: Elizabeth Thompson <[email protected]>
---
 .../HeaderReportActionsDropdown/index.tsx          | 26 ++++++++++++++--------
 superset-frontend/src/views/CRUD/alert/types.ts    |  1 +
 2 files changed, 18 insertions(+), 9 deletions(-)

diff --git 
a/superset-frontend/src/components/ReportModal/HeaderReportActionsDropdown/index.tsx
 
b/superset-frontend/src/components/ReportModal/HeaderReportActionsDropdown/index.tsx
index 3ebb164..dff3a9b 100644
--- 
a/superset-frontend/src/components/ReportModal/HeaderReportActionsDropdown/index.tsx
+++ 
b/superset-frontend/src/components/ReportModal/HeaderReportActionsDropdown/index.tsx
@@ -46,13 +46,11 @@ export default function HeaderReportActionsDropDown({
   chart?: ChartState;
 }) {
   const dispatch = useDispatch();
-  const reports: any = useSelector<any>(state =>
-    Object.values(state.reports).filter((report: any) =>
-      dashboardId
-        ? report.dashboard_id === dashboardId
-        : report.chart_id === chart?.id,
-    ),
+  const reports: Record<number, AlertObject> = useSelector<any, AlertObject>(
+    state => state.reports,
   );
+  const report: AlertObject = Object.values(reports)[0];
+  const hasReport = !!report;
   const user: UserWithPermissionsAndRoles = useSelector<
     any,
     UserWithPermissionsAndRoles
@@ -63,7 +61,6 @@ export default function HeaderReportActionsDropDown({
   ] = useState<AlertObject | null>(null);
   const theme = useTheme();
   const [showModal, setShowModal] = useState<boolean>(false);
-  const [showModal, setShowModal] = useState(false);
   const toggleActiveKey = async (data: AlertObject, checked: boolean) => {
     if (data?.id) {
       toggleActive(data, checked);
@@ -103,10 +100,21 @@ export default function HeaderReportActionsDropDown({
         }),
       );
     }
-    return () => {
-    };
   }, []);
 
+  useEffect(() => {
+    if (hasReport && report.dashboard_id !== dashboardId) {
+      dispatch(
+        fetchUISpecificReport({
+          userId: user.userId,
+          filterField: dashboardId ? 'dashboard_id' : 'chart_id',
+          creationMethod: dashboardId ? 'dashboards' : 'charts',
+          resourceId: dashboardId || chart?.id,
+        }),
+      );
+    }
+  }, [dashboardId]);
+
   const menu = () => (
     <Menu selectable={false} css={{ width: '200px' }}>
       <Menu.Item>
diff --git a/superset-frontend/src/views/CRUD/alert/types.ts 
b/superset-frontend/src/views/CRUD/alert/types.ts
index 3f939a0..24e5ddf 100644
--- a/superset-frontend/src/views/CRUD/alert/types.ts
+++ b/superset-frontend/src/views/CRUD/alert/types.ts
@@ -66,6 +66,7 @@ export type AlertObject = {
   created_on?: string;
   crontab?: string;
   dashboard?: MetaObject;
+  dashboard_id?: number;
   database?: MetaObject;
   description?: string;
   grace_period?: number;

Reply via email to