diff --git a/superset-frontend/src/components/ReportModal/HeaderReportActionsDropdown/index.tsx b/superset-frontend/src/components/ReportModal/HeaderReportActionsDropdown/index.tsx index aa4d0c20d8167..79f88ba754eda 100644 --- a/superset-frontend/src/components/ReportModal/HeaderReportActionsDropdown/index.tsx +++ b/superset-frontend/src/components/ReportModal/HeaderReportActionsDropdown/index.tsx @@ -47,15 +47,21 @@ export default function HeaderReportActionsDropDown({ chart?: ChartState; }) { const dispatch = useDispatch(); - const reports: Record = useSelector( - state => state.reports, - ); - const report: AlertObject = Object.values(reports).filter(report => { + const report: AlertObject = useSelector(state => { if (dashboardId) { - return report.dashboard_id === dashboardId; + return state.reports.dashboards?.[dashboardId]; + } + if (chart?.id) { + return state.reports.charts?.[chart.id]; } - return report.chart_id === chart?.id; - })[0]; + return {}; + }); + // const report: ReportObject = Object.values(reports).filter(report => { + // if (dashboardId) { + // return report.dashboards?.[dashboardId]; + // } + // // return report.charts?.[chart?.id] + // })[0]; const user: UserWithPermissionsAndRoles = useSelector< any, diff --git a/superset-frontend/src/dashboard/components/Header/index.jsx b/superset-frontend/src/dashboard/components/Header/index.jsx index 54abaf47eb494..52cb505be758e 100644 --- a/superset-frontend/src/dashboard/components/Header/index.jsx +++ b/superset-frontend/src/dashboard/components/Header/index.jsx @@ -169,6 +169,13 @@ 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 && diff --git a/superset-frontend/src/reports/reducers/reports.js b/superset-frontend/src/reports/reducers/reports.js index de23f572a94fc..a18d72e92c8f0 100644 --- a/superset-frontend/src/reports/reducers/reports.js +++ b/superset-frontend/src/reports/reducers/reports.js @@ -43,14 +43,13 @@ export default function reportsReducer(state = {}, action) { [SET_REPORT]() { // Grabs the first report with a dashboard id that // matches the parameter report's dashboard_id - const reportWithDashboard = action.report.result.find( + const reportWithDashboard = action.report.result?.find( report => !!report.dashboard_id, ); - // Grabs the first report with a chart id that // matches the parameter report's chart.id - const reportWithChart = action.report.result.find( - report => !!report.chart.id, + const reportWithChart = action.report.result?.find( + report => !!report.chart?.id, ); // This organizes report by its type, dashboard or chart @@ -64,12 +63,17 @@ export default function reportsReducer(state = {}, action) { }, }; } + if (reportWithChart) { + return { + ...state, + charts: { + ...state.chart, + [reportWithChart.chart.id]: reportWithChart, + }, + }; + } return { ...state, - charts: { - ...state.chart, - [reportWithChart.chart.id]: reportWithChart, - }, }; },