-
Notifications
You must be signed in to change notification settings - Fork 74
[Feat]: Activity Report Implementation #3607
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Add comprehensive activity report interfaces with proper TypeScript types - Create enums for activity sources, log types, and grouping options - Move IActivityReportParams to dedicated file - Integrate with existing buildTimeLogParams utility - Update getActivityReportRequest to use proper typing Closes #[ticket-number]
- Add TimeLogType import for proper typing - Cast source parameter to any[] temporarily - Fix type assertions for logType parameter - Ensure proper type handling in activity report endpoint Part of activity report implementation
- Add getActivityReport function for fetching activity data - Include comprehensive TypeScript interface for parameters - Add proper query string handling with qs.stringify - Set sensible defaults for optional parameters - Include detailed JSDoc with usage example Part of activity report implementation
- Add activity report state management - Implement fetchActivityReport using shared fetchReport pattern - Include activity report in filter updates - Add loading state handling - Update type definitions for queryFn Part of activity report implementation
- Add activityReportState atom in time-logs store - Replace local state with global atom in useReportActivity - Update activity report typing with IActivityReport - Clean up unused imports and formatting - Comment out unused variable in AppUrls component Part of activity report state management improvements
WalkthroughThe changes integrate an activity reporting feature throughout the application. A new GET endpoint was added to retrieve activity reports based on query parameters. The existing reporting hook was enhanced by adding state management and functions to fetch and update activity data. Additionally, new TypeScript interfaces and types were introduced for structured reporting data and timesheet statistics. Client and server services now include methods to request activity reports, and a new state atom was added for storing received reports. Changes
Sequence Diagram(s)sequenceDiagram
participant C as Component
participant H as useReportActivity Hook
participant A as Client API (getActivityReport)
participant S as Server GET Handler
C->>H: Update date range / filters
H->>A: Call fetchActivityReport
A->>S: Request GET /timesheet/activity/report with query params
S-->>A: Return activity report data (200) or error (400/500)
A-->>H: Provide fetched report data
H-->>C: Update state with activity report results
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Warning There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure. 🔧 ESLint
apps/web/app/hooks/features/useReportActivity.tsOops! Something went wrong! :( ESLint: 8.46.0 ESLint couldn't find the config "next/core-web-vitals" to extend from. Please check that the name of the config is correct. The config "next/core-web-vitals" was referenced from the config file in "/apps/web/.eslintrc.json". If you still have problems, please stop by https://eslint.org/chat/help to chat with the team. apps/web/app/interfaces/activity/IActivityReport.tsOops! Something went wrong! :( ESLint: 8.46.0 ESLint couldn't find the config "next/core-web-vitals" to extend from. Please check that the name of the config is correct. The config "next/core-web-vitals" was referenced from the config file in "/apps/web/.eslintrc.json". If you still have problems, please stop by https://eslint.org/chat/help to chat with the team. apps/web/app/[locale]/dashboard/app-url/[teamId]/page.tsxOops! Something went wrong! :( ESLint: 8.46.0 ESLint couldn't find the config "next/core-web-vitals" to extend from. Please check that the name of the config is correct. The config "next/core-web-vitals" was referenced from the config file in "/apps/web/.eslintrc.json". If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.
✨ Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🧹 Nitpick comments (6)
apps/web/app/interfaces/activity/IActivityReport.ts (2)
54-54
: Consider using string literal unions for better type safety.The properties
payPeriod
andemployeeLevel
could benefit from more specific type definitions.- payPeriod: 'NONE' | 'TWICE_PER_MONTH'; + payPeriod: PayPeriodType; - employeeLevel: 'A' | 'B' | 'C'; + employeeLevel: EmployeeLevelType; +export type PayPeriodType = 'NONE' | 'TWICE_PER_MONTH'; +export type EmployeeLevelType = 'A' | 'B' | 'C';Also applies to: 58-58
85-85
: Add validation for percentage format.The
duration_percentage
property is typed as string but should include format validation.- duration_percentage: string; + duration_percentage: `${number}%`;apps/web/app/api/timesheet/activity/report/route.ts (1)
73-80
: Consider using custom error types for better error handling.Using custom error types would allow for more specific error handling and responses.
+class ActivityReportError extends Error { + constructor( + message: string, + public statusCode: number = 500 + ) { + super(message); + this.name = 'ActivityReportError'; + } +} return new Response( JSON.stringify({ message: 'Internal server error', - error: error instanceof Error ? error.message : 'Unknown error' + error: error instanceof ActivityReportError + ? error.message + : 'Unknown error' }),apps/web/app/hooks/features/useReportActivity.ts (2)
217-218
: Consider adding error handling for individual promises.The Promise.all() calls in
updateDateRange
andupdateFilters
could fail silently if any individual promise rejects.Consider handling individual promise failures:
-Promise.all([ - fetchReportActivity(newProps), - fetchDailyReport(newProps), - fetchStatisticsCounts(newProps), - fetchActivityReport(newProps) -]).catch(console.error); +Promise.allSettled([ + fetchReportActivity(newProps).catch(err => console.error('Failed to fetch report activity:', err)), + fetchDailyReport(newProps).catch(err => console.error('Failed to fetch daily report:', err)), + fetchStatisticsCounts(newProps).catch(err => console.error('Failed to fetch statistics:', err)), + fetchActivityReport(newProps).catch(err => console.error('Failed to fetch activity report:', err)) +]);Also applies to: 229-230
238-243
: Consider adding retry logic for initial data fetching.The initial data fetching in useEffect could benefit from retry logic to handle temporary network issues.
Consider implementing a retry mechanism:
const retryFetch = async (fn: () => Promise<any>, retries = 3, delay = 1000) => { try { return await fn(); } catch (error) { if (retries > 0) { await new Promise(resolve => setTimeout(resolve, delay)); return retryFetch(fn, retries - 1, delay * 2); } throw error; } }; // Usage in useEffect if (user) { Promise.allSettled([ retryFetch(() => fetchReportActivity()), retryFetch(() => fetchDailyReport()), retryFetch(() => fetchStatisticsCounts()), retryFetch(() => fetchActivityReport()) ]).catch(console.error); }apps/web/app/services/client/api/timer/timer-log.ts (1)
369-415
: Add input validation and consider using a type-safe query builder.The function could benefit from input validation and a more type-safe approach to query building.
Consider these improvements:
// Add input validation if (!organizationId || !tenantId || !startDate || !endDate) { throw new Error('Required parameters missing: organizationId, tenantId, startDate, and endDate are required'); } // Validate activity level range if (activityLevel.start < 0 || activityLevel.end > 100 || activityLevel.start >= activityLevel.end) { throw new Error('Invalid activity level range'); } // Use a type-safe query builder const queryParams = { activityLevel, organizationId, tenantId, startDate: startDate instanceof Date ? startDate.toISOString() : startDate, endDate: endDate instanceof Date ? endDate.toISOString() : endDate, timeZone, groupBy, ...(projectIds?.length > 0 && { projectIds }), ...(employeeIds?.length > 0 && { employeeIds }), ...(source?.length > 0 && { source }), ...(logType?.length > 0 && { logType }) };
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (8)
apps/web/app/[locale]/dashboard/app-url/[teamId]/page.tsx
(1 hunks)apps/web/app/api/timesheet/activity/report/route.ts
(1 hunks)apps/web/app/hooks/features/useReportActivity.ts
(5 hunks)apps/web/app/interfaces/activity/IActivityReport.ts
(1 hunks)apps/web/app/interfaces/timer/ITimerLog.ts
(1 hunks)apps/web/app/services/client/api/timer/timer-log.ts
(2 hunks)apps/web/app/services/server/requests/timesheet.ts
(3 hunks)apps/web/app/stores/time-logs.ts
(2 hunks)
✅ Files skipped from review due to trivial changes (1)
- apps/web/app/[locale]/dashboard/app-url/[teamId]/page.tsx
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: deploy
🔇 Additional comments (11)
apps/web/app/stores/time-logs.ts (1)
4-4
: LGTM! Clean integration of activity report state.The new state atom follows the established patterns and is well-integrated with the existing state management structure.
Also applies to: 31-31
apps/web/app/interfaces/activity/IActivityReport.ts (1)
112-124
: Great documentation with example usage!The example usage in the comments is very helpful for developers implementing the interface.
apps/web/app/interfaces/timer/ITimerLog.ts (1)
277-284
: LGTM! Well-structured statistics interface.The new
ITimesheetStatisticsData
interface is well-documented and follows the established patterns in the codebase.apps/web/app/services/server/requests/timesheet.ts (3)
6-6
: LGTM!Clean import of the activity report interface.
176-184
: LGTM!Well-documented interface that extends the base interface with additional optional parameters for activity report filtering.
269-287
: LGTM!The function is well-documented and follows the established pattern of using
buildTimeLogParams
for parameter construction.apps/web/app/hooks/features/useReportActivity.ts (3)
4-4
: LGTM!Clean integration of activity report functionality with proper imports and state management.
Also applies to: 12-12, 65-65
74-74
: LGTM!Consistent query hook setup for activity report.
175-179
: LGTM!Well-structured fetch function for activity report that follows the established pattern.
apps/web/app/services/client/api/timer/timer-log.ts (2)
5-5
: LGTM!Clean import of the activity report interface.
354-368
: LGTM!Excellent JSDoc documentation with clear examples.
Description
Please include a summary of the changes and the related issues.
Type of Change
Checklist
Previous screenshots
Please add here videos or images of the previous status
Current screenshots
Please add here videos or images of the current (new) status
Summary by CodeRabbit