Skip to content

Commit

Permalink
next changes
Browse files Browse the repository at this point in the history
  • Loading branch information
AAfghahi committed Oct 28, 2021
1 parent 6046f88 commit 7c902c9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,13 @@ export default function HeaderReportActionsDropDown({
const reports: Record<number, AlertObject> = useSelector<any, AlertObject>(
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
Expand Down Expand Up @@ -103,7 +108,7 @@ export default function HeaderReportActionsDropDown({
}, []);

useEffect(() => {
if (hasReport && report.dashboard_id !== dashboardId) {
if (canAddReports()) {
dispatch(
fetchUISpecificReport({
userId: user.userId,
Expand All @@ -121,8 +126,8 @@ export default function HeaderReportActionsDropDown({
{t('Email reports active')}
<Switch
data-test="toggle-active"
checked={reports?.active}
onClick={(checked: boolean) => toggleActiveKey(reports, checked)}
checked={report?.active}
onClick={(checked: boolean) => toggleActiveKey(report, checked)}
size="small"
css={{ marginLeft: theme.gridUnit * 2 }}
/>
Expand All @@ -131,7 +136,7 @@ export default function HeaderReportActionsDropDown({
{t('Edit email report')}
</Menu.Item>
<Menu.Item
onClick={() => setCurrentReportDeleting(reports)}
onClick={() => setCurrentReportDeleting(report)}
css={deleteColor}
>
{t('Delete email report')}
Expand Down
3 changes: 3 additions & 0 deletions superset-frontend/src/reports/reducers/reports.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }),
{},
Expand Down
1 change: 1 addition & 0 deletions superset-frontend/src/views/CRUD/alert/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 7c902c9

Please sign in to comment.