Skip to content

Commit

Permalink
refactor(reports): Arash/again refactor reports (apache#16872)
Browse files Browse the repository at this point in the history
* pexdax refactor (apache#16333)

* refactor progress (apache#16339)

* fix: Header Actions test refactor (apache#16336)

* fixed tests

* Update index.tsx

Co-authored-by: Elizabeth Thompson <eschutho@gmail.com>

* code dry (apache#16358)

* Fetch bug fixed (apache#16376)

* continued refactoring (apache#16377)

* refactor: Reports - ReportModal (apache#16622)

* refactoring progress

* removed consoles

* Working, but with 2 fetches

* it is still not working

Co-authored-by: Lyndsi Kay Williams <55605634+lyndsiWilliams@users.noreply.github.com>
Co-authored-by: Elizabeth Thompson <eschutho@gmail.com>
  • Loading branch information
3 people committed Oct 28, 2021
1 parent 8827a04 commit 6046f88
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
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 Down Expand Up @@ -104,6 +102,19 @@ export default function HeaderReportActionsDropDown({
}
}, []);

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

0 comments on commit 6046f88

Please sign in to comment.