Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(reports): Arash/again refactor reports #16872

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,11 @@ export default function HeaderReportActionsDropDown({
chart?: ChartState;
}) {
const dispatch = useDispatch();
const reports: any = useSelector<any>(state =>
Object.values(state.reports).filter((report: any) =>
dashboardId
? report.dashboard_id === dashboardId
: report.chart_id === chart?.id,
),
const reports: Record<number, AlertObject> = useSelector<any, AlertObject>(
state => state.reports,
);
const report: AlertObject = Object.values(reports)[0];
const hasReport = !!report;
const user: UserWithPermissionsAndRoles = useSelector<
any,
UserWithPermissionsAndRoles
Expand All @@ -63,7 +61,6 @@ export default function HeaderReportActionsDropDown({
] = useState<AlertObject | null>(null);
const theme = useTheme();
const [showModal, setShowModal] = useState<boolean>(false);
const [showModal, setShowModal] = useState(false);
const toggleActiveKey = async (data: AlertObject, checked: boolean) => {
if (data?.id) {
toggleActive(data, checked);
Expand Down Expand Up @@ -103,10 +100,21 @@ export default function HeaderReportActionsDropDown({
}),
);
}
return () => {
};
}, []);

useEffect(() => {
if (hasReport && report.dashboard_id !== dashboardId) {
dispatch(
fetchUISpecificReport({
userId: user.userId,
filterField: dashboardId ? 'dashboard_id' : 'chart_id',
creationMethod: dashboardId ? 'dashboards' : 'charts',
resourceId: dashboardId || chart?.id,
}),
);
}
}, [dashboardId]);

const menu = () => (
<Menu selectable={false} css={{ width: '200px' }}>
<Menu.Item>
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 @@ -66,6 +66,7 @@ export type AlertObject = {
created_on?: string;
crontab?: string;
dashboard?: MetaObject;
dashboard_id?: number;
database?: MetaObject;
description?: string;
grace_period?: number;
Expand Down