Skip to content

Conversation

eunjae-lee
Copy link
Contributor

@eunjae-lee eunjae-lee commented Jul 25, 2025

What does this PR do?

This PR refactors the insights booking charts to use the standardized InsightsBookingService architecture, replacing custom data fetching implementations with a consistent, maintainable approach. The refactoring improves performance, code organization, and developer experience while maintaining all existing functionality.

Key improvements

  • Standardized all booking charts to use InsightsBookingService with createInsightsBookingService() helper
  • Renamed tPRC handlers to match the chart component names.
  • Moved data fetching logic from trpc-router.ts into InsightsBookingService

Mandatory Tasks (DO NOT REMOVE)

  • I have self-reviewed the code (A decent size PR without self-review might be rejected).
  • I have updated the developer docs in /docs if this PR makes changes that would require a documentation change. If N/A, write N/A here and check the checkbox.
  • I confirm automated tests are in place that prove my fix is effective or that my feature works.

How should this be tested?

Visit /insights and the charts are the same.

Copy link
Contributor

coderabbitai bot commented Jul 25, 2025

Warning

Rate limit exceeded

@eunjae-lee has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 7 minutes and 21 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between bd3420a and 37894c8.

📒 Files selected for processing (23)
  • packages/features/insights/components/BookingAtCell.tsx (1 hunks)
  • packages/features/insights/components/ChartCard.tsx (1 hunks)
  • packages/features/insights/components/FeedbackTable.tsx (1 hunks)
  • packages/features/insights/components/KPICard.tsx (1 hunks)
  • packages/features/insights/components/UserStatsTable.tsx (3 hunks)
  • packages/features/insights/components/booking/AverageEventDurationChart.tsx (1 hunks)
  • packages/features/insights/components/booking/BookingKPICards.tsx (1 hunks)
  • packages/features/insights/components/booking/EventTrendsChart.tsx (1 hunks)
  • packages/features/insights/components/booking/HighestNoShowHostTable.tsx (1 hunks)
  • packages/features/insights/components/booking/HighestRatedMembersTable.tsx (2 hunks)
  • packages/features/insights/components/booking/LeastBookedTeamMembersTable.tsx (2 hunks)
  • packages/features/insights/components/booking/LowestRatedMembersTable.tsx (2 hunks)
  • packages/features/insights/components/booking/MostBookedTeamMembersTable.tsx (2 hunks)
  • packages/features/insights/components/booking/MostCancelledBookingsTables.tsx (1 hunks)
  • packages/features/insights/components/booking/PopularEventsTable.tsx (1 hunks)
  • packages/features/insights/components/booking/RecentFeedbackTable.tsx (1 hunks)
  • packages/features/insights/components/booking/TimezoneBadge.tsx (1 hunks)
  • packages/features/insights/components/routing/FailedBookingsByField.tsx (1 hunks)
  • packages/features/insights/components/routing/RoutedToPerPeriod.tsx (2 hunks)
  • packages/features/insights/components/routing/RoutingKPICards.tsx (1 hunks)
  • packages/features/insights/components/tremor/BarList.tsx (1 hunks)
  • packages/features/insights/server/__tests__/events.test.ts (47 hunks)
  • packages/features/insights/server/insightsDateUtils.ts (1 hunks)

Walkthrough

This update implements a comprehensive refactor and modularization of the insights and analytics features related to bookings and routing. The changes include the extraction and migration of booking-related components into a dedicated booking directory, the introduction of new hooks (useInsightsBookingParameters), and the consolidation of component exports via index files for both booking and routing insights. Several booking insights components were refactored to use the new hook for parameter aggregation. On the backend, the insightsRouter and the InsightsBookingService were significantly expanded and refactored, delegating most analytics queries and aggregations to service methods. Date range and period formatting utilities were extracted into a new insightsDateUtils module. Several legacy or redundant components were removed or replaced, and a detailed developer guide was added for extending booking charts.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~40–55 minutes

  • Complexity: High. This PR involves the migration and refactoring of numerous frontend components, the introduction of new hooks and index modules, significant backend service and router refactoring, removal and replacement of legacy code, and the addition of new utilities and documentation. The changes impact both frontend and backend logic across many files, requiring careful review for correctness, regression, and consistency.

Possibly related PRs

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor/charts-on-insights

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 generate unit tests to generate unit tests for 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.

@keithwillcode keithwillcode added consumer core area: core, team members only labels Jul 25, 2025
@eunjae-lee eunjae-lee force-pushed the refactor/charts-on-insights branch from 2cb0737 to 93fa26f Compare July 25, 2025 16:16
Copy link

vercel bot commented Jul 25, 2025

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

2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
cal ⬜️ Ignored (Inspect) Jul 29, 2025 9:32am
cal-eu ⬜️ Ignored (Inspect) Jul 29, 2025 9:32am


type TimeViewType = "week" | "month" | "year" | "day";

export interface DateRange {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are moved from events.ts file as-is

import type { readonlyPrisma } from "@calcom/prisma";
import { MembershipRole } from "@calcom/prisma/enums";

import { MembershipRepository } from "../repository/membership";
import { TeamRepository } from "../repository/team";

// Utility function to build user hash map with avatar URL fallback
export const buildHashMapForUsers = <
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the logics added in this file are almost moved from trpc-router.ts, but the main queries are mostly converted to raw query though

@eunjae-lee eunjae-lee marked this pull request as ready for review July 29, 2025 09:10
@graphite-app graphite-app bot requested review from a team July 29, 2025 09:10
@dosubot dosubot bot added insights area: insights, analytics 💻 refactor labels Jul 29, 2025
Copy link

graphite-app bot commented Jul 29, 2025

Graphite Automations

"Add consumer team as reviewer" took an action on this PR • (07/29/25)

1 reviewer was added to this PR based on Keith Williams's automation.

"Add foundation team as reviewer" took an action on this PR • (07/29/25)

1 reviewer was added to this PR based on Keith Williams's automation.

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

🔭 Outside diff range comments (1)
packages/features/insights/server/__tests__/events.test.ts (1)

803-858: Update tests to use direct formatPeriod import

The tests at the bottom of events.test.ts import formatPeriod directly but still call EventsInsights.formatPeriod. Replace these calls for consistency and to avoid runtime errors.

Affected locations in packages/features/insights/server/tests/events.test.ts:

  • Month View “without year” test
  • Month View “with year” test
  • Year View “same year” test
  • Year View “different years” test
  • Invalid View test
-        const result = EventsInsights.formatPeriod({
+        const result = formatPeriod({
🧹 Nitpick comments (7)
apps/web/app/(use-page-wrapper)/settings/(admin-layout)/admin/playground/bookings-by-hour/page.tsx (1)

40-44: Hard-coded UI copy should be wrapped with t()

Strings like "Bookings by Hour Playground" and the paragraph on line 42 bypass the i18n layer. Per project guidelines every visible string in .tsx must use t().

-<h1 className="text-3xl font-bold">Bookings by Hour Playground</h1>
+<h1 className="text-3xl font-bold">{t("bookings_by_hour_playground_title")}</h1>

-<p className="mt-2 text-gray-600">
-  This page demonstrates the BookingsByHourChartContent component with sample data.
-</p>
+<p className="mt-2 text-gray-600">
+  {t("bookings_by_hour_playground_description")}
+</p>
apps/web/app/(use-page-wrapper)/settings/(admin-layout)/admin/playground/routing-funnel/page.tsx (1)

61-64: Localize visible text

Lines 61-64 embed plain English copy. Please wrap with t() keys for consistency with localization policy.

-<h1 className="text-3xl font-bold">Routing Funnel Playground</h1>
+<h1 className="text-3xl font-bold">{t("routing_funnel_playground_title")}</h1>

-<p className="mt-2 text-gray-600">
-  This page demonstrates the RoutingFunnelContent component with sample data.
-</p>
+<p className="mt-2 text-gray-600">
+  {t("routing_funnel_playground_description")}
+</p>
packages/features/insights/components/booking/MostCancelledBookingsTables.tsx (1)

9-9: Consider renaming component to match its singular functionality.

The component name MostCancelledBookingsTables uses plural "Tables" but only renders a single UserStatsTable. Consider renaming to MostCancelledBookingsTable for consistency.

-export const MostCancelledBookingsTables = () => {
+export const MostCancelledBookingsTable = () => {
packages/features/insights/hooks/useInsightsBookingParameters.ts (2)

23-36: Consider performance optimization for date calculations.

The date calculations using dayjs are wrapped in useMemo which is good, but in performance-critical scenarios with frequent re-renders, consider using native Date operations or dayjs .utc() methods as they are more performant.


20-22: Track the timezone handling refactor.

The TODO indicates an important architectural improvement to move timezone handling to the DateRangeFilter component. This would simplify both frontend and backend code.

Would you like me to create a GitHub issue to track this technical debt item about moving timezone handling to DateRangeFilter?

packages/features/insights/HOW_TO_ADD_BOOKING_CHARTS.md (1)

9-11: Add language specifier to fenced code block.

The fenced code block is missing a language specifier. While it's a text diagram, adding text as the language specifier improves markdown rendering consistency.

-```
+```text
 UI Component → tRPC Handler → Insights Service → Database Query → Response

</blockquote></details>
<details>
<summary>packages/lib/server/service/insightsBooking.ts (1)</summary><blockquote>

`23-24`: **Address TODO: Migrate to AVATAR_FALLBACK constant.**

The TODO indicates a planned migration from the avatar.png endpoint.


Would you like me to create an issue to track migrating from the `avatar.png` endpoint to using the `AVATAR_FALLBACK` constant?

</blockquote></details>

</blockquote></details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->

Copy link
Member

@sean-brydon sean-brydon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started reveiwing this only noticed the use client issue.

Asked Claude Code to review because i couldnt find anything wrong. Neither could it.

Tested manually works perfect! Nice job man

Copy link
Contributor

E2E results are ready!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
consumer core area: core, team members only insights area: insights, analytics ready-for-e2e 💻 refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants