diff --git a/superset-frontend/src/components/ReportModal/HeaderReportActionsDropdown/index.tsx b/superset-frontend/src/components/ReportModal/HeaderReportActionsDropdown/index.tsx index 3003c00ae7598..357bd5b3c8ad0 100644 --- a/superset-frontend/src/components/ReportModal/HeaderReportActionsDropdown/index.tsx +++ b/superset-frontend/src/components/ReportModal/HeaderReportActionsDropdown/index.tsx @@ -46,21 +46,23 @@ export default function HeaderReportActionsDropDown({ chart?: ChartState; }) { const dispatch = useDispatch(); - const reports: Record = useSelector( - state => state.reports, + const reports: any = useSelector(state => + Object.values(state.reports).filter((report: any) => + dashboardId + ? report.dashboard_id === dashboardId + : report.chart_id === chart?.id, + ), ); const user: UserWithPermissionsAndRoles = useSelector< any, UserWithPermissionsAndRoles >(state => state.user || state.explore?.user); - const reportsIds = Object.keys(reports || []); - const report: AlertObject = reports?.[reportsIds[0]]; const [ currentReportDeleting, setCurrentReportDeleting, ] = useState(null); const theme = useTheme(); - const [showModal, setShowModal] = useState(false); + const [showModal, setShowModal] = useState(false); const toggleActiveKey = async (data: AlertObject, checked: boolean) => { if (data?.id) { toggleActive(data, checked); @@ -102,27 +104,14 @@ export default function HeaderReportActionsDropDown({ } }, []); - useEffect(() => { - if (canAddReports()) { - dispatch( - fetchUISpecificReport({ - userId: user.userId, - filterField: 'dashboard_id', - creationMethod: 'dashboards', - resourceId: dashboardId, - }), - ); - } - }, [dashboardId]); - const menu = () => ( {t('Email reports active')} toggleActiveKey(report, checked)} + checked={reports?.active} + onClick={(checked: boolean) => toggleActiveKey(reports, checked)} size="small" css={{ marginLeft: theme.gridUnit * 2 }} /> @@ -131,7 +120,7 @@ export default function HeaderReportActionsDropDown({ {t('Edit email report')} setCurrentReportDeleting(report)} + onClick={() => setCurrentReportDeleting(reports)} css={deleteColor} > {t('Delete email report')} @@ -143,14 +132,14 @@ export default function HeaderReportActionsDropDown({ canAddReports() && ( <> setShowModal(false)} userId={user.userId} + showModal={showModal} + onHide={() => setShowModal(false)} userEmail={user.email} dashboardId={dashboardId} chart={chart} /> - {report ? ( + {reports ? ( <> void; addSuccessToast: (msg: string) => void; addReport: (report?: ReportObject) => {}; - onHide: () => {}; + onHide: () => void; onReportAdd: (report?: ReportObject) => {}; - show: boolean; + showModal: boolean; userId: number; userEmail: string; dashboardId?: number; chart?: ChartState; - props: any; + props?: any; } interface ReportPayloadType { @@ -154,7 +153,7 @@ const reportReducer = ( const ReportModal: FunctionComponent = ({ onReportAdd, onHide, - show = false, + showModal = false, dashboardId, chart, userId, @@ -291,7 +290,7 @@ const ReportModal: FunctionComponent = ({ return ( = ({ ); }; -const mapDispatchToProps = (dispatch: any) => - bindActionCreators({ addReport, editReport }, dispatch); - -export default connect(null, mapDispatchToProps)(withToasts(ReportModal)); +export default withToasts(ReportModal); diff --git a/superset-frontend/src/dashboard/components/Header/index.jsx b/superset-frontend/src/dashboard/components/Header/index.jsx index fa1e6a1493f19..9449e258bd026 100644 --- a/superset-frontend/src/dashboard/components/Header/index.jsx +++ b/superset-frontend/src/dashboard/components/Header/index.jsx @@ -517,6 +517,7 @@ class Header extends React.PureComponent { )} Optional[Response]: "changed_by.last_name", "changed_on", "changed_on_delta_humanized", + "chart_id", "created_by.first_name", "created_by.last_name", "created_on", "creation_method", "crontab", "crontab_humanized", + "dashboard_id", "description", "id", "last_eval_dttm",