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: Improve the arrangement of metrics in mobile view in ratelimit overview page #2732

Merged
merged 14 commits into from
Dec 11, 2024

Conversation

BadriVishalPadhy
Copy link
Contributor

@BadriVishalPadhy BadriVishalPadhy commented Dec 10, 2024

What does this PR do?

Vertically arranged the metrics in mobile view in ratelimit->overview page

Fixes #2731

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Chore (refactoring code, technical debt, workflow improvements)
  • [ x] 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?

  • Test A
  • Test B

Checklist

Required

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

Appreciated

  • [ x ] If a UI change was made: Added a screen recording or screenshots to this PR
  • Updated the Unkey Docs if changes were necessary
Screenshot 2024-12-10 at 16 22 15

Summary by CodeRabbit

  • New Features

    • Introduced a new TimestampInfo component for displaying formatted timestamps (local, UTC, and relative).
    • Enhanced the layout and responsiveness of the RatelimitNamespacePage component.
  • Bug Fixes

    • Corrected minor formatting issues in class names for improved responsiveness.

Copy link

changeset-bot bot commented Dec 10, 2024

⚠️ No Changeset found

Latest commit: c751bb7

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 Dec 10, 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 Dec 11, 2024 6:27pm
engineering ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 11, 2024 6:27pm
play ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 11, 2024 6:27pm
www ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 11, 2024 6:27pm

Copy link

vercel bot commented Dec 10, 2024

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

A member of the Team first needs to authorize it.

@github-actions github-actions bot added Feature New feature or request Needs Approval Needs approval from Unkey labels Dec 10, 2024
Copy link
Contributor

github-actions bot commented Dec 10, 2024

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

@BadriVishalPadhy
Copy link
Contributor Author

@ogzhanolguncu check plz

Copy link
Contributor

coderabbitai bot commented Dec 10, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes in this pull request primarily focus on the RatelimitNamespacePage component, enhancing the layout and styling for improved responsiveness, particularly for mobile views. The changes include adjustments to class names for the main container and the CardContent component. Additionally, a new component named TimestampInfo has been introduced to format and display timestamps in various formats, utilizing React hooks for dynamic tooltip alignment.

Changes

File Path Change Summary
apps/dashboard/app/(app)/ratelimits/[namespaceId]/page.tsx Modified layout and styling for responsiveness; class name adjustments for main container and CardContent.
apps/dashboard/components/timestamp-info 2.tsx Introduced TimestampInfo component for displaying formatted timestamps with tooltip functionality.

Assessment against linked issues

Objective Addressed Explanation
Improve the arrangement of metrics in mobile view (2731)

Possibly related PRs

  • fix: Responsiveness issue of ratelimit page #2710: This PR addresses responsiveness issues on the RatelimitNamespacePage, which is directly related to the changes made in the main PR that also updates the same component for layout and styling improvements.
  • fix: Ratelimit identifier component changes #2712: This PR modifies the Ratelimit identifier component, which is part of the same functionality as the RatelimitNamespacePage in the main PR, indicating a connection in the context of rate limit management.
  • fix: ratelimit date input and time display logs #2717: This PR focuses on enhancing date input and time display in the ratelimit logs, which aligns with the overall functionality of the RatelimitNamespacePage in the main PR, as both deal with date and time management in the context of rate limits.

Suggested reviewers

  • mcstepp
  • chronark
  • ogzhanolguncu
  • perkinsjr

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 9f85fc0 and 12058ec.

📒 Files selected for processing (1)
  • apps/dashboard/app/(app)/ratelimits/[namespaceId]/page.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/dashboard/app/(app)/ratelimits/[namespaceId]/page.tsx

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. (Experiment)
  • @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: 1

🧹 Outside diff range and nitpick comments (3)
apps/dashboard/components/timestamp-info 2.tsx (1)

50-65: Consider debouncing the scroll and resize event listeners

The current implementation might cause performance issues on mobile devices as scroll and resize events can fire frequently.

 useEffect(() => {
+  const debounce = (fn: Function, ms = 100) => {
+    let timeoutId: ReturnType<typeof setTimeout>;
+    return function (this: any, ...args: any[]) {
+      clearTimeout(timeoutId);
+      timeoutId = setTimeout(() => fn.apply(this, args), ms);
+    };
+  };
+
+  const debouncedUpdateAlignment = debounce(updateAlignment);
   const updateAlignment = () => {
     if (triggerRef.current) {
       const rect = triggerRef.current.getBoundingClientRect();
       const windowHeight = window.innerHeight;
       setAlign(rect.top < windowHeight / 2 ? "start" : "end");
     }
   };
   updateAlignment();
-  window.addEventListener("scroll", updateAlignment);
-  window.addEventListener("resize", updateAlignment);
+  window.addEventListener("scroll", debouncedUpdateAlignment);
+  window.addEventListener("resize", debouncedUpdateAlignment);
   return () => {
-    window.removeEventListener("scroll", updateAlignment);
-    window.removeEventListener("resize", updateAlignment);
+    window.removeEventListener("scroll", debouncedUpdateAlignment);
+    window.removeEventListener("resize", debouncedUpdateAlignment);
   };
 }, []);
apps/dashboard/app/(app)/ratelimits/[namespaceId]/page.tsx (2)

128-128: Remove unnecessary double spaces in className strings

There are extra spaces in the className strings which should be removed for consistency.

-    <div className="flex flex-col  gap-4">
+    <div className="flex flex-col gap-4">
       <Card>
-        <CardContent className="grid sm:grid-cols-3  sm:divide-x">
+        <CardContent className="grid sm:grid-cols-3 sm:divide-x">

Also applies to: 130-130


Line range hint 130-143: Consider adding explicit mobile layout classes

While the layout switches to a single column on mobile by default, consider adding explicit mobile-first classes for better clarity.

-        <CardContent className="grid sm:grid-cols-3  sm:divide-x">
+        <CardContent className="grid grid-cols-1 gap-4 sm:gap-0 sm:grid-cols-3 sm:divide-x">
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 2364e6b and 8a09eba.

📒 Files selected for processing (2)
  • apps/dashboard/app/(app)/ratelimits/[namespaceId]/page.tsx (1 hunks)
  • apps/dashboard/components/timestamp-info 2.tsx (1 hunks)
🔇 Additional comments (2)
apps/dashboard/components/timestamp-info 2.tsx (1)

1-1: Consider adding proper attribution and license information

The comment indicates this file is based on Supabase's implementation. Ensure proper attribution and license compliance are maintained.

apps/dashboard/app/(app)/ratelimits/[namespaceId]/page.tsx (1)

Line range hint 128-143: Verify mobile responsiveness across different screen sizes

The layout changes look good, but we should verify the responsiveness across various mobile devices and screen sizes.

✅ Verification successful

Let me analyze the code further to verify the responsive design implementation.


Responsive design implementation verified and follows best practices

The implementation demonstrates proper responsive design patterns:

  • Uses sm:grid-cols-3 with a proper fallback for mobile (single column)
  • Implements responsive text sizing (text-xs sm:text-xxs)
  • Handles spacing responsively (gap-0 sm:gap-8)
  • Includes mobile-specific display logic (hidden sm:block)
  • Follows dashboard-wide grid pattern conventions
  • Uses flexible layouts with flex and flex-col for adaptable content
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any responsive design test configurations
fd -e spec.tsx -e spec.ts -e test.tsx -e test.ts | xargs rg -l "viewport|screen size|mobile|responsive"

# Look for existing responsive design patterns
rg -l "sm:|md:|lg:|xl:|2xl:"

Length of output: 6046


Script:

#!/bin/bash
# Check the specific file for responsive design patterns and grid implementation
rg -A 5 "sm:|md:|lg:|xl:|2xl:" "apps/dashboard/app/(app)/ratelimits/[namespaceId]/page.tsx"

# Look for similar grid patterns in other dashboard pages for consistency
rg "grid sm:grid-cols-[23]" "apps/dashboard/app/(app)/"

# Check for any responsive design utilities or components used
rg "className=\".*flex.*\"" "apps/dashboard/app/(app)/ratelimits/[namespaceId]/page.tsx"

Length of output: 1702

apps/dashboard/components/timestamp-info 2.tsx Outdated Show resolved Hide resolved
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: 3

🧹 Outside diff range and nitpick comments (2)
apps/dashboard/components/timestamp-info 2.tsx (1)

50-65: Optimize scroll and resize event listeners

The current implementation might cause unnecessary re-renders on frequent scroll/resize events.

Consider debouncing the event handlers:

+ import debounce from 'lodash/debounce';

  useEffect(() => {
-   const updateAlignment = () => {
+   const updateAlignment = debounce(() => {
      if (triggerRef.current) {
        const rect = triggerRef.current.getBoundingClientRect();
        const windowHeight = window.innerHeight;
        setAlign(rect.top < windowHeight / 2 ? "start" : "end");
      }
-   };
+   }, 150);
    updateAlignment();
    window.addEventListener("scroll", updateAlignment);
    window.addEventListener("resize", updateAlignment);
    return () => {
      window.removeEventListener("scroll", updateAlignment);
      window.removeEventListener("resize", updateAlignment);
+     updateAlignment.cancel();
    };
  }, []);
apps/dashboard/app/(app)/ratelimits/[namespaceId]/page.tsx (1)

130-130: Remove extra whitespace in className

There are multiple consecutive spaces in the className string.

- <CardContent className="grid sm:grid-cols-3  sm:divide-x">
+ <CardContent className="grid sm:grid-cols-3 sm:divide-x">
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 2364e6b and 8a09eba.

📒 Files selected for processing (2)
  • apps/dashboard/app/(app)/ratelimits/[namespaceId]/page.tsx (1 hunks)
  • apps/dashboard/components/timestamp-info 2.tsx (1 hunks)
🔇 Additional comments (1)
apps/dashboard/app/(app)/ratelimits/[namespaceId]/page.tsx (1)

128-130: Verify mobile layout improvements

The grid layout changes look good for improving mobile responsiveness. The sm:grid-cols-3 ensures single-column layout on mobile and three columns on larger screens.

✅ Verification successful

Let me gather more context about the grid layout patterns to ensure consistency.


Mobile layout implementation is consistent with app patterns

The grid layout implementation in the ratelimits page follows the established responsive design patterns across the app:

  • Uses flex flex-col gap-4 for vertical stacking of components
  • Implements grid sm:grid-cols-3 with sm:divide-x for metric cards, matching the pattern used in other dashboard pages like the API keys view
  • Properly handles the mobile-first approach by defaulting to single column and expanding to 3 columns on larger screens
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for consistent responsive design patterns across the app
rg -l 'sm:grid-cols-[0-9]' | xargs rg 'flex flex-col.*gap-4'

Length of output: 375


Script:

#!/bin/bash
# Check the grid layout implementation in the files that use sm:grid-cols
rg -l 'sm:grid-cols-[0-9]' | xargs rg 'grid.*sm:grid-cols|sm:grid-cols.*grid' -B 2 -A 2

Length of output: 2952

apps/dashboard/components/timestamp-info 2.tsx Outdated Show resolved Hide resolved
apps/dashboard/components/timestamp-info 2.tsx Outdated Show resolved Hide resolved
apps/dashboard/components/timestamp-info 2.tsx Outdated Show resolved Hide resolved
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: 3

🧹 Outside diff range and nitpick comments (3)
apps/dashboard/components/timestamp-info 2.tsx (1)

9-17: Consider adding input validation and error handling

The timestamp conversion functions could benefit from additional error handling:

  1. Validate input ranges
  2. Handle invalid inputs gracefully
 const unixMicroToDate = (unix: string | number): Date => {
+  if (!isUnixMicro(unix)) {
+    throw new Error('Invalid Unix microsecond timestamp');
+  }
   return fromUnixTime(Number(unix) / 1000 / 1000);
 };

 const isUnixMicro = (unix: string | number): boolean => {
+  if (unix === null || unix === undefined) {
+    return false;
+  }
   const digitLength = String(unix).length === 16;
   const isNum = !Number.isNaN(Number(unix));
   return isNum && digitLength;
 };
apps/dashboard/app/(app)/ratelimits/[namespaceId]/page.tsx (2)

128-130: Clean up unnecessary whitespace in className strings

There are extra spaces in the className strings that should be removed.

-    <div className="flex flex-col  gap-4">
+    <div className="flex flex-col gap-4">
       <Card>
-        <CardContent className="grid sm:grid-cols-3  sm:divide-x">
+        <CardContent className="grid sm:grid-cols-3 sm:divide-x">

130-130: Enhance mobile responsiveness

While the changes improve mobile layout, consider these additional improvements:

  1. Add padding for better touch targets on mobile
  2. Consider adjusting text sizes for better readability
-        <CardContent className="grid sm:grid-cols-3 sm:divide-x">
+        <CardContent className="grid gap-4 sm:gap-0 sm:grid-cols-3 sm:divide-x p-4">

-          <Code className="flex items-start  gap-0 sm:gap-8 p-4 my-8  text-xs  sm:text-xxs text-start overflow-x-auto max-w-full">
+          <Code className="flex items-start gap-0 sm:gap-8 p-4 my-8 text-sm sm:text-xs text-start overflow-x-auto max-w-full">

Also applies to: 191-192

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 2364e6b and 8a09eba.

📒 Files selected for processing (2)
  • apps/dashboard/app/(app)/ratelimits/[namespaceId]/page.tsx (1 hunks)
  • apps/dashboard/components/timestamp-info 2.tsx (1 hunks)

apps/dashboard/components/timestamp-info 2.tsx Outdated Show resolved Hide resolved
apps/dashboard/components/timestamp-info 2.tsx Outdated Show resolved Hide resolved
apps/dashboard/components/timestamp-info 2.tsx Outdated Show resolved Hide resolved
@ogzhanolguncu
Copy link
Contributor

ogzhanolguncu commented Dec 10, 2024

Also, let's add horizontal dividers similar to what we use in vertical design

@ogzhanolguncu ogzhanolguncu added this pull request to the merge queue Dec 11, 2024
@ogzhanolguncu ogzhanolguncu added Improvement Improve an existing feature and removed Feature New feature or request labels Dec 11, 2024
Merged via the queue into unkeyed:main with commit 5fafbbe Dec 11, 2024
23 of 24 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Dec 21, 2024
18 tasks
@BadriVishalPadhy
Copy link
Contributor Author

@ogzhanolguncu hey can i ask u something

@ogzhanolguncu
Copy link
Contributor

Sure

@BadriVishalPadhy
Copy link
Contributor Author

BadriVishalPadhy commented Dec 27, 2024

@ogzhanolguncu can i work as intern at unkey
I am actively looking for an internship . . .

@perkinsjr
Copy link
Collaborator

@ogzhanolguncu can i work as intern at unkey

I am actively looking for an internship . . .

I Appreciate your interest in interning at Unkey. We currently don't offer internships as we are a small team and don't have the infrastructure to offer it at this time.

@BadriVishalPadhy
Copy link
Contributor Author

thnks @perkinsjr if there will be any job roles or intern open please do consider me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Improvement Improve an existing feature Needs Approval Needs approval from Unkey
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve the arrangement of metrics in mobile view in ratelimit->overview page
3 participants