diff --git a/superset-frontend/src/components/ReportModal/HeaderReportActionsDropdown/index.tsx b/superset-frontend/src/components/ReportModal/HeaderReportActionsDropdown/index.tsx index 45a3fde058cfc..52f9f15c55066 100644 --- a/superset-frontend/src/components/ReportModal/HeaderReportActionsDropdown/index.tsx +++ b/superset-frontend/src/components/ReportModal/HeaderReportActionsDropdown/index.tsx @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -import React, { useState, useEffect, useRef } from 'react'; +import React, { useState, useEffect } from 'react'; import { useSelector, useDispatch } from 'react-redux'; import { t, SupersetTheme, css, useTheme } from '@superset-ui/core'; import Icons from 'src/components/Icons'; @@ -50,19 +50,23 @@ export default function HeaderReportActionsDropDown({ const reports: Record = useSelector( state => state.reports, ); + 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 >(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 dashboardIdRef = useRef(dashboardId); + const [showModal, setShowModal] = useState(false); const toggleActiveKey = async (data: AlertObject, checked: boolean) => { if (data?.id) { toggleActive(data, checked); @@ -105,17 +109,13 @@ export default function HeaderReportActionsDropDown({ }, []); useEffect(() => { - if ( - canAddReports() && - dashboardId && - dashboardId !== dashboardIdRef.current - ) { + if (canAddReports()) { dispatch( fetchUISpecificReport({ userId: user.userId, - filterField: 'dashboard_id', - creationMethod: 'dashboards', - resourceId: dashboardId, + filterField: dashboardId ? 'dashboard_id' : 'chart_id', + creationMethod: dashboardId ? 'dashboards' : 'charts', + resourceId: dashboardId || chart?.id, }), ); } @@ -149,14 +149,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 ? ( <> >>>>>> code dry (#16358) import { antDErrorAlertStyles, StyledModal, @@ -134,7 +131,6 @@ const ReportModal: FunctionComponent = ({ chart, userId, userEmail, -<<<<<<< HEAD creationMethod, ...props }) => { @@ -173,22 +169,6 @@ const ReportModal: FunctionComponent = ({ reportReducer, initialState, ); -======= - props, -}) => { - const vizType = chart?.sliceFormData?.viz_type; - const isChart = !!chart; - const defaultNotificationFormat = - vizType && TEXT_BASED_VISUALIZATION_TYPES.includes(vizType) - ? NOTIFICATION_FORMATS.TEXT - : NOTIFICATION_FORMATS.PNG; - const [currentReport, setCurrentReport] = useReducer< - Reducer | null, ReportActionType> - >(reportReducer, null); - const onReducerChange = useCallback((type: any, payload: any) => { - setCurrentReport({ type, payload }); - }, []); ->>>>>>> code dry (#16358) const [cronError, setCronError] = useState(); const dispatch = useDispatch(); @@ -285,11 +265,7 @@ const ReportModal: FunctionComponent = ({ }} value={currentReport.report_format || defaultNotificationFormat} > -<<<<<<< HEAD {isTextBasedChart && ( -======= - {vizType && TEXT_BASED_VISUALIZATION_TYPES.includes(vizType) && ( ->>>>>>> code dry (#16358) {t('Text embedded in email')} diff --git a/superset-frontend/src/dashboard/components/Header/index.jsx b/superset-frontend/src/dashboard/components/Header/index.jsx index a5fb46dfbe623..54abaf47eb494 100644 --- a/superset-frontend/src/dashboard/components/Header/index.jsx +++ b/superset-frontend/src/dashboard/components/Header/index.jsx @@ -169,13 +169,6 @@ class Header extends React.PureComponent { this.startPeriodicRender(refreshFrequency * 1000); } - componentDidUpdate(prevProps) { - if (this.props.refreshFrequency !== prevProps.refreshFrequency) { - const { refreshFrequency } = this.props; - this.startPeriodicRender(refreshFrequency * 1000); - } - } - UNSAFE_componentWillReceiveProps(nextProps) { if ( UNDO_LIMIT - nextProps.undoLength <= 0 && @@ -554,6 +547,7 @@ class Header extends React.PureComponent { )} ({ ...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 ef320b5f7b9a9..99a9c480abef4 100644 --- a/superset-frontend/src/views/CRUD/alert/types.ts +++ b/superset-frontend/src/views/CRUD/alert/types.ts @@ -62,10 +62,12 @@ export type AlertObject = { chart?: MetaObject; changed_by?: user; changed_on_delta_humanized?: string; + chart_id: number; created_by?: user; created_on?: string; crontab?: string; dashboard?: MetaObject; + dashboard_id?: number; database?: MetaObject; description?: string; force_screenshot: boolean; diff --git a/superset/reports/api.py b/superset/reports/api.py index 645cd24894634..4694e228743b6 100644 --- a/superset/reports/api.py +++ b/superset/reports/api.py @@ -125,12 +125,14 @@ def ensure_alert_reports_enabled(self) -> 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",