Skip to content

Conversation

Innocent-Akim
Copy link
Contributor

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

  • Optimize API calls for APPS-URLS type reports
  • Fix LoadingSkeleton component TypeScript return type
  • Add proper return statement to React components
  • Improve code formatting and remove unnecessary Promise.all
  • Separate API calls based on report type for better performance
  • Fix date range initialization to show current month by default
  • Add proper TypeScript types and interfaces
  • Remove redundant API calls when only activity report is needed

Breaking Changes:

  • Modified useReportActivity hook to handle report types separately
  • Changed default date range behavior to show full current month

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 internationalization for productivity components.
    • Dashboard tables now display localized headers (e.g., Date, Member, Application, Time Spent, Percent Used).
    • Empty and loading states show translated messages based on the selected language.
    • New functionality added for fetching activity reports within the reporting hook.
    • These updates improve the overall user experience by dynamically adapting text to the user's locale.

- Optimize API calls for APPS-URLS type reports
- Fix LoadingSkeleton component TypeScript return type
- Add proper return statement to React components
- Improve code formatting and remove unnecessary Promise.all
- Separate API calls based on report type for better performance
- Fix date range initialization to show current month by default
- Add proper TypeScript types and interfaces
- Remove redundant API calls when only activity report is needed

Breaking Changes:
- Modified useReportActivity hook to handle report types separately
- Changed default date range behavior to show full current month
@Innocent-Akim Innocent-Akim self-assigned this Feb 24, 2025
@Innocent-Akim Innocent-Akim marked this pull request as draft February 24, 2025 08:33
Copy link
Contributor

coderabbitai bot commented Feb 24, 2025

Walkthrough

The changes integrate the useTranslations hook from the next-intl library into multiple productivity components. Both the employee and project table components now retrieve a translation function (t) and pass it to the EmptyState component. Additionally, table headers and messages in the project-related state components are updated to use localized strings. The overall functionality remains unchanged except for enhanced internationalization support.

Changes

File(s) Change Summary
apps/web/app/[locale]/.../productivity-employee/ProductivityEmployeeTable.tsx Added const t = useTranslations(); and passed t to <EmptyState /> when no data is present.
apps/web/app/[locale]/.../productivity-project/index.tsx Integrated useTranslations to replace hardcoded table header text with localized strings and passed t to <EmptyState />.
apps/web/app/[locale]/.../productivity-project/states.tsx Updated the EmptyState and LoadingSkeleton components to retrieve text via t; modified component interface to include the translation function.
apps/web/app/[locale]/.../productivity-project/types.ts Introduced new interfaces: EmployeeWithProjects, DailyReportData, and DateGroup to enhance type definitions.
apps/web/app/[locale]/.../productivity-project/utils.ts Modified formatDuration and groupActivitiesByProjectAndDate functions for better type handling and error management.
apps/web/app/hooks/features/useReportActivity.ts Added fetchActivityReport function to enhance data fetching capabilities within the hook.
apps/web/app/[locale]/.../dashboard/app-url/[teamId]/page.tsx Reordered a case statement in the switch block without altering functionality.

Sequence Diagram(s)

sequenceDiagram
    participant Component as Productivity Component
    participant TransHook as useTranslations Hook
    participant Child as EmptyState / Table Headers
    Component ->> TransHook: Call useTranslations()
    TransHook -->> Component: Return translation function (t)
    Component ->> Child: Pass 't' as prop for localized text
Loading

Possibly related PRs

  • [Feat]: Report Activity Data productivity #3613: The changes in the main PR and this PR are related as both involve modifications to the EmptyState component, specifically in how they pass the translation function t as a prop to enhance internationalization support.
  • [Feat]: Implement productivity table for app usage statistics #3606: The changes in the main PR, which involve adding internationalization support to the ProductivityEmployeeTable component, are related to this PR as both involve modifications to the EmptyState component to accept a translation function t as a prop.
  • [Fea]: Activity Modal #3551: The changes in the main PR, which involve integrating the useTranslations hook into the ProductivityEmployeeTable component and modifying the EmptyState component to accept a translation function, are related to this PR, as both involve enhancing components with internationalization support.

Suggested labels

feature, WEB, Improvement, Timesheets, UI/UX

Suggested reviewers

  • evereq

Poem

I'm a little rabbit, happy and spry,
Hopping through code beneath the sky.
With useTranslations in my clever paws,
I bring language magic with little flaws.
Cheers to bugs hopped away with glee!
Code and carrots—what a spree!

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

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

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

Oops! 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/components/productivity-project/index.tsx

Oops! 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/components/productivity-project/types.ts

Oops! 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.

  • 2 others
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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.

@Innocent-Akim Innocent-Akim marked this pull request as ready for review February 24, 2025 12:10
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/[locale]/dashboard/app-url/components/productivity-employee/ProductivityEmployeeTable.tsx (1)

13-19: 🛠️ Refactor suggestion

Replace hardcoded strings with translation keys.

The TABLE_HEADERS constant uses hardcoded English strings. For consistency with other components, these should use translation keys.

-const TABLE_HEADERS = [
-  'Date',
-  'Project',
-  'Application',
-  'Time Spent',
-  'Percent used'
-] as const;
+const TABLE_HEADERS = [
+  t('common.DATE'),
+  t('common.PROJECT'),
+  t('common.APPLICATION'),
+  t('common.TIME_SPENT'),
+  t('common.PERCENT_USED')
+] as const;
🧹 Nitpick comments (4)
apps/web/app/[locale]/dashboard/app-url/components/productivity-project/states.tsx (2)

56-61: Consider using the current locale for date formatting.

The date is being formatted using a hardcoded 'en-US' locale, which may not match the user's selected language.

-  const formattedDate = selectedDate ? new Date(selectedDate).toLocaleDateString('en-US', {
+  const formattedDate = selectedDate ? new Date(selectedDate).toLocaleDateString(undefined, {
     weekday: 'long',
     day: '2-digit',
     month: 'long',
     year: 'numeric'
   }) : '';

22-26: Consider using TypeScript const assertions for translation keys.

Using const assertions for translation keys can help catch typos and ensure type safety.

+const TRANSLATION_KEYS = {
+  DATE: 'common.DATE',
+  MEMBER: 'common.MEMBER',
+  APPLICATION: 'common.APPLICATION',
+  TIME_SPENT: 'common.TIME_SPENT',
+  PERCENT_USED: 'common.PERCENT_USED',
+  NO_ACTIVITY_DATA: 'common.NO_ACTIVITY_DATA',
+  SELECT_DIFFERENT_DATE: 'common.SELECT_DIFFERENT_DATE',
+} as const;

-<TableHead className="font-semibold">{t('common.DATE')}</TableHead>
+<TableHead className="font-semibold">{t(TRANSLATION_KEYS.DATE)}</TableHead>

Also applies to: 66-66, 70-70

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

43-47: Consider extracting shared translation keys.

The translation keys are duplicated between this component and the LoadingSkeleton component. Consider extracting them to a shared constants file.

Create a new file translationKeys.ts:

export const PRODUCTIVITY_TRANSLATION_KEYS = {
  DATE: 'common.DATE',
  MEMBER: 'common.MEMBER',
  APPLICATION: 'common.APPLICATION',
  TIME_SPENT: 'common.TIME_SPENT',
  PERCENT_USED: 'common.PERCENT_USED',
  NO_ACTIVITY_DATA: 'common.NO_ACTIVITY_DATA',
  SELECT_DIFFERENT_DATE: 'common.SELECT_DIFFERENT_DATE',
} as const;
apps/web/app/[locale]/dashboard/app-url/components/productivity-employee/ProductivityEmployeeTable.tsx (1)

31-39: Use consistent locale for date formatting.

The date formatting uses a hardcoded 'en-US' locale in multiple places. This should respect the user's locale preference.

-  return date.toLocaleDateString('en-US', {
+  return date.toLocaleDateString(undefined, {
     weekday: 'long',
     day: '2-digit',
     month: 'long',
     year: 'numeric'
   });

Also applies to: 174-174

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b3c6787 and 60f0b71.

📒 Files selected for processing (3)
  • apps/web/app/[locale]/dashboard/app-url/components/productivity-employee/ProductivityEmployeeTable.tsx (3 hunks)
  • apps/web/app/[locale]/dashboard/app-url/components/productivity-project/index.tsx (3 hunks)
  • apps/web/app/[locale]/dashboard/app-url/components/productivity-project/states.tsx (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Codacy Static Code Analysis

…ture handling

- Reverted Props interface to accept array data format
- Restored state management with localData and useEffect
- Re-implemented groupedData logic using useMemo for data processing
- Added proper error handling for invalid data structures
- Maintained backward compatibility with existing data format
- Fixed date sorting and employee grouping functionality
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

🧹 Nitpick comments (4)
apps/web/app/[locale]/dashboard/app-url/components/productivity-project/types.ts (2)

57-60: Add clarifying documentation for new interface.

Although the interface is self-explanatory, a short doc comment explaining its usage in consumer code might help readers understand how it fits into the overall reporting workflow.


62-69: Unify the activity item type.

Handling a union of IActivityItem or IActivityItem[] tends to complicate type checks. If possible, consider always using an array for consistency or providing clear utilities to handle single vs. multiple items.

apps/web/app/[locale]/dashboard/app-url/components/productivity-project/utils.ts (2)

4-23: Validate fallback behavior for invalid durations.

Returning '00:00:00' and logging a warning may be acceptable, but consider:

  1. Throwing or surfacing an explicit error in development.
  2. Providing a user-facing indication that the time is invalid.

This ensures developers/users quickly understand when the data is incorrect.


25-113: Avoid using any casting and standardize data validation.

Forcing the cast using data as any can hide potential issues if data is not shaped as expected. A more robust solution is to narrow the type with explicit checks or use safer parsing techniques. Consider extracting validation logic into a helper or rewriting to ensure type safety without multiple logging statements.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 60f0b71 and 771ebf0.

📒 Files selected for processing (5)
  • apps/web/app/[locale]/dashboard/app-url/[teamId]/page.tsx (1 hunks)
  • apps/web/app/[locale]/dashboard/app-url/components/productivity-project/index.tsx (3 hunks)
  • apps/web/app/[locale]/dashboard/app-url/components/productivity-project/types.ts (1 hunks)
  • apps/web/app/[locale]/dashboard/app-url/components/productivity-project/utils.ts (1 hunks)
  • apps/web/app/hooks/features/useReportActivity.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • apps/web/app/[locale]/dashboard/app-url/[teamId]/page.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/web/app/[locale]/dashboard/app-url/components/productivity-project/index.tsx
⏰ 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 (1)

328-328: Good improvement: exposing fetchActivityReport function

This change aligns perfectly with the PR objectives of improving report functionality and performance. By exposing the fetchActivityReport function through the hook's return object, consumers can now directly fetch only the activity report when needed, eliminating redundant API calls that would otherwise fetch all reports.

apps/web/app/[locale]/dashboard/app-url/components/productivity-project/types.ts (1)

52-55: Looks good!

This interface is straightforward and aligns well with existing naming conventions.

@Innocent-Akim Innocent-Akim requested a review from evereq February 26, 2025 07:20
@evereq evereq merged commit ac30771 into develop Feb 26, 2025
13 checks passed
@evereq evereq deleted the feat/productivity-report-improvements branch February 26, 2025 08:40
@coderabbitai coderabbitai bot mentioned this pull request Feb 26, 2025
9 tasks
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