-
Notifications
You must be signed in to change notification settings - Fork 10.4k
refactor: update charts on /insights to use InsightsBookingService #22744
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
Conversation
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 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. 📒 Files selected for processing (23)
WalkthroughThis 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 Estimated code review effort🎯 4 (Complex) | ⏱️ ~40–55 minutes
Possibly related PRs
✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
2cb0737
to
93fa26f
Compare
The latest updates on your projects. Learn more about Vercel for Git ↗︎ |
|
||
type TimeViewType = "week" | "month" | "year" | "day"; | ||
|
||
export interface DateRange { |
There was a problem hiding this comment.
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 = < |
There was a problem hiding this comment.
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
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. |
There was a problem hiding this 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 importThe 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 witht()
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 uset()
.-<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 textLines 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 singleUserStatsTable
. Consider renaming toMostCancelledBookingsTable
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 -->
There was a problem hiding this 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
E2E results are ready! |
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
InsightsBookingService
withcreateInsightsBookingService()
helpertrpc-router.ts
intoInsightsBookingService
Mandatory Tasks (DO NOT REMOVE)
How should this be tested?
Visit /insights and the charts are the same.