umami/src/app/(main)/reports/[reportId]/ReportPage.tsx

34 lines
812 B
TypeScript
Raw Normal View History

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';
2024-02-06 07:59:33 +00:00
import classNames from 'classnames';
import { useReport } from 'components/hooks';
2023-09-29 12:29:22 +00:00
import styles from './Report.module.css';
export const ReportContext = createContext(null);
2024-02-06 07:59:33 +00:00
export function ReportPage({
reportId,
defaultParameters,
children,
className,
}: {
2023-12-03 11:07:03 +00:00
reportId: string;
defaultParameters: { [key: string]: any };
children: ReactNode;
className?: string;
2024-02-06 07:59:33 +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>
</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
2024-02-06 07:59:33 +00:00
export default ReportPage;