From 7c902c97bc7b6a19190645c8139356b989a19f67 Mon Sep 17 00:00:00 2001 From: Arash Date: Tue, 5 Oct 2021 23:37:33 -0400 Subject: [PATCH] next changes --- .../HeaderReportActionsDropdown/index.tsx | 17 +++++++++++------ .../src/reports/reducers/reports.js | 3 +++ superset-frontend/src/views/CRUD/alert/types.ts | 1 + 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/superset-frontend/src/components/ReportModal/HeaderReportActionsDropdown/index.tsx b/superset-frontend/src/components/ReportModal/HeaderReportActionsDropdown/index.tsx index c23d187b66d1a..5eb4448e5b4a5 100644 --- a/superset-frontend/src/components/ReportModal/HeaderReportActionsDropdown/index.tsx +++ b/superset-frontend/src/components/ReportModal/HeaderReportActionsDropdown/index.tsx @@ -49,8 +49,13 @@ export default function HeaderReportActionsDropDown({ const reports: Record = useSelector( state => state.reports, ); - const report: AlertObject = Object.values(reports)[0]; - const hasReport = !!report; + const report: AlertObject = Object.values(reports).filter(report => { + if (dashboardId) { + return report.dashboard_id === dashboardId; + } + return report.chart_id === chart?.id; + })[0]; + const user: UserWithPermissionsAndRoles = useSelector< any, UserWithPermissionsAndRoles @@ -103,7 +108,7 @@ export default function HeaderReportActionsDropDown({ }, []); useEffect(() => { - if (hasReport && report.dashboard_id !== dashboardId) { + if (canAddReports()) { dispatch( fetchUISpecificReport({ userId: user.userId, @@ -121,8 +126,8 @@ export default function HeaderReportActionsDropDown({ {t('Email reports active')} toggleActiveKey(reports, checked)} + checked={report?.active} + onClick={(checked: boolean) => toggleActiveKey(report, checked)} size="small" css={{ marginLeft: theme.gridUnit * 2 }} /> @@ -131,7 +136,7 @@ export default function HeaderReportActionsDropDown({ {t('Edit email report')} setCurrentReportDeleting(reports)} + onClick={() => setCurrentReportDeleting(report)} css={deleteColor} > {t('Delete email report')} diff --git a/superset-frontend/src/reports/reducers/reports.js b/superset-frontend/src/reports/reducers/reports.js index 8b582d0d0cc1d..54cf493fd5cea 100644 --- a/superset-frontend/src/reports/reducers/reports.js +++ b/superset-frontend/src/reports/reducers/reports.js @@ -19,10 +19,13 @@ /* eslint-disable camelcase */ import { SET_REPORT, ADD_REPORT, EDIT_REPORT } from '../actions/reports'; +// Talk about the delete + export default function reportsReducer(state = {}, action) { const actionHandlers = { [SET_REPORT]() { return { + ...state, ...action.report.result.reduce( (obj, report) => ({ ...obj, [report.id]: report }), {}, diff --git a/superset-frontend/src/views/CRUD/alert/types.ts b/superset-frontend/src/views/CRUD/alert/types.ts index 24e5ddf13770a..b0319c9f83385 100644 --- a/superset-frontend/src/views/CRUD/alert/types.ts +++ b/superset-frontend/src/views/CRUD/alert/types.ts @@ -62,6 +62,7 @@ export type AlertObject = { chart?: MetaObject; changed_by?: user; changed_on_delta_humanized?: string; + chart_id: number; created_by?: user; created_on?: string; crontab?: string;