Skip to content
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

[Feat]: Report Activity Data productivity #3613

Merged
merged 5 commits into from
Feb 19, 2025

Conversation

Innocent-Akim
Copy link
Contributor

@Innocent-Akim Innocent-Akim commented Feb 19, 2025

Description

Please include a summary of the changes and the related issues.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented on my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings

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

  • New Features

    • Enhanced dashboard reporting with dynamic grouping options for activity data, offering improved visibility into productivity metrics.
    • Upgraded productivity views now display clear loading indicators, formatted activity durations, and employee visuals.
  • UI Improvements

    • Optimized navigation with a smoother back button experience.
    • Refined email verification layouts for better visual consistency.
  • Bug Fixes

    • Improved handling of empty activity data in reports, providing user feedback when no data is available.

@Innocent-Akim Innocent-Akim self-assigned this Feb 19, 2025
Copy link
Contributor

coderabbitai bot commented Feb 19, 2025

Warning

Rate limit exceeded

@Innocent-Akim has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 8 minutes and 30 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between d1e7b44 and 879f62f.

📒 Files selected for processing (1)
  • apps/web/app/hooks/features/useReportActivity.ts (10 hunks)

Walkthrough

This pull request refactors various dashboard components and hooks to improve data handling and type safety. The changes remove redundant state management in favor of dedicated handler functions, update the useReportActivity hook to accept a new types parameter and an optional groupBy value, and adjust component prop types (using GroupByType) to streamline interactions between the dashboard header, grouping selector, and productivity table. There are also cosmetic adjustments in the unverified email component.

Changes

File(s) Change Summary
apps/web/app/[locale]/dashboard/app-url/[teamId]/page.tsx Removed local groupBy state; introduced handleGroupByChange; updated useReportActivity call with { types: 'APPS-URLS' }; streamlined generateMonthData; removed shadow from Card; updated ProductivityTable props to use activityReport and loadingActivityReport.
apps/web/app/[locale]/dashboard/app-url/components/GroupBySelect.tsx
apps/web/app/[locale]/dashboard/team-dashboard/[teamId]/components/dashboard-header.tsx
Changed the onGroupByChange callback parameter type from string to GroupByType (with an added import of GroupByType in the latter) to ensure stricter type safety.
apps/web/app/[locale]/dashboard/app-url/components/ProductivityTable.tsx Refactored data handling by updating the prop type from AppUsageData[] to IActivityReport[]; overhauled rendering logic (including conditional messages and increased skeleton rows); introduced a new utility function formatDuration for time formatting.
apps/web/app/[locale]/dashboard/team-dashboard/[teamId]/page.tsx Reordered state declarations and imports; invoked useReportActivity with { types: 'TEAM-DASHBOARD' }; introduced a dedicated handleBack function to encapsulate back navigation logic.
apps/web/app/hooks/features/useReportActivity.ts Extended the hook to accept an additional types parameter, added an optional groupBy property to its props, updated memoization to include groupBy, and introduced a new handleGroupByChange callback; defined new types (GroupByType and interface GroupByOptions).
apps/web/lib/features/unverified-email.tsx Reordered CSS classes within JSX elements for layout adjustments; changes are purely cosmetic with no logic alteration.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant DH as DashboardHeader
    participant AU as AppUrls Component
    participant UR as useReportActivity Hook
    participant PT as ProductivityTable

    U->>DH: Selects new GroupBy option
    DH->>AU: Triggers onGroupByChange (handleGroupByChange)
    AU->>UR: Calls handleGroupByChange with new groupBy value
    UR->>UR: Fetches updated activity report (based on APPS-URLS)
    UR-->>AU: Returns updated report data and loading state
    AU->>PT: Passes updated activityReport and loading flags
Loading

Possibly related PRs

  • [Feat]: Activity Report Implementation #3607: Related to modifications in the useReportActivity hook, which is also referenced in the main PR, specifically in the context of the AppUrls component.
  • [Feat]: Improve activity modal UI #3585: Involves changes to the onGroupByChange prop type in both the GroupBySelect and DashboardHeader components, aligning with the new GroupByType introduced in the useReportActivity hook.
  • [Feat]: Team Dashboard UI apps and URLs #3605: Focuses on modifications in the onGroupByChange prop type in the DashboardHeader and GroupBySelect components, which align with updates made in the main PR regarding the DashboardHeader component's props.

Suggested labels

feature, WEB, Improvement, Ever Teams, Timesheets

Suggested reviewers

  • evereq

Poem

I'm a little rabbit, hopping with delight,
Through refactored code that now shines so bright.
Grouping data with a skip and a bound,
Cleaner flows and types that astound.
In every line and every tweak I see,
A garden of improvements made just for me.
🐇 Happy hops in every commit!


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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (5)
apps/web/app/[locale]/dashboard/app-url/components/ProductivityTable.tsx (3)

78-91: Consider iterating over all projects.
Right now, the code only accesses employeeData.projects[0]?.activity. If employees can have multiple projects, the other projects' activities are effectively ignored. Verify whether this is intentional or refactor to iterate through all projects as needed.


142-142: Avoid unnecessary type conversion.
If activity.duration originates as a number, there is no need to convert it with .toString(). Instead, pass the numeric value directly into formatDuration() to reduce potential type-parsing pitfalls.


166-173: Handle invalid or negative durations.
Currently, formatDuration assumes valid non-negative numeric input. Consider adding validation or defaulting to "00:00:00" if parsing fails to make the function more robust.

apps/web/app/hooks/features/useReportActivity.ts (2)

240-279: Improve error handling in update handlers.

The use of Promise.all for concurrent API calls is good for performance, but error handling could be more specific to help with debugging.

Apply this diff to improve error handling:

-			]).catch(console.error);
+			]).catch((error) => {
+				console.error('Failed to update report data:', {
+					error,
+					filters: newFilters,
+					type: types
+				});
+			});

293-316: Consider memoizing returned object for better performance.

The returned object contains multiple values that could benefit from memoization to prevent unnecessary re-renders in consuming components.

Apply this diff to memoize the returned object:

+	const returnValue = useMemo(
+		() => ({
+			// Loading states
+			loadingTimeLogReportDailyChart,
+			loadingTimeLogReportDaily,
+			loadingTimesheetStatisticsCounts,
+			loadingActivityReport,
+
+			// Data states
+			rapportChartActivity,
+			rapportDailyActivity,
+			statisticsCounts,
+			activityReport,
+
+			// Update handlers
+			updateDateRange,
+			updateFilters,
+			handleGroupByChange,
+
+			// Other states
+			currentFilters,
+			setStatisticsCounts,
+			isManage
+		}),
+		[
+			loadingTimeLogReportDailyChart,
+			loadingTimeLogReportDaily,
+			loadingTimesheetStatisticsCounts,
+			loadingActivityReport,
+			rapportChartActivity,
+			rapportDailyActivity,
+			statisticsCounts,
+			activityReport,
+			updateDateRange,
+			updateFilters,
+			handleGroupByChange,
+			currentFilters,
+			setStatisticsCounts,
+			isManage
+		]
+	);
+
-	return {
-		// Loading states
-		loadingTimeLogReportDailyChart,
-		loadingTimeLogReportDaily,
-		loadingTimesheetStatisticsCounts,
-		loadingActivityReport,
-
-		// Data states
-		rapportChartActivity,
-		rapportDailyActivity,
-		statisticsCounts,
-		activityReport,
-
-		// Update handlers
-		updateDateRange,
-		updateFilters,
-		handleGroupByChange,
-
-		// Other states
-		currentFilters,
-		setStatisticsCounts,
-		isManage
-	};
+	return returnValue;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ecb6aec and 3bff0a2.

📒 Files selected for processing (7)
  • apps/web/app/[locale]/dashboard/app-url/[teamId]/page.tsx (6 hunks)
  • apps/web/app/[locale]/dashboard/app-url/components/GroupBySelect.tsx (1 hunks)
  • apps/web/app/[locale]/dashboard/app-url/components/ProductivityTable.tsx (3 hunks)
  • apps/web/app/[locale]/dashboard/team-dashboard/[teamId]/components/dashboard-header.tsx (1 hunks)
  • apps/web/app/[locale]/dashboard/team-dashboard/[teamId]/page.tsx (4 hunks)
  • apps/web/app/hooks/features/useReportActivity.ts (10 hunks)
  • apps/web/lib/features/unverified-email.tsx (3 hunks)
✅ Files skipped from review due to trivial changes (1)
  • apps/web/lib/features/unverified-email.tsx
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: deploy
🔇 Additional comments (6)
apps/web/app/[locale]/dashboard/app-url/components/ProductivityTable.tsx (1)

15-18: Verify correct type usage.
The prop data is defined as IActivityReport[], yet it’s cast to IActivityReportGroupByDate[]. Ensure that these types are truly compatible or consider changing the prop type to match this usage more explicitly to avoid confusion or runtime errors.

apps/web/app/[locale]/dashboard/app-url/components/GroupBySelect.tsx (1)

3-7: Ensure values match the enum.
The onGroupByChange prop expects a GroupByType, yet string literals like "date" and "project" are passed in. Confirm that these strings align exactly with the union or enum definition of GroupByType to avoid runtime or type-checking issues.

apps/web/app/[locale]/dashboard/team-dashboard/[teamId]/components/dashboard-header.tsx (1)

10-10: Aligned callback signature.
Switching the onGroupByChange type from string to GroupByType provides better type safety and consistency with GroupBySelect. This ensures only valid grouping values are passed around.

Also applies to: 18-18

apps/web/app/hooks/features/useReportActivity.ts (1)

21-34: LGTM! Well-structured type definitions.

The new GroupByType type and updated UseReportActivityProps interface provide good type safety while maintaining backward compatibility.

Also applies to: 66-70

apps/web/app/[locale]/dashboard/team-dashboard/[teamId]/page.tsx (1)

28-38: LGTM! Clean and well-structured changes.

The refactoring improves code organization while maintaining functionality. Good use of the new useReportActivity hook with proper typing.

Also applies to: 50-51, 62-63

apps/web/app/[locale]/dashboard/app-url/[teamId]/page.tsx (1)

131-131: LGTM! Good use of loading state.

Properly handling loading state in the ProductivityTable component improves user experience.

@Innocent-Akim Innocent-Akim added bug Something isn't working feature WEB Web app Improvement Improvement Timesheets and removed bug Something isn't working labels Feb 19, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🔭 Outside diff range comments (1)
apps/web/app/hooks/features/useReportActivity.ts (1)

21-34: 🛠️ Refactor suggestion

Improve type safety by using GroupByType for groupBy property.

The groupBy property in UseReportActivityProps should be constrained to GroupByType instead of string to ensure type safety.

Apply this diff:

-	groupBy?: string;
+	groupBy?: GroupByType;

Also, consider removing the redundant GroupByOptions interface and directly use { groupBy: GroupByType } where needed.

Also applies to: 66-70

🧹 Nitpick comments (3)
apps/web/app/hooks/features/useReportActivity.ts (3)

72-72: Improve type safety by using const assertion for types parameter.

Use a const assertion to make the types parameter more type-safe and self-documenting.

Apply this diff:

-export function useReportActivity({ types }: { types?: 'TEAM-DASHBOARD' | 'APPS-URLS' })
+const REPORT_TYPES = ['TEAM-DASHBOARD', 'APPS-URLS'] as const;
+type ReportType = typeof REPORT_TYPES[number];
+export function useReportActivity({ types }: { types?: ReportType })

143-192: Improve error handling with specific error types.

While the error handling is good, it could be improved by using more specific error types and error messages.

Apply this diff:

-			} catch (err) {
-				console.error('Failed to fetch report:', err);
+			} catch (err: unknown) {
+				const errorMessage = err instanceof Error ? err.message : 'Unknown error';
+				console.error(`Failed to fetch report with query ${queryFn.name}:`, errorMessage);

257-267: Improve error handling in handleGroupByChange.

The error handling in handleGroupByChange could be more robust and provide better error feedback.

Apply this diff:

-			} catch (error) {
-				console.error('Failed to update activity grouping:', error);
+			} catch (error: unknown) {
+				const errorMessage = error instanceof Error ? error.message : 'Unknown error';
+				console.error('Failed to update activity grouping:', errorMessage);
+				// Consider adding error state management or error callback
+				throw new Error(`Failed to update activity grouping: ${errorMessage}`);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3bff0a2 and d1e7b44.

📒 Files selected for processing (1)
  • apps/web/app/hooks/features/useReportActivity.ts (10 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: deploy
🔇 Additional comments (2)
apps/web/app/hooks/features/useReportActivity.ts (2)

96-140: LGTM! Props merging logic is well-implemented.

The memoized props merging function correctly handles all edge cases and has proper dependency tracking.


281-291: LGTM! Initial data fetch is well-implemented.

The initial data fetch correctly handles conditional fetching and has proper dependency tracking.

- Simplify mergedProps and setData validation
- Remove redundant setData([]) initialization
- Add consistent mergedProps check in fetchStatisticsCounts
- Optimize dependency array in useMemo
- Improve type safety with null coalescing for tenantId
- Simplify mergedProps and setData validation
- Remove redundant setData([]) initialization
- Add consistent mergedProps check in fetchStatisticsCounts
- Optimize dependency array in useMemo
- Improve type safety with null coalescing for tenantId
@Innocent-Akim Innocent-Akim requested a review from evereq February 19, 2025 17:03
@evereq evereq merged commit 72e8642 into develop Feb 19, 2025
13 checks passed
@evereq evereq deleted the feat/report-activity-data-productivity branch February 19, 2025 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants