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

[Refactor] Profile page | visited apps tab UI #3578

Merged

Conversation

CREDO23
Copy link
Contributor

@CREDO23 CREDO23 commented Feb 3, 2025

Description

Closes #3398

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

Current screenshots

Screenshot 2025-02-03 at 20 02 54 Screenshot 2025-02-03 at 20 03 33 Screenshot 2025-02-03 at 20 07 07

Summary by CodeRabbit

  • New Features

    • Progress bars now offer a customizable background color for enhanced visual integration.
    • Enhanced flexibility in the app data structure with optional properties for timer applications.
  • Bug Fixes

    • Updated activity percentage formatting now displays “0%” for clarity.
  • Refactor

    • Improved app grouping and activity views for more consistent layout and reliable handling of missing information.
    • Streamlined rendering logic in the app visit table for better performance and maintainability.

@CREDO23 CREDO23 added enhancement New feature or request UI/UX WEB Web app Improvement Improvement Ever Teams labels Feb 3, 2025
@CREDO23 CREDO23 self-assigned this Feb 3, 2025
@CREDO23 CREDO23 linked an issue Feb 3, 2025 that may be closed by this pull request
Copy link
Contributor

coderabbitai bot commented Feb 3, 2025

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/helpers/array-data.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.

apps/web/app/interfaces/timer/ITimerApp.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.

apps/web/lib/features/activity/screenshoots.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.

  • 3 others

Walkthrough

The PR introduces several code modifications across UI helper functions, interfaces, and components. In the helper, a new check for an application’s duration is added before grouping apps by hour. The ITimerApps interface is refactored to replace required string fields with optional fields and new properties. The ProgressBar component now allows background color customization. Finally, components in the visited apps tab have been updated with useMemo optimization, enhanced conditional rendering, and minor UI text adjustments.

Changes

File(s) Change Summary
apps/web/app/helpers/array-data.ts Added a conditional check for app.duration in the groupAppsByHour function to ensure only apps with a defined duration are processed and grouped.
apps/web/app/interfaces/timer/ITimerApp.ts Updated the ITimerApps interface by removing required string properties and introducing optional properties with updated types; added new fields (description, durationPercentage, childItems).
apps/web/lib/components/progress-bar.tsx Introduced an optional backgroundColor prop for the ProgressBar component; adjusted the default background color for progress under 25% and updated the destructuring assignment.
apps/web/lib/features/activity/apps.tsx, apps/web/lib/features/activity/components/app-visited-Item.tsx, apps/web/lib/features/activity/screenshoots.tsx Optimized header creation using useMemo in apps.tsx; enhanced conditional rendering and fallback handling in AppVisitedItem with duration checks and date/title fallbacks; updated string output in ScreenshootTab to display activity percentage with a % symbol.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant GroupHelper as groupAppsByHour
    Caller->>GroupHelper: Pass app object
    alt app.duration is defined
      GroupHelper->>GroupHelper: Check and update/create hour entry
      GroupHelper-->>Caller: Return updated grouped data
    else app.duration is undefined
      GroupHelper-->>Caller: Skip processing
    end
Loading
sequenceDiagram
    participant Component as AppVisitedItem
    participant AppData as App Object
    Component->>AppData: Retrieve app data
    alt app.duration exists
      Component->>Component: Compute time components and percent value
    else
      Component->>Component: Default values {h:0, m:0, s:0} with undefined percent
    end
    Component->>ProgressBar: Render with backgroundColor "black"
Loading

Assessment against linked issues

Objective Addressed Explanation
Update and refactor the Visited Apps Tab UI [#3398]

Possibly related PRs

  • [Fix]: Handle Timesheet Update #3384: The changes in the main PR, specifically the modifications to the ITimerApps interface and the groupAppsByHour function, are related to the handling of application durations, which connects to the time calculation logic introduced in the retrieved PR's AddTaskModal and EditTaskModal components.
  • [Fea]: Activity Modal #3551: The changes in the main PR, specifically the modifications to the groupAppsByHour function and the handling of app.duration, are related to the updates in the AppVisitedItem component where app?.duration is conditionally checked, indicating a shared focus on managing application duration data.
  • fix: Screenshot Details Card show twice #3396: The changes in the main PR, specifically the modifications to the groupAppsByHour function and the handling of app.duration, are related to the updates in the AppVisitedItem component where app?.duration is conditionally checked, indicating a shared focus on managing application duration data.

Suggested reviewers

  • evereq

Poem

Oh, I’m a rabbit with a joyful code beat,
Hopping through functions with checks oh so neat,
I nibble at bugs and design with delight,
New props and interfaces making the future bright,
In a garden of code, I celebrate every byte!
🐇💻

✨ 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.

Copy link

socket-security bot commented Feb 3, 2025

No dependency changes detected. Learn more about Socket for GitHub ↗︎

👍 No dependency changes detected in pull request

@CREDO23 CREDO23 marked this pull request as draft February 3, 2025 18:38
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/lib/features/activity/components/app-visited-Item.tsx (1)

16-17: Improve number formatting for better readability.

The time and percentage calculations handle optional fields correctly, but the number formatting could be improved.

Consider using Intl.NumberFormat for consistent number formatting:

-const percent = app?.duration && ((+app.duration * 100) / totalMilliseconds).toFixed(2);
+const percent = app?.duration 
+  ? new Intl.NumberFormat('en-US', { 
+      maximumFractionDigits: 2 
+    }).format((+app.duration * 100) / totalMilliseconds)
+  : undefined;
apps/web/lib/features/activity/apps.tsx (1)

64-69: Simplify loading state condition.

The loading state check could be simplified.

Consider this simpler condition:

-{loading && visitedApps?.length < 1 && (
+{loading && (
apps/web/lib/components/progress-bar.tsx (1)

20-33: Simplify color logic with a utility function.

The color logic could be extracted into a utility function for better maintainability.

Consider this refactor:

+const getProgressColor = (progress: number) => {
+  if (progress < 25) return 'bg-red-600 dark:bg-red-400';
+  if (progress < 50) return 'bg-yellow-600 dark:bg-yellow-400';
+  if (progress < 75) return 'bg-blue-600 dark:bg-blue-400';
+  return 'bg-green-600 dark:bg-green-400';
+};

 <div
   className={clsxm(
     ' h-2 rounded-full absolute z-[1] bg-black ',
-    +parseInt(progress.toString()) < 25 && 'bg-red-600 dark:bg-red-400',
-    +parseInt(progress.toString()) >= 25 &&
-      +parseInt(progress.toString()) < 50 &&
-      'bg-yellow-600 dark:bg-yellow-400',
-    +parseInt(progress.toString()) >= 50 &&
-      +parseInt(progress.toString()) < 75 &&
-      'bg-blue-600 dark:bg-blue-400',
-    +parseInt(progress.toString()) >= 75 && 'bg-green-600 dark:bg-green-400'
+    getProgressColor(+parseInt(progress.toString()))
   )}
   style={{ width: progress }}
 />
apps/web/lib/features/activity/screenshoots.tsx (1)

26-26: Consider memoizing the formatted activity percentage.

The UI improvement to consistently show percentage format is good. However, since this calculation is done on every render, consider memoizing it for better performance.

+ const formattedActivityPercent = useMemo(() => {
+   return Number.isNaN(parseFloat(activityPercent.toFixed(2))) ? '0%' : activityPercent.toFixed(2);
+ }, [activityPercent]);

  <h2 className="text-3xl font-medium">
-   {Number.isNaN(parseFloat(activityPercent.toFixed(2))) ? '0%' : activityPercent.toFixed(2)}
+   {formattedActivityPercent}
  </h2>
apps/web/app/helpers/array-data.ts (1)

37-46: Improve code structure and readability.

While the defensive programming approach is good, the code structure could be improved by:

  1. Flattening the if-else nesting
  2. Avoiding repeated time slice operation
  3. Making type conversion more explicit
- if (app.duration)
-   if (hourDataIndex !== -1) {
-     groupedData[hourDataIndex].apps.push(app);
-     groupedData[hourDataIndex].totalMilliseconds += +app.duration;
-   } else
-     groupedData.push({
-       hour: app.time.slice(0, 5),
-       totalMilliseconds: +app.duration,
-       apps: [app]
-     });
+ if (!app.duration) {
+   return;
+ }
+ 
+ const hour = app.time.slice(0, 5);
+ const duration = Number(app.duration);
+ 
+ if (hourDataIndex !== -1) {
+   groupedData[hourDataIndex].apps.push(app);
+   groupedData[hourDataIndex].totalMilliseconds += duration;
+   return;
+ }
+ 
+ groupedData.push({
+   hour,
+   totalMilliseconds: duration,
+   apps: [app]
+ });
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e60c210 and 442f30e.

⛔ Files ignored due to path filters (2)
  • apps/server-web/release/app/yarn.lock is excluded by !**/yarn.lock, !**/*.lock
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (6)
  • apps/web/app/helpers/array-data.ts (1 hunks)
  • apps/web/app/interfaces/timer/ITimerApp.ts (1 hunks)
  • apps/web/lib/components/progress-bar.tsx (2 hunks)
  • apps/web/lib/features/activity/apps.tsx (1 hunks)
  • apps/web/lib/features/activity/components/app-visited-Item.tsx (2 hunks)
  • apps/web/lib/features/activity/screenshoots.tsx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: deploy
  • GitHub Check: deploy
🔇 Additional comments (2)
apps/web/lib/features/activity/components/app-visited-Item.tsx (1)

19-27: LGTM! Good performance optimization.

The use of useMemo for layout calculations prevents unnecessary recalculations.

apps/web/lib/features/activity/apps.tsx (1)

14-34: LGTM! Excellent optimization with proper dependencies.

The headers configuration is properly memoized with the translation function as a dependency.

@CREDO23 CREDO23 force-pushed the 3398-refactor-profile-page--update-visited-apps-tab-ui branch from 442f30e to 8b446e4 Compare February 3, 2025 18:45
@CREDO23 CREDO23 force-pushed the 3398-refactor-profile-page--update-visited-apps-tab-ui branch from 8b446e4 to 3d8cded Compare February 3, 2025 19:06
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 (2)
apps/web/app/interfaces/timer/ITimerApp.ts (2)

11-12: Document the purpose and usage of new fields.

The new fields durationPercentage and childItems lack documentation explaining their purpose and expected values.

Consider adding JSDoc comments to document:

  • The meaning of durationPercentage (e.g., is it a value between 0-1 or 0-100?)
  • The relationship between parent and child items
  • Any constraints on the values
 export interface ITimerApps {
   time: string;
   sessions?: number;
   duration?: number;
   employeeId?: string;
   date?: string;
   title?: string;
   description?: string;
+  /** Percentage of time spent on this app (0-100) */
   durationPercentage?: number;
+  /** Nested timer apps, e.g., for grouping related activities */
   childItems?: ITimerApps[];
 }

8-8: Consider using a more specific date type.

The date field is typed as an optional string, which provides no type safety for date format validation.

Consider using a more specific type or adding validation:

  1. Use a union type with specific date format strings
  2. Add runtime validation for date strings
  3. Consider using a Date object if date manipulation is needed
-  date?: string;
+  /** Date in ISO 8601 format (YYYY-MM-DD) */
+  date?: `${number}-${number}-${number}`;
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 442f30e and 25d3ef7.

📒 Files selected for processing (6)
  • apps/web/app/helpers/array-data.ts (1 hunks)
  • apps/web/app/interfaces/timer/ITimerApp.ts (1 hunks)
  • apps/web/lib/components/progress-bar.tsx (2 hunks)
  • apps/web/lib/features/activity/apps.tsx (1 hunks)
  • apps/web/lib/features/activity/components/app-visited-Item.tsx (2 hunks)
  • apps/web/lib/features/activity/screenshoots.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • apps/web/lib/components/progress-bar.tsx
  • apps/web/lib/features/activity/screenshoots.tsx
  • apps/web/lib/features/activity/apps.tsx
  • apps/web/lib/features/activity/components/app-visited-Item.tsx
  • apps/web/app/helpers/array-data.ts
🔇 Additional comments (2)
apps/web/app/interfaces/timer/ITimerApp.ts (2)

4-12: Ensure proper handling of optional fields across components.

The interface changes make several critical fields optional, which could lead to runtime issues if not handled properly in components.

Let's verify the handling of these optional fields in components:

#!/bin/bash
# Description: Search for direct property access without optional chaining
# Focus on components that might not handle undefined values properly

# Search for direct property access without optional chaining or nullish checks
rg -g '*.{ts,tsx}' --type-add 'tsx:*.{ts,tsx}' -A 2 'const.*=.*app\.(sessions|duration|employeeId|date|title|description|durationPercentage|childItems)[^?]'

# Search for array operations on childItems that might not handle undefined
rg -g '*.{ts,tsx}' --type-add 'tsx:*.{ts,tsx}' -A 2 'app\.childItems\.(map|filter|reduce|forEach|some|every)'

5-6: Consider type consistency for numeric fields.

The sessions and duration fields are now typed as optional numbers instead of strings. While this is a more appropriate type, ensure consistent type usage:

  1. Update any string-to-number conversions in components
  2. Verify that API responses match these numeric types

Let's check for any remaining string-to-number conversions:

✅ Verification successful

Numeric Field Consistency Verified
The search for string-to-number conversions (using parseInt, parseFloat, and string methods) on the sessions and duration fields yielded no matches. This indicates that the codebase consistently treats these fields as numbers, and no unintended string operations are being performed on them.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find potential type mismatches in numeric field handling

# Search for parseInt/parseFloat usage on these fields
rg -g '*.{ts,tsx}' --type-add 'tsx:*.{ts,tsx}' -A 2 '(parseInt|parseFloat)\(.*\.(sessions|duration)'

# Search for string operations on these numeric fields
rg -g '*.{ts,tsx}' --type-add 'tsx:*.{ts,tsx}' -A 2 '\.(sessions|duration)\.(toString|split|replace)'

Length of output: 206

@evereq evereq merged commit 7f109f1 into develop Feb 3, 2025
13 checks passed
@evereq evereq deleted the 3398-refactor-profile-page--update-visited-apps-tab-ui branch February 3, 2025 19:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Ever Teams Improvement Improvement UI/UX WEB Web app
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Refactor] Profile Page | Update Visited Apps Tab UI
2 participants