2023-09-29 12:29:22 +00:00
|
|
|
'use client';
|
2023-12-03 11:07:03 +00:00
|
|
|
import { createContext, ReactNode } from 'react';
|
2023-12-13 04:05:45 +00:00
|
|
|
import { Loading } from 'react-basics';
|
2023-08-21 09:06:09 +00:00
|
|
|
import { useReport } from 'components/hooks';
|
2023-09-29 12:29:22 +00:00
|
|
|
import styles from './Report.module.css';
|
2023-12-03 11:07:03 +00:00
|
|
|
import classNames from 'classnames';
|
2023-05-29 04:37:34 +00:00
|
|
|
|
|
|
|
|
export const ReportContext = createContext(null);
|
|
|
|
|
|
2023-12-03 11:07:03 +00:00
|
|
|
export interface ReportProps {
|
|
|
|
|
reportId: string;
|
|
|
|
|
defaultParameters: { [key: string]: any };
|
|
|
|
|
children: ReactNode;
|
|
|
|
|
className?: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function Report({ reportId, defaultParameters, children, className }: ReportProps) {
|
2023-05-29 04:37:34 +00:00
|
|
|
const report = useReport(reportId, defaultParameters);
|
2023-05-18 06:20:06 +00:00
|
|
|
|
2023-10-16 03:24:28 +00:00
|
|
|
if (!report) {
|
2023-12-13 04:05:45 +00:00
|
|
|
return reportId ? <Loading position="page" /> : null;
|
2023-10-16 03:24:28 +00:00
|
|
|
}
|
|
|
|
|
|
2023-05-20 16:02:08 +00:00
|
|
|
return (
|
2023-12-13 04:05:45 +00:00
|
|
|
<ReportContext.Provider value={report}>
|
2023-12-03 11:07:03 +00:00
|
|
|
<div className={classNames(styles.container, className)}>{children}</div>
|
2023-05-29 04:37:34 +00:00
|
|
|
</ReportContext.Provider>
|
2023-05-20 16:02:08 +00:00
|
|
|
);
|
2023-05-18 06:20:06 +00:00
|
|
|
}
|
2023-05-20 16:02:08 +00:00
|
|
|
|
|
|
|
|
export default Report;
|