umami/src/app/(main)/reports/[id]/Report.tsx

32 lines
851 B
TypeScript
Raw Normal View History

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';
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';
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) {
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
export default Report;