Skip to content

[Dashboard] Fix: Async team analytics rendering #7289

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

Merged
merged 1 commit into from
Jun 5, 2025

Conversation

gregfromstl
Copy link
Member

@gregfromstl gregfromstl commented Jun 5, 2025


PR-Codex overview

This PR focuses on improving the analytics components in the dashboard by refining data handling, enhancing user experience with loading states, and restructuring the code for better readability and maintainability.

Detailed summary

  • Added checks for trend in Stat.tsx.
  • Updated date comparison logic in page.tsx filters.
  • Removed redundant checks and simplified conditional rendering in AsyncAppHighlightsCard.
  • Introduced new loading states using LoadingChartState.
  • Refactored OverviewPageContent into multiple async components for better modularity.
  • Improved handling of promises with Promise.allSettled.
  • Enhanced empty state handling for various analytics components.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Summary by CodeRabbit

  • Refactor
    • Improved analytics dashboard performance and reliability by modularizing data fetching and rendering into smaller, independent components.
    • Enhanced error handling and empty state displays for analytics charts.
    • Optimized date comparison for more accurate time series data processing.
  • Bug Fixes
    • Prevented display of trend badges when the trend value is infinite.
  • Style
    • Updated loading states for analytics charts to provide a more consistent visual experience.

@gregfromstl gregfromstl requested review from a team as code owners June 5, 2025 17:08
Copy link

changeset-bot bot commented Jun 5, 2025

⚠️ No Changeset found

Latest commit: 031a66b

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 Jun 5, 2025

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

Name Status Preview Comments Updated (UTC)
thirdweb-www ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 5, 2025 5:16pm
4 Skipped Deployments
Name Status Preview Comments Updated (UTC)
docs-v2 ⬜️ Skipped (Inspect) Jun 5, 2025 5:16pm
login ⬜️ Skipped (Inspect) Jun 5, 2025 5:16pm
thirdweb_playground ⬜️ Skipped (Inspect) Jun 5, 2025 5:16pm
wallet-ui ⬜️ Skipped (Inspect) Jun 5, 2025 5:16pm

Copy link
Contributor

coderabbitai bot commented Jun 5, 2025

Walkthrough

The analytics dashboard was refactored to split a monolithic component into multiple Suspense-wrapped async components, each responsible for fetching and rendering a specific analytics card. Data fetching now uses Promise.allSettled with improved error handling. Time series date comparisons were corrected, and trend badges avoid rendering on infinite values.

Changes

File(s) Change Summary
.../team/[team_slug]/(team)/~/analytics/page.tsx Refactored to use multiple Suspense-wrapped async components for analytics cards; improved data fetching and error handling; updated Suspense fallbacks; improved date comparison in time series processing.
.../team/[team_slug]/[project_slug]/(sidebar)/page.tsx Updated date comparison logic in processTimeSeriesData; simplified condition for rendering AppHighlightsCard.
.../team/components/Analytics/Stat.tsx Modified trend badge rendering to exclude infinite values.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant TeamOverviewPage
    participant AsyncAppHighlightsCard
    participant AsyncWalletDistributionCard
    participant AsyncAuthMethodDistributionCard
    participant AsyncTransactionsChartCard
    participant AsyncTotalSponsoredCard
    participant DataSources

    User->>TeamOverviewPage: Load page
    TeamOverviewPage->>AsyncAppHighlightsCard: Render (Suspense)
    AsyncAppHighlightsCard->>DataSources: Fetch wallet user stats & bridge usage
    TeamOverviewPage->>AsyncWalletDistributionCard: Render (Suspense)
    AsyncWalletDistributionCard->>DataSources: Fetch wallet connections
    TeamOverviewPage->>AsyncAuthMethodDistributionCard: Render (Suspense)
    AsyncAuthMethodDistributionCard->>DataSources: Fetch in-app wallet usage
    TeamOverviewPage->>AsyncTransactionsChartCard: Render (Suspense)
    AsyncTransactionsChartCard->>DataSources: Fetch transactions data
    TeamOverviewPage->>AsyncTotalSponsoredCard: Render (Suspense)
    AsyncTotalSponsoredCard->>DataSources: Fetch sponsored operations data
    Note over TeamOverviewPage: Each card renders chart or empty state based on fetched data
Loading

Possibly related PRs

Suggested labels

Dashboard

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • TEAM-0000: Entity not found: Issue - Could not find referenced Issue.
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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

graphite-app bot commented Jun 5, 2025

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • merge-queue - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

@github-actions github-actions bot added the Dashboard Involves changes to the Dashboard. label Jun 5, 2025
@gregfromstl gregfromstl changed the title Fix:: Async team analytics rendering [Dashboard] Fix: Async team analytics rendering Jun 5, 2025
Copy link

codecov bot commented Jun 5, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 55.58%. Comparing base (7ab79dc) to head (031a66b).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7289   +/-   ##
=======================================
  Coverage   55.58%   55.58%           
=======================================
  Files         909      909           
  Lines       58670    58670           
  Branches     4158     4158           
=======================================
  Hits        32609    32609           
  Misses      25954    25954           
  Partials      107      107           
Flag Coverage Δ
packages 55.58% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

♻️ Duplicate comments (1)
apps/dashboard/src/app/(app)/team/[team_slug]/(team)/~/analytics/page.tsx (1)

315-327: Same date comparison improvement with identical duplication issue.

As suggested in the project analytics file, consider extracting the common filter predicate to reduce duplication.

🧹 Nitpick comments (1)
apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/(sidebar)/page.tsx (1)

233-246: Date comparison fix looks good, but consider reducing duplication.

The ISO string conversion ensures consistent date matching across different formats and timezones. However, the filtering logic is duplicated.

Consider extracting the common filter predicate:

+  const isCompletedOnDate = (v: UniversalBridgeStats, targetDate: string) =>
+    new Date(v.date).toISOString() === new Date(targetDate).toISOString() &&
+    v.status === "completed";

   const volume = volumeStats
-    .filter(
-      (v) =>
-        new Date(v.date).toISOString() ===
-          new Date(stat.date).toISOString() && v.status === "completed",
-    )
+    .filter((v) => isCompletedOnDate(v, stat.date))
     .reduce((acc, curr) => acc + curr.amountUsdCents / 100, 0);

   const fees = volumeStats
-    .filter(
-      (v) =>
-        new Date(v.date).toISOString() ===
-          new Date(stat.date).toISOString() && v.status === "completed",
-    )
+    .filter((v) => isCompletedOnDate(v, stat.date))
     .reduce((acc, curr) => acc + curr.developerFeeUsdCents / 100, 0);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7ab79dc and 031a66b.

📒 Files selected for processing (3)
  • apps/dashboard/src/app/(app)/team/[team_slug]/(team)/~/analytics/page.tsx (3 hunks)
  • apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/(sidebar)/page.tsx (2 hunks)
  • apps/dashboard/src/app/(app)/team/components/Analytics/Stat.tsx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: E2E Tests (pnpm, esbuild)
  • GitHub Check: Size
  • GitHub Check: E2E Tests (pnpm, webpack)
  • GitHub Check: Lint Packages
  • GitHub Check: E2E Tests (pnpm, vite)
  • GitHub Check: Unit Tests
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (4)
apps/dashboard/src/app/(app)/team/components/Analytics/Stat.tsx (1)

15-15: Good defensive check against infinite values.

Adding the infinity check prevents displaying meaningless "Infinity%" values in the trend badge, improving the user experience.

apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/(sidebar)/page.tsx (1)

349-352: Simplified rendering logic is more consistent.

Removing the non-zero user check allows the highlights card to render even with zero activity, which provides better UI consistency and prevents false empty states.

apps/dashboard/src/app/(app)/team/[team_slug]/(team)/~/analytics/page.tsx (2)

79-124: Excellent refactoring to improve modularity and error handling.

Breaking down the monolithic component into smaller, Suspense-wrapped async components provides:

  • Better error isolation with Promise.allSettled
  • Granular loading states for improved UX
  • Parallel data fetching for better performance
  • Enhanced maintainability

153-157:

❓ Verification inconclusive

Inconsistent rendering condition compared to project analytics.

This component checks for non-zero totalUsers before rendering, while the same component in apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/(sidebar)/page.tsx had this check removed. This inconsistency could lead to different behaviors between team and project analytics pages.

Should the rendering conditions be consistent across both analytics pages? If so, consider removing the totalUsers check here as well:

  if (
    walletUserStatsTimeSeries.status === "fulfilled" &&
-   universalBridgeUsage.status === "fulfilled" &&
-   walletUserStatsTimeSeries.value.some((w) => w.totalUsers !== 0)
+   universalBridgeUsage.status === "fulfilled"
  ) {

Run this script to check for other instances of this pattern:


🏁 Script executed:

#!/bin/bash
# Description: Find all instances of AsyncAppHighlightsCard to verify rendering conditions

# Search for AsyncAppHighlightsCard component definitions and usages
ast-grep --pattern 'AsyncAppHighlightsCard'

# Look for totalUsers checks in analytics components
rg -A 5 'totalUsers !== 0|totalUsers === 0' --glob '**/analytics/**'

Length of output: 1236


Inconsistent rendering logic between team and project analytics pages

The Team analytics page (apps/dashboard/src/app/(app)/team/[team_slug]/(team)/~/analytics/page.tsx lines 153–157) still guards on non-zero totalUsers, whereas the Project analytics page (apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/(sidebar)/page.tsx) has removed that check. This divergence can cause confusing UX and maintenance drift.

• Team page condition:

if (
  walletUserStatsTimeSeries.status === "fulfilled" &&
  universalBridgeUsage.status === "fulfilled" &&
  walletUserStatsTimeSeries.value.some((w) => w.totalUsers !== 0)
) {
  
}

• Project page condition:

if (
  walletUserStatsTimeSeries.status === "fulfilled" &&
  universalBridgeUsage.status === "fulfilled"
) {
  
}

If the intention is to align both views, remove the totalUsers filter on the Team page:

  if (
    walletUserStatsTimeSeries.status === "fulfilled" &&
-   universalBridgeUsage.status === "fulfilled" &&
-   walletUserStatsTimeSeries.value.some((w) => w.totalUsers !== 0)
+   universalBridgeUsage.status === "fulfilled"
  ) {

Please verify whether filtering out zero-user series was intentionally dropped in the project view or if it should be removed here as well. To find other occurrences, you can run:

#!/bin/bash
# Search for totalUsers checks in analytics pages
rg -n 'walletUserStatsTimeSeries.value.some.*totalUsers' --glob '**/analytics/**'

Copy link
Contributor

github-actions bot commented Jun 5, 2025

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
thirdweb (esm) 62.57 KB (0%) 1.3 s (0%) 147 ms (+69.09% 🔺) 1.4 s
thirdweb (cjs) 345.55 KB (0%) 7 s (0%) 603 ms (-5.36% 🔽) 7.6 s
thirdweb (minimal + tree-shaking) 5.7 KB (0%) 114 ms (0%) 62 ms (+1167.67% 🔺) 176 ms
thirdweb/chains (tree-shaking) 531 B (0%) 11 ms (0%) 21 ms (+380.79% 🔺) 31 ms
thirdweb/react (minimal + tree-shaking) 19.56 KB (0%) 392 ms (0%) 56 ms (+311.8% 🔺) 447 ms

@gregfromstl gregfromstl merged commit 6610633 into main Jun 5, 2025
25 checks passed
@gregfromstl gregfromstl deleted the greg/team-analytics-cleanup branch June 5, 2025 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Dashboard Involves changes to the Dashboard.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant