From 6046f88424dd49dbbb19be9fb15b7d5e171bdfbc Mon Sep 17 00:00:00 2001 From: AAfghahi <48933336+AAfghahi@users.noreply.github.com> Date: Tue, 5 Oct 2021 16:09:40 -0400 Subject: [PATCH] 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 * 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 <55605634+lyndsiWilliams@users.noreply.github.com> Co-authored-by: Elizabeth Thompson --- .../HeaderReportActionsDropdown/index.tsx | 23 ++++++++++++++----- .../src/views/CRUD/alert/types.ts | 1 + 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/superset-frontend/src/components/ReportModal/HeaderReportActionsDropdown/index.tsx b/superset-frontend/src/components/ReportModal/HeaderReportActionsDropdown/index.tsx index 357bd5b3c8ad0..c23d187b66d1a 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(state => - Object.values(state.reports).filter((report: any) => - dashboardId - ? report.dashboard_id === dashboardId - : report.chart_id === chart?.id, - ), + const reports: Record = useSelector( + state => state.reports, ); + const report: AlertObject = Object.values(reports)[0]; + const hasReport = !!report; const user: UserWithPermissionsAndRoles = useSelector< any, UserWithPermissionsAndRoles @@ -104,6 +102,19 @@ export default function HeaderReportActionsDropDown({ } }, []); + 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 = () => ( diff --git a/superset-frontend/src/views/CRUD/alert/types.ts b/superset-frontend/src/views/CRUD/alert/types.ts index 3f939a03bcfa1..24e5ddf13770a 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;