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

fix: dashboard icon flickering #2170

Merged
merged 2 commits into from
Oct 4, 2024

Conversation

AkshayBandi027
Copy link
Contributor

@AkshayBandi027 AkshayBandi027 commented Oct 3, 2024

What does this PR do?

Fixes #2156

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Chore (refactoring code, technical debt, workflow improvements)
  • Enhancement (small improvements)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How should this be tested?

  • Go to dashboard
  • Select the any workspace

Checklist

Required

  • Filled out the "How to test" section in this PR
  • Read Contributing Guide
  • Self-reviewed my own code
  • Commented on my code in hard-to-understand areas
  • Ran pnpm build
  • Ran pnpm fmt
  • Checked for warnings, there are none
  • Removed all console.logs
  • Merged the latest changes from main onto my branch with git pull origin main
  • My changes don't cause any responsiveness issues

Appreciated

  • If a UI change was made: Added a screen recording or screenshots to this PR
unkey-icons.mp4

Summary by CodeRabbit

  • New Features

    • Introduced a custom hook useDelayLoader for improved loading state management.
    • Enhanced navigation experience with refined loading indicators in the NavLink component.
  • Bug Fixes

    • Corrected the import of permissions in the RolesPage component to ensure proper functionality.
  • Chores

    • Minor formatting adjustments in the code for consistency.

Copy link

changeset-bot bot commented Oct 3, 2024

⚠️ No Changeset found

Latest commit: dc9022f

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

vercel bot commented Oct 3, 2024

@AkshayBandi027 is attempting to deploy a commit to the Unkey Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented Oct 3, 2024

📝 Walkthrough

Walkthrough

The pull request introduces several modifications across multiple files, primarily focusing on enhancing the functionality of the dashboard components. Key changes include the active import of permissions in the RolesPage, the addition of a new custom hook useDelayLoader to manage loading states in the NavLink component, and minor formatting adjustments. Additionally, a trivial change is made in the package.json of the @unkey/ratelimit package, involving whitespace in the files array.

Changes

File Path Change Summary
apps/dashboard/app/(app)/authorization/permissions/page.tsx Active import of permissions from @unkey/db/src/schema; minor formatting adjustment in orderBy.
apps/dashboard/app/(app)/desktop-sidebar.tsx Added useDelayLoader import; replaced isPending with showLoader for loading state management.
apps/dashboard/lib/hooks/useDelayLoader.tsx Introduced useDelayLoader hook to manage loading states with a delay; includes cleanup for timeouts.
packages/ratelimit/package.json Added a space after the comma in the files array; no other changes made.

Assessment against linked issues

Objective Addressed Explanation
Smooth icon transitions when switching tabs (2156) The changes do not address the flickering issue directly.

Possibly related PRs

Suggested labels

🕹️ oss.gg, :joystick: 300 points

Suggested reviewers

  • mcstepp
  • chronark
  • perkinsjr

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

github-actions bot commented Oct 3, 2024

Thank you for following the naming conventions for pull request titles! 🙏

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 and nitpick comments (5)
apps/dashboard/lib/hooks/useDelayLoader.tsx (3)

3-3: LGTM: Well-structured hook declaration with a minor suggestion.

The hook is correctly named and exported, with appropriate parameters. However, consider using a more specific type for the delay parameter.

Consider updating the parameter types for improved clarity:

-export const useDelayLoader = (isPending: boolean, delay = 50) => {
+export const useDelayLoader = (isPending: boolean, delay: number = 50) => {

4-22: LGTM: Effective implementation with a minor optimization suggestion.

The hook implementation effectively addresses the flickering issue by introducing a delay before showing the loader. The use of useEffect with a cleanup function is a good practice to prevent memory leaks.

Consider this minor optimization to avoid unnecessary state updates:

 useEffect(() => {
   let timeout: NodeJS.Timeout;
   if (isPending) {
     timeout = setTimeout(() => {
       setShowLoader(true);
     }, delay);
   } else {
-    setShowLoader(false);
+    if (showLoader) {
+      setShowLoader(false);
+    }
   }

   return () => {
     clearTimeout(timeout);
   };
-}, [isPending, delay]);
+}, [isPending, delay, showLoader]);

This change prevents unnecessary state updates when showLoader is already false, potentially improving performance.


1-22: Great solution! Consider adding documentation.

This custom hook effectively addresses the icon flickering issue described in the PR objectives. It's a well-implemented, reusable solution that follows React best practices.

To enhance maintainability, consider adding a brief JSDoc comment explaining the hook's purpose and parameters:

/**
 * A custom hook that introduces a delay before showing a loader to prevent flickering.
 * @param isPending - Indicates whether the loading state is active.
 * @param delay - The delay in milliseconds before showing the loader (default: 50ms).
 * @returns A boolean indicating whether to show the loader.
 */
export const useDelayLoader = (isPending: boolean, delay: number = 50) => {
  // ... (existing implementation)
};
apps/dashboard/app/(app)/authorization/permissions/page.tsx (1)

22-22: LGTM: Improved orderBy property

The adjustment to the orderBy property is correct and improves code consistency by using the imported permissions schema. This change enhances readability and maintains a consistent structure throughout the codebase.

For even better consistency, consider using object shorthand notation:

- orderBy: [asc(permissions.name)],
+ orderBy: [{ permissions: { name: asc } }],

This aligns with the Prisma query API style and might be more consistent with other parts of your codebase.

apps/dashboard/app/(app)/desktop-sidebar.tsx (1)

Line range hint 1-270: Overall impact: Improved loading state management

The changes in this file effectively address the icon flickering issue mentioned in the PR objectives. The introduction of the useDelayLoader hook and its application in the NavLink component provide a more controlled approach to managing loading states during navigation.

Key points:

  1. The solution is focused and minimal, reducing the risk of introducing new issues.
  2. The use of a custom hook suggests a reusable approach that could be applied to other components if similar issues arise.

Suggestions for future improvements:

  1. Consider adding comments explaining the purpose of useDelayLoader for future maintainers.
  2. If this solution proves effective, consider applying it to other areas of the application where similar loading state issues might occur.

To further improve the application's architecture and performance:

  1. Consider implementing a global loading state manager using React Context if loading state management becomes a common concern across multiple components.
  2. Evaluate the performance impact of this change and document any significant improvements for future reference.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between cff6f74 and dc9022f.

📒 Files selected for processing (4)
  • apps/dashboard/app/(app)/authorization/permissions/page.tsx (2 hunks)
  • apps/dashboard/app/(app)/desktop-sidebar.tsx (3 hunks)
  • apps/dashboard/lib/hooks/useDelayLoader.tsx (1 hunks)
  • packages/ratelimit/package.json (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/ratelimit/package.json
🔇 Additional comments (5)
apps/dashboard/lib/hooks/useDelayLoader.tsx (1)

1-1: LGTM: Appropriate imports.

The necessary React hooks (useEffect and useState) are correctly imported.

apps/dashboard/app/(app)/authorization/permissions/page.tsx (2)

6-6: LGTM: Import statement added correctly

The addition of the import statement for permissions from @unkey/db/src/schema is appropriate. This change ensures that the permissions schema is explicitly imported and used in the component, which aligns with best practices for code clarity and maintainability.


Line range hint 1-114: Verify impact on icon flickering issue

While the changes in this file improve code quality and consistency, they don't appear to directly address the icon flickering issue mentioned in the PR objectives (issue #2156).

To ensure we're addressing the main objective of this PR:

  1. Please confirm if there are other files in this PR that more directly tackle the icon flickering problem.
  2. If not, consider investigating the rendering of icons in the dashboard, particularly when switching between workspace tabs. This might involve:
    • Checking for any unnecessary re-renders
    • Ensuring proper use of React's key prop for list items
    • Verifying that icon components are optimized for performance

This will help us identify files that might be more relevant to the flickering issue.

apps/dashboard/app/(app)/desktop-sidebar.tsx (2)

6-6: LGTM: New import for useDelayLoader

The new import for useDelayLoader is correctly placed and follows good practices for importing custom hooks.


223-223: Improved loading state management

The introduction of useDelayLoader and the use of showLoader instead of isPending for rendering the loading indicator is a good approach. This change likely addresses the icon flickering issue mentioned in the PR objectives by providing more control over when the loading state is displayed.

A few points to consider:

  1. The implementation looks good and aligns with the PR's goal.
  2. This change should reduce unnecessary re-renders and provide a smoother transition between states.

To ensure this change doesn't introduce any regressions, please verify the following:

  1. The loading indicator appears and disappears smoothly when navigating between tabs.
  2. There's no visible flickering of icons during navigation.

Also applies to: 248-252

@perkinsjr perkinsjr changed the title Fix/dashboard icon flickering fix: dashboard icon flickering Oct 3, 2024
Copy link

vercel bot commented Oct 4, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
dashboard ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 4, 2024 9:47am
planetfall ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 4, 2024 9:47am
play ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 4, 2024 9:47am
workflows ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 4, 2024 9:47am
www ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 4, 2024 9:47am

@chronark
Copy link
Collaborator

chronark commented Oct 4, 2024

Nice one, this is super clean

@chronark chronark added this pull request to the merge queue Oct 4, 2024
@chronark chronark self-assigned this Oct 4, 2024
Merged via the queue into unkeyed:main with commit 3182661 Oct 4, 2024
23 of 27 checks passed
Copy link

oss-gg bot commented Oct 4, 2024

Awarding AkshayBandi027: 150 points 🕹️ Well done! Check out your new contribution on oss.gg/AkshayBandi027

@coderabbitai coderabbitai bot mentioned this pull request Oct 4, 2024
18 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.

[🕹️] Dashboard icon flickering
2 participants