Reporting and Data Export
Relevant source files
The following files were used as context for generating this wiki page:
- apps/web/core/components/pages/time-and-activity/export/time-activity-export-menu.tsx
- apps/web/core/components/pages/time-and-activity/export/time-activity-pdf.tsx
- apps/web/core/hooks/activities/use-time-activity-export.ts
- apps/web/core/lib/config/export-config.ts
- apps/web/core/components/pages/dashboard/app-url/productivity-pdf.tsx
- apps/web/app/[locale]/(main)/dashboard/app-url/[teamId]/page.tsx
- apps/web/core/components/pages/dashboard/pdf/index.tsx
The Reporting and Data Export system in Ever Teams provides functionality for users to generate and download reports based on time, activity, and productivity data. The primary export format currently implemented is PDF, with placeholders for future CSV and XLSX support.
The architecture is designed to be modular, separating the user interface, data processing logic, and document rendering. It leverages the @react-pdf/renderer library for creating dynamic PDF documents from React components. The system is also built with performance in mind, including mechanisms to validate and optimize exports for large datasets.
Core Architecture
The export functionality is initiated from UI components, which trigger a data processing hook. This hook transforms raw application data into a standardized format, which is then passed to a dedicated PDF rendering component to generate the final downloadable file.
This diagram illustrates the high-level flow from user interaction to file download.
UI Components
The user-facing part of the export feature is handled by specific React components.
TimeActivityExportMenu
This component renders a dropdown menu with export options. It is the primary entry point for a user to initiate a data export.
Key Features:
- Renders an "Export" button with a dropdown.
- Provides options for PDF, CSV, and XLSX formats (though only PDF is fully implemented).
- Uses
@react-pdf/renderer'sPDFDownloadLinkto handle the PDF generation and download process in the background. - Manages the state for a progress modal (
ExportProgressModal) for asynchronous exports like CSV/XLSX. - Constructs the PDF document by passing transformed data and metadata to a PDF component (e.g.,
TimeActivityPDF).
Sources: apps/web/core/components/pages/time-and-activity/export/time-activity-export-menu.tsx:43-345
Component Props
| Prop | Type | Description |
|---|---|---|
rapportDailyActivity | DailyActivityReport[] | The raw daily activity data to be exported. |
isManage | boolean | Flag to determine if the user has manager permissions for data filtering. |
currentFilters | FilterState | The currently applied filters (teams, members, etc.). |
startDate | Date | The start date of the report period. |
endDate | Date | The end date of the report period. |
groupByType | GroupByType | The grouping strategy for the report (e.g., 'daily', 'member'). |
buttonClassName | string | Optional CSS class for styling the export button. |
Sources: apps/web/core/components/pages/time-and-activity/export/time-activity-export-menu.tsx:29-37
Data Handling and Transformation
The useTimeActivityExport hook is central to processing data for export. It encapsulates the logic for filtering, transforming, and summarizing activity data.
useTimeActivityExport Hook
This hook prepares the data received from the application state for export.
Responsibilities:
- Permission-based Filtering: If the user is not a manager (
isManageis false), it filters therapportDailyActivityto include only the authenticated user's data. - Data Structure Compatibility: It can process two different shapes of activity data by using type guards:
hasLogsStructureandhasEmployeesStructure. This ensures backward compatibility or flexibility with different API responses. - Data Transformation: It iterates through the raw activity data and transforms it into a flattened, standardized
ExportData[]array, which is easier for rendering components to consume. - Performance Optimization: It integrates with the export configuration system (
getOptimalExportConfig,validateExportFeasibility) to ensure that large exports are handled efficiently. - Summary Generation: It calculates a summary of the exportable data, including the total number of records.
Sources: apps/web/core/hooks/activities/use-time-activity-export.ts:63-288
The following diagram shows the data transformation logic within the hook.
ExportData Structure
This interface defines the standardized format for a single row of exportable data.
| Field | Type | Description |
|---|---|---|
date | string | The date of the activity. |
member | string | The name of the team member. |
project | string | The name of the project. |
task | string | The title of the task. |
trackedHours | string | The formatted duration of time tracked. |
earnings | string | The calculated earnings for the time. |
activityLevel | string | The average activity level as a percentage. |
Sources: apps/web/core/hooks/activities/use-time-activity-export.ts:40-48
PDF Generation
PDF documents are generated using the @react-pdf/renderer library, which allows for creating PDFs with React components.
PDF Components
Components like TimeActivityPDF, ProductivityPDF, and TeamStatsPDF define the layout and content of the PDF files. They are structured similarly to standard React components but use primitives from the library (e.g., <Document>, <Page>, <View>, <Text>).
Example: TimeActivityPDF
- Receives props such as
data,title,startDate,endDate,appliedFilters, andsummary. - Defines styles using
StyleSheet.create. - Renders a header with the report title and date range.
- Optionally displays a section for applied filters.
- Shows a summary block with key metrics (total hours, earnings, etc.).
- Renders a table with headers and rows, mapping over the
dataprop. - Includes a footer with the application name.
Sources: apps/web/core/components/pages/time-and-activity/export/time-activity-pdf.tsx:8-199, apps/web/core/components/pages/dashboard/app-url/productivity-pdf.tsx:8-379, apps/web/core/components/pages/dashboard/pdf/index.tsx:10-252
PDF Generation Sequence
The following diagram shows the sequence of events when a user clicks the PDF export option.
Performance and Configuration
To handle potentially large reports, a dedicated configuration and monitoring system is in place.
export-config.ts
This file provides utilities to manage export performance.
ExportPerformanceMonitor: A class to start a timer, add checkpoints, and log performance metrics during the export process. This is used in development to identify bottlenecks.getOptimalExportConfig(recordCount): A function that returns configuration settings (e.g., chunk size, processing strategy) based on the number of records to be exported. This allows the system to adapt its approach for small vs. large datasets.validateExportFeasibility(recordCount, config): A function that checks if an export is likely to succeed based on the record count and configuration, preventing browser crashes or long hangs on extremely large exports.
Sources: apps/web/core/lib/config/export-config.ts, apps/web/core/hooks/activities/use-time-activity-export.ts:108-118