Skip to content

Comments

feat: add booking status filter to /insights#22842

Merged
emrysal merged 6 commits intomainfrom
eunjae/cal-5448-allow-filtering-all-columns
Aug 4, 2025
Merged

feat: add booking status filter to /insights#22842
emrysal merged 6 commits intomainfrom
eunjae/cal-5448-allow-filtering-all-columns

Conversation

@eunjae-lee
Copy link
Contributor

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

What does this PR do?

This PR adds "booking status" filter to the /insights page (including a bit of refactoring)

  • Fixes CAL-5448

Visual Demo (For contributors especially)

Screenshot 2025-07-31 at 16 05 02

Mandatory Tasks (DO NOT REMOVE)

  • I have self-reviewed the code (A decent size PR without self-review might be rejected).
  • N/A - 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 try the "Booking status" filter

@vercel
Copy link

vercel bot commented Jul 31, 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) Aug 4, 2025 0:53am
cal-eu ⬜️ Ignored (Inspect) Aug 4, 2025 0:53am

@linear
Copy link

linear bot commented Jul 31, 2025

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 31, 2025

Walkthrough

This set of changes refactors the filtering mechanism for booking insights in the application. It introduces a new hook (useInsightsBookingFacetedUniqueValues) for faceted filtering, updates column definitions and filtering logic in related hooks and components, and modifies the backend schema and service logic to support a generalized column filter array instead of individual filter fields. The changes affect both frontend (React hooks, components, and localization) and backend (schemas, service, and router) code, aligning the filtering capabilities with all visible columns in the booking insights table.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15–20 minutes

Assessment against linked issues

Objective Addressed Explanation
Allow filtering all columns in Insights bookings table (CAL-5448)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes found.

Possibly related PRs

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 49d25c3 and 531b8b5.

📒 Files selected for processing (1)
  • packages/features/insights/server/trpc-router.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/features/insights/server/trpc-router.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
  • GitHub Check: Tests / E2E Embed Core
  • GitHub Check: Tests / E2E App Store
  • GitHub Check: Tests / E2E Embed React
  • GitHub Check: Analyze Build / analyze
  • GitHub Check: Tests / E2E (4/4)
  • GitHub Check: Tests / E2E API v2
  • GitHub Check: Tests / E2E (1/4)
  • GitHub Check: Tests / E2E (3/4)
  • GitHub Check: Tests / E2E (2/4)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch eunjae/cal-5448-allow-filtering-all-columns

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

Support

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

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 31, 2025
userId,
teamId,
isAll,
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

just renaming useInsightsFacetedUniqueValues to useInsightsRoutingFacetedUniqueValues.

@@ -0,0 +1,76 @@
import type { Table } from "@tanstack/react-table";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Created a similar file but dedicated to the /insights page.

This provides faceted values for "status", "userId", "eventTypeId"

}, [createdAtRange?.endDate])
);
const columnFilters = useColumnFilters({ exclude: ["createdAt"] });

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Instead of getting filter values one by one and passing all of them, we're now just returning the whole columnFilters, and the server side will handle them (picking them and building sql conditions, etc)

columnHelper.accessor("eventTypeId", {
id: "eventTypeId",
header: t("event_type"),
columnHelper.accessor("status", {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

adding "status" (booking status) column

@eunjae-lee eunjae-lee marked this pull request as ready for review July 31, 2025 14:06
@graphite-app graphite-app bot requested a review from a team July 31, 2025 14:06
@dosubot dosubot bot added insights area: insights, analytics ✨ feature New feature or request labels Jul 31, 2025
@graphite-app
Copy link

graphite-app bot commented Jul 31, 2025

Graphite Automations

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

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

"Add ready-for-e2e label" took an action on this PR • (08/01/25)

1 label 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: 0

🧹 Nitpick comments (1)
apps/web/public/static/locales/en/common.json (1)

3432-3432: Align label capitalisation with existing strings

Most booking-related labels use Title Case (e.g., “Booking Paid”, “Booking Canceled”).
For consistency change the value to “Booking Status”.

-"booking_status": "Booking status",
+"booking_status": "Booking Status",
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2cc7827 and b8d70f3.

📒 Files selected for processing (9)
  • apps/web/public/static/locales/en/common.json (1 hunks)
  • packages/features/insights/components/routing/RoutingFormResponsesTable.tsx (2 hunks)
  • packages/features/insights/hooks/useInsightsBookingFacetedUniqueValues.ts (1 hunks)
  • packages/features/insights/hooks/useInsightsBookingParameters.ts (2 hunks)
  • packages/features/insights/hooks/useInsightsBookings.ts (2 hunks)
  • packages/features/insights/hooks/useInsightsRoutingFacetedUniqueValues.ts (1 hunks)
  • packages/features/insights/server/raw-data.schema.ts (1 hunks)
  • packages/features/insights/server/trpc-router.ts (2 hunks)
  • packages/lib/server/service/insightsBooking.ts (4 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.ts

📄 CodeRabbit Inference Engine (.cursor/rules/review.mdc)

**/*.ts: For Prisma queries, only select data you need; never use include, always use select
Ensure the credential.key field is never returned from tRPC endpoints or APIs

Files:

  • packages/features/insights/hooks/useInsightsBookingFacetedUniqueValues.ts
  • packages/features/insights/server/trpc-router.ts
  • packages/features/insights/hooks/useInsightsRoutingFacetedUniqueValues.ts
  • packages/lib/server/service/insightsBooking.ts
  • packages/features/insights/hooks/useInsightsBookingParameters.ts
  • packages/features/insights/server/raw-data.schema.ts
  • packages/features/insights/hooks/useInsightsBookings.ts
**/*.{ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/review.mdc)

Flag excessive Day.js use in performance-critical code; prefer native Date or Day.js .utc() in hot paths like loops

Files:

  • packages/features/insights/hooks/useInsightsBookingFacetedUniqueValues.ts
  • packages/features/insights/server/trpc-router.ts
  • packages/features/insights/hooks/useInsightsRoutingFacetedUniqueValues.ts
  • packages/features/insights/components/routing/RoutingFormResponsesTable.tsx
  • packages/lib/server/service/insightsBooking.ts
  • packages/features/insights/hooks/useInsightsBookingParameters.ts
  • packages/features/insights/server/raw-data.schema.ts
  • packages/features/insights/hooks/useInsightsBookings.ts
**/*.tsx

📄 CodeRabbit Inference Engine (.cursor/rules/review.mdc)

Always use t() for text localization in frontend code; direct text embedding should trigger a warning

Files:

  • packages/features/insights/components/routing/RoutingFormResponsesTable.tsx
🧠 Learnings (9)
📓 Common learnings
Learnt from: eunjae-lee
PR: calcom/cal.com#22106
File: packages/features/insights/components/RoutingFunnel.tsx:15-17
Timestamp: 2025-07-15T12:58:40.539Z
Learning: In the insights routing funnel component (packages/features/insights/components/RoutingFunnel.tsx), the useColumnFilters exclusions are intentionally different from the general useInsightsParameters exclusions. RoutingFunnel specifically excludes only ["createdAt"] while useInsightsParameters excludes ["bookingUserId", "formId", "createdAt", "eventTypeId"]. This difference is by design.
Learnt from: eunjae-lee
PR: calcom/cal.com#22106
File: packages/features/insights/components/FailedBookingsByField.tsx:65-71
Timestamp: 2025-07-15T12:59:34.389Z
Learning: In the FailedBookingsByField component (packages/features/insights/components/FailedBookingsByField.tsx), although routingFormId is typed as optional in useInsightsParameters, the system automatically enforces a routing form filter, so routingFormId is always present in practice. This means the data always contains only one entry, making the single-entry destructuring approach safe.
Learnt from: eunjae-lee
PR: calcom/cal.com#22702
File: packages/lib/server/service/insightsBooking.ts:120-124
Timestamp: 2025-07-24T08:39:06.185Z
Learning: In the InsightsBookingService (packages/lib/server/service/insightsBooking.ts), the constructor stores null for invalid options or filters but this is handled safely through null checks in buildFilterConditions() and buildAuthorizationConditions() methods. The service uses defensive programming to return safe fallback conditions (null or NOTHING_CONDITION) rather than throwing errors on invalid inputs.
Learnt from: eunjae-lee
PR: calcom/cal.com#22106
File: packages/lib/server/service/insightsRouting.ts:367-368
Timestamp: 2025-07-15T13:02:17.403Z
Learning: In the InsightsRoutingService (packages/lib/server/service/insightsRouting.ts), multi-select filter data is already validated by zod before reaching the buildFormFieldSqlCondition method, so null/undefined values are not present in filterValue.data arrays and don't need to be filtered out.
📚 Learning: in the insights routing funnel component (packages/features/insights/components/routingfunnel.tsx), ...
Learnt from: eunjae-lee
PR: calcom/cal.com#22106
File: packages/features/insights/components/RoutingFunnel.tsx:15-17
Timestamp: 2025-07-15T12:58:40.539Z
Learning: In the insights routing funnel component (packages/features/insights/components/RoutingFunnel.tsx), the useColumnFilters exclusions are intentionally different from the general useInsightsParameters exclusions. RoutingFunnel specifically excludes only ["createdAt"] while useInsightsParameters excludes ["bookingUserId", "formId", "createdAt", "eventTypeId"]. This difference is by design.

Applied to files:

  • packages/features/insights/hooks/useInsightsBookingFacetedUniqueValues.ts
  • packages/features/insights/server/trpc-router.ts
  • packages/features/insights/hooks/useInsightsRoutingFacetedUniqueValues.ts
  • packages/features/insights/components/routing/RoutingFormResponsesTable.tsx
  • packages/lib/server/service/insightsBooking.ts
  • packages/features/insights/hooks/useInsightsBookingParameters.ts
  • packages/features/insights/server/raw-data.schema.ts
  • packages/features/insights/hooks/useInsightsBookings.ts
📚 Learning: in the failedbookingsbyfield component (packages/features/insights/components/failedbookingsbyfield....
Learnt from: eunjae-lee
PR: calcom/cal.com#22106
File: packages/features/insights/components/FailedBookingsByField.tsx:65-71
Timestamp: 2025-07-15T12:59:34.389Z
Learning: In the FailedBookingsByField component (packages/features/insights/components/FailedBookingsByField.tsx), although routingFormId is typed as optional in useInsightsParameters, the system automatically enforces a routing form filter, so routingFormId is always present in practice. This means the data always contains only one entry, making the single-entry destructuring approach safe.

Applied to files:

  • packages/features/insights/hooks/useInsightsBookingFacetedUniqueValues.ts
  • packages/features/insights/server/trpc-router.ts
  • packages/features/insights/hooks/useInsightsRoutingFacetedUniqueValues.ts
  • packages/features/insights/components/routing/RoutingFormResponsesTable.tsx
  • packages/lib/server/service/insightsBooking.ts
  • packages/features/insights/hooks/useInsightsBookingParameters.ts
  • packages/features/insights/server/raw-data.schema.ts
  • packages/features/insights/hooks/useInsightsBookings.ts
📚 Learning: in the insightsroutingservice (packages/lib/server/service/insightsrouting.ts), multi-select filter ...
Learnt from: eunjae-lee
PR: calcom/cal.com#22106
File: packages/lib/server/service/insightsRouting.ts:367-368
Timestamp: 2025-07-15T13:02:17.403Z
Learning: In the InsightsRoutingService (packages/lib/server/service/insightsRouting.ts), multi-select filter data is already validated by zod before reaching the buildFormFieldSqlCondition method, so null/undefined values are not present in filterValue.data arrays and don't need to be filtered out.

Applied to files:

  • packages/features/insights/hooks/useInsightsBookingFacetedUniqueValues.ts
  • packages/features/insights/server/trpc-router.ts
  • packages/features/insights/hooks/useInsightsRoutingFacetedUniqueValues.ts
  • packages/features/insights/components/routing/RoutingFormResponsesTable.tsx
  • packages/lib/server/service/insightsBooking.ts
  • packages/features/insights/hooks/useInsightsBookingParameters.ts
  • packages/features/insights/server/raw-data.schema.ts
  • packages/features/insights/hooks/useInsightsBookings.ts
📚 Learning: in the insightsbookingservice (packages/lib/server/service/insightsbooking.ts), the constructor stor...
Learnt from: eunjae-lee
PR: calcom/cal.com#22702
File: packages/lib/server/service/insightsBooking.ts:120-124
Timestamp: 2025-07-24T08:39:06.185Z
Learning: In the InsightsBookingService (packages/lib/server/service/insightsBooking.ts), the constructor stores null for invalid options or filters but this is handled safely through null checks in buildFilterConditions() and buildAuthorizationConditions() methods. The service uses defensive programming to return safe fallback conditions (null or NOTHING_CONDITION) rather than throwing errors on invalid inputs.

Applied to files:

  • packages/features/insights/server/trpc-router.ts
  • packages/lib/server/service/insightsBooking.ts
  • packages/features/insights/hooks/useInsightsBookingParameters.ts
  • packages/features/insights/server/raw-data.schema.ts
  • packages/features/insights/hooks/useInsightsBookings.ts
📚 Learning: the filterhostsbysameroundrobinhost function in packages/lib/bookings/filterhostsbysameroundrobinhos...
Learnt from: CarinaWolli
PR: calcom/cal.com#22296
File: packages/lib/bookings/filterHostsBySameRoundRobinHost.ts:41-42
Timestamp: 2025-07-22T11:42:47.623Z
Learning: The filterHostsBySameRoundRobinHost function in packages/lib/bookings/filterHostsBySameRoundRobinHost.ts has a known limitation where it doesn't work correctly with fixed hosts or round robin groups. This is pre-existing technical debt that was already broken before the round robin groups feature. CarinaWolli has documented this in Linear issue CAL-6134 for future fix.

Applied to files:

  • packages/features/insights/server/trpc-router.ts
📚 Learning: applies to **/*.{ts,tsx} : flag excessive day.js use in performance-critical code; prefer native dat...
Learnt from: CR
PR: calcom/cal.com#0
File: .cursor/rules/review.mdc:0-0
Timestamp: 2025-07-28T11:50:23.946Z
Learning: Applies to **/*.{ts,tsx} : Flag excessive Day.js use in performance-critical code; prefer native Date or Day.js `.utc()` in hot paths like loops

Applied to files:

  • packages/lib/server/service/insightsBooking.ts
  • packages/features/insights/hooks/useInsightsBookingParameters.ts
📚 Learning: applies to **/*.ts : for prisma queries, only select data you need; never use `include`, always use ...
Learnt from: CR
PR: calcom/cal.com#0
File: .cursor/rules/review.mdc:0-0
Timestamp: 2025-07-28T11:50:23.946Z
Learning: Applies to **/*.ts : For Prisma queries, only select data you need; never use `include`, always use `select`

Applied to files:

  • packages/lib/server/service/insightsBooking.ts
📚 Learning: when making localization changes for new features, it's often safer to add new strings rather than m...
Learnt from: bandhan-majumder
PR: calcom/cal.com#22359
File: packages/lib/server/locales/en/common.json:1336-1339
Timestamp: 2025-07-14T16:31:45.233Z
Learning: When making localization changes for new features, it's often safer to add new strings rather than modify existing ones to avoid breaking existing functionality that depends on the original strings. This approach allows for feature-specific customization while maintaining backward compatibility.

Applied to files:

  • apps/web/public/static/locales/en/common.json
🧬 Code Graph Analysis (6)
packages/features/insights/hooks/useInsightsBookingFacetedUniqueValues.ts (2)
packages/features/data-table/lib/types.ts (1)
  • FacetedValue (220-224)
packages/features/data-table/lib/utils.ts (1)
  • convertFacetedValuesToMap (150-154)
packages/features/insights/components/routing/RoutingFormResponsesTable.tsx (1)
packages/features/insights/hooks/useInsightsRoutingFacetedUniqueValues.ts (1)
  • useInsightsRoutingFacetedUniqueValues (19-111)
packages/lib/server/service/insightsBooking.ts (2)
packages/features/data-table/lib/types.ts (2)
  • ZColumnFilter (172-175)
  • ColumnFilter (167-170)
packages/features/data-table/lib/utils.ts (2)
  • isSingleSelectFilterValue (86-88)
  • isMultiSelectFilterValue (78-80)
packages/features/insights/hooks/useInsightsBookingParameters.ts (1)
packages/lib/timezoneConstants.ts (1)
  • CURRENT_TIMEZONE (4-4)
packages/features/insights/server/raw-data.schema.ts (1)
packages/features/data-table/lib/types.ts (1)
  • ZColumnFilter (172-175)
packages/features/insights/hooks/useInsightsBookings.ts (2)
packages/features/insights/hooks/useInsightsOrgTeams.ts (1)
  • useInsightsOrgTeams (6-32)
packages/features/insights/hooks/useInsightsBookingFacetedUniqueValues.ts (1)
  • useInsightsBookingFacetedUniqueValues (18-76)
🔇 Additional comments (16)
packages/features/insights/hooks/useInsightsRoutingFacetedUniqueValues.ts (1)

19-19: LGTM: Good naming specialization.

The renaming from useInsightsFacetedUniqueValues to useInsightsRoutingFacetedUniqueValues improves code clarity by making it explicit that this hook is specific to routing insights functionality.

packages/features/insights/hooks/useInsightsBookingParameters.ts (1)

36-44: LGTM: Successful refactor to unified column filters.

The replacement of individual filter extractions (memberUserId, eventTypeId) with the unified columnFilters approach aligns well with the PR's objective to consolidate filtering logic. The exclusion of "createdAt" is appropriate since it's handled separately with specialized date range logic.

packages/features/insights/components/routing/RoutingFormResponsesTable.tsx (2)

25-25: LGTM: Import updated consistently with hook renaming.

The import change aligns with the renaming of useInsightsFacetedUniqueValues to useInsightsRoutingFacetedUniqueValues, maintaining consistency across the codebase.


52-57: LGTM: Hook usage updated correctly.

The instantiation correctly uses the renamed useInsightsRoutingFacetedUniqueValues hook with the same parameters, ensuring no functional changes while maintaining the specialized naming convention.

packages/features/insights/server/raw-data.schema.ts (1)

79-79: LGTM: Schema updated to support unified column filtering.

The addition of the optional columnFilters field using z.array(ZColumnFilter) properly supports the refactor from individual filter fields to a unified filtering approach. This change aligns well with the corresponding updates in the client-side hooks and server-side processing logic.

packages/features/insights/hooks/useInsightsBookings.ts (3)

11-15: LGTM: Type definition updated to support booking status filtering.

The DummyTableRow type changes appropriately support the new filtering capabilities:

  • bookingUserIduserId provides clearer naming
  • Addition of status: BookingStatus directly enables the booking status filter feature requested in the PR

23-27: LGTM: Specialized hook usage aligns with the feature-specific pattern.

The switch to useInsightsBookingFacetedUniqueValues follows the established pattern of using specialized hooks for different insights features (booking vs routing), improving code organization and maintainability.


32-70: LGTM: Column configuration directly addresses PR objectives.

The new column structure effectively implements the booking status filter functionality:

  • eventTypeId (SINGLE_SELECT): Enables filtering by event type
  • status (MULTI_SELECT): Directly addresses the PR objective by allowing users to filter by multiple booking statuses
  • userId (SINGLE_SELECT): Provides member-based filtering

The filter types are appropriately chosen for each column's use case, and the disabled sorting with enabled filtering confirms this is designed as a filter-only interface.

packages/features/insights/server/trpc-router.ts (1)

323-323: LGTM! Clean refactoring to unified column filtering.

The change correctly extracts columnFilters from the input and passes it to the service constructor, replacing the previous individual filter fields. This aligns well with the broader refactoring to use a generic column filtering approach.

Also applies to: 334-334

packages/features/insights/hooks/useInsightsBookingFacetedUniqueValues.ts (3)

1-17: LGTM! Well-organized imports and status ordering.

The imports are properly structured and the statusOrder object provides a logical hierarchy for booking statuses.


18-46: LGTM! Proper TRPC query setup.

The hook parameters are well-defined and the TRPC queries are correctly configured with appropriate performance optimizations.


48-75: LGTM! Comprehensive faceted value mapping.

The callback correctly handles all three supported column types with proper fallbacks and localized labels. The memoization is appropriately configured with the right dependencies.

packages/lib/server/service/insightsBooking.ts (4)

6-8: LGTM! Required imports for column filtering.

The new imports provide the necessary types and utility functions for the column filter refactoring.


118-118: LGTM! Schema correctly updated for unified column filtering.

The change from individual filter fields to a generic columnFilters array properly centralizes filter handling with appropriate validation.


243-251: LGTM! Clean refactoring to process column filters.

The iteration over columnFilters with proper null checking maintains the defensive programming approach while enabling flexible column-based filtering.


281-302: LGTM! Robust column filter condition builder.

The method properly handles all three supported filter types with appropriate type checking and defensive programming. The eventTypeId logic correctly accounts for parent/child relationships, and the status filter safely handles multi-select values.

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 (2)
packages/features/insights/components/routing/RoutingFormResponsesTable.tsx (1)

25-25: Import updated to use renamed hook.

The import correctly references the renamed useInsightsRoutingFacetedUniqueValues hook.

packages/features/insights/hooks/useInsightsBookingParameters.ts (1)

36-36: Column filters implementation aligns with the refactoring goal.

The use of useColumnFilters({ exclude: ["createdAt"] }) correctly implements the new filtering approach while appropriately excluding the date filter that's handled separately.

🧹 Nitpick comments (1)
apps/web/public/static/locales/en/common.json (1)

3432-3432: Capitalize second word for label consistency

Most single-label strings (e.g. “Team Info”, “Booking Appearance”, “Event Setup”) use Title Case. Consider changing the value from "Booking status" to "Booking Status" to match the prevailing UI copy style.

-  "booking_status": "Booking status",
+  "booking_status": "Booking Status",
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2cc7827 and b8d70f3.

📒 Files selected for processing (9)
  • apps/web/public/static/locales/en/common.json (1 hunks)
  • packages/features/insights/components/routing/RoutingFormResponsesTable.tsx (2 hunks)
  • packages/features/insights/hooks/useInsightsBookingFacetedUniqueValues.ts (1 hunks)
  • packages/features/insights/hooks/useInsightsBookingParameters.ts (2 hunks)
  • packages/features/insights/hooks/useInsightsBookings.ts (2 hunks)
  • packages/features/insights/hooks/useInsightsRoutingFacetedUniqueValues.ts (1 hunks)
  • packages/features/insights/server/raw-data.schema.ts (1 hunks)
  • packages/features/insights/server/trpc-router.ts (2 hunks)
  • packages/lib/server/service/insightsBooking.ts (4 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.ts

📄 CodeRabbit Inference Engine (.cursor/rules/review.mdc)

**/*.ts: For Prisma queries, only select data you need; never use include, always use select
Ensure the credential.key field is never returned from tRPC endpoints or APIs

Files:

  • packages/features/insights/hooks/useInsightsBookingParameters.ts
  • packages/lib/server/service/insightsBooking.ts
  • packages/features/insights/hooks/useInsightsBookings.ts
  • packages/features/insights/server/trpc-router.ts
  • packages/features/insights/server/raw-data.schema.ts
  • packages/features/insights/hooks/useInsightsBookingFacetedUniqueValues.ts
  • packages/features/insights/hooks/useInsightsRoutingFacetedUniqueValues.ts
**/*.{ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/review.mdc)

Flag excessive Day.js use in performance-critical code; prefer native Date or Day.js .utc() in hot paths like loops

Files:

  • packages/features/insights/hooks/useInsightsBookingParameters.ts
  • packages/features/insights/components/routing/RoutingFormResponsesTable.tsx
  • packages/lib/server/service/insightsBooking.ts
  • packages/features/insights/hooks/useInsightsBookings.ts
  • packages/features/insights/server/trpc-router.ts
  • packages/features/insights/server/raw-data.schema.ts
  • packages/features/insights/hooks/useInsightsBookingFacetedUniqueValues.ts
  • packages/features/insights/hooks/useInsightsRoutingFacetedUniqueValues.ts
**/*.tsx

📄 CodeRabbit Inference Engine (.cursor/rules/review.mdc)

Always use t() for text localization in frontend code; direct text embedding should trigger a warning

Files:

  • packages/features/insights/components/routing/RoutingFormResponsesTable.tsx
🧠 Learnings (8)
📓 Common learnings
Learnt from: eunjae-lee
PR: calcom/cal.com#22106
File: packages/features/insights/components/RoutingFunnel.tsx:15-17
Timestamp: 2025-07-15T12:58:40.539Z
Learning: In the insights routing funnel component (packages/features/insights/components/RoutingFunnel.tsx), the useColumnFilters exclusions are intentionally different from the general useInsightsParameters exclusions. RoutingFunnel specifically excludes only ["createdAt"] while useInsightsParameters excludes ["bookingUserId", "formId", "createdAt", "eventTypeId"]. This difference is by design.
Learnt from: eunjae-lee
PR: calcom/cal.com#22702
File: packages/lib/server/service/insightsBooking.ts:120-124
Timestamp: 2025-07-24T08:39:06.185Z
Learning: In the InsightsBookingService (packages/lib/server/service/insightsBooking.ts), the constructor stores null for invalid options or filters but this is handled safely through null checks in buildFilterConditions() and buildAuthorizationConditions() methods. The service uses defensive programming to return safe fallback conditions (null or NOTHING_CONDITION) rather than throwing errors on invalid inputs.
Learnt from: eunjae-lee
PR: calcom/cal.com#22106
File: packages/features/insights/components/FailedBookingsByField.tsx:65-71
Timestamp: 2025-07-15T12:59:34.389Z
Learning: In the FailedBookingsByField component (packages/features/insights/components/FailedBookingsByField.tsx), although routingFormId is typed as optional in useInsightsParameters, the system automatically enforces a routing form filter, so routingFormId is always present in practice. This means the data always contains only one entry, making the single-entry destructuring approach safe.
Learnt from: eunjae-lee
PR: calcom/cal.com#22106
File: packages/lib/server/service/insightsRouting.ts:367-368
Timestamp: 2025-07-15T13:02:17.403Z
Learning: In the InsightsRoutingService (packages/lib/server/service/insightsRouting.ts), multi-select filter data is already validated by zod before reaching the buildFormFieldSqlCondition method, so null/undefined values are not present in filterValue.data arrays and don't need to be filtered out.
📚 Learning: in the insights routing funnel component (packages/features/insights/components/routingfunnel.tsx), ...
Learnt from: eunjae-lee
PR: calcom/cal.com#22106
File: packages/features/insights/components/RoutingFunnel.tsx:15-17
Timestamp: 2025-07-15T12:58:40.539Z
Learning: In the insights routing funnel component (packages/features/insights/components/RoutingFunnel.tsx), the useColumnFilters exclusions are intentionally different from the general useInsightsParameters exclusions. RoutingFunnel specifically excludes only ["createdAt"] while useInsightsParameters excludes ["bookingUserId", "formId", "createdAt", "eventTypeId"]. This difference is by design.

Applied to files:

  • packages/features/insights/hooks/useInsightsBookingParameters.ts
  • packages/features/insights/components/routing/RoutingFormResponsesTable.tsx
  • packages/lib/server/service/insightsBooking.ts
  • packages/features/insights/hooks/useInsightsBookings.ts
  • packages/features/insights/server/trpc-router.ts
  • packages/features/insights/server/raw-data.schema.ts
  • packages/features/insights/hooks/useInsightsBookingFacetedUniqueValues.ts
  • packages/features/insights/hooks/useInsightsRoutingFacetedUniqueValues.ts
📚 Learning: in the failedbookingsbyfield component (packages/features/insights/components/failedbookingsbyfield....
Learnt from: eunjae-lee
PR: calcom/cal.com#22106
File: packages/features/insights/components/FailedBookingsByField.tsx:65-71
Timestamp: 2025-07-15T12:59:34.389Z
Learning: In the FailedBookingsByField component (packages/features/insights/components/FailedBookingsByField.tsx), although routingFormId is typed as optional in useInsightsParameters, the system automatically enforces a routing form filter, so routingFormId is always present in practice. This means the data always contains only one entry, making the single-entry destructuring approach safe.

Applied to files:

  • packages/features/insights/hooks/useInsightsBookingParameters.ts
  • packages/features/insights/components/routing/RoutingFormResponsesTable.tsx
  • packages/lib/server/service/insightsBooking.ts
  • packages/features/insights/hooks/useInsightsBookings.ts
  • packages/features/insights/server/trpc-router.ts
  • packages/features/insights/server/raw-data.schema.ts
  • packages/features/insights/hooks/useInsightsBookingFacetedUniqueValues.ts
  • packages/features/insights/hooks/useInsightsRoutingFacetedUniqueValues.ts
📚 Learning: in the insightsroutingservice (packages/lib/server/service/insightsrouting.ts), multi-select filter ...
Learnt from: eunjae-lee
PR: calcom/cal.com#22106
File: packages/lib/server/service/insightsRouting.ts:367-368
Timestamp: 2025-07-15T13:02:17.403Z
Learning: In the InsightsRoutingService (packages/lib/server/service/insightsRouting.ts), multi-select filter data is already validated by zod before reaching the buildFormFieldSqlCondition method, so null/undefined values are not present in filterValue.data arrays and don't need to be filtered out.

Applied to files:

  • packages/features/insights/hooks/useInsightsBookingParameters.ts
  • packages/features/insights/components/routing/RoutingFormResponsesTable.tsx
  • packages/lib/server/service/insightsBooking.ts
  • packages/features/insights/hooks/useInsightsBookings.ts
  • packages/features/insights/server/trpc-router.ts
  • packages/features/insights/server/raw-data.schema.ts
  • packages/features/insights/hooks/useInsightsBookingFacetedUniqueValues.ts
  • packages/features/insights/hooks/useInsightsRoutingFacetedUniqueValues.ts
📚 Learning: in the insightsbookingservice (packages/lib/server/service/insightsbooking.ts), the constructor stor...
Learnt from: eunjae-lee
PR: calcom/cal.com#22702
File: packages/lib/server/service/insightsBooking.ts:120-124
Timestamp: 2025-07-24T08:39:06.185Z
Learning: In the InsightsBookingService (packages/lib/server/service/insightsBooking.ts), the constructor stores null for invalid options or filters but this is handled safely through null checks in buildFilterConditions() and buildAuthorizationConditions() methods. The service uses defensive programming to return safe fallback conditions (null or NOTHING_CONDITION) rather than throwing errors on invalid inputs.

Applied to files:

  • packages/features/insights/hooks/useInsightsBookingParameters.ts
  • packages/lib/server/service/insightsBooking.ts
  • packages/features/insights/hooks/useInsightsBookings.ts
  • packages/features/insights/server/trpc-router.ts
  • packages/features/insights/server/raw-data.schema.ts
📚 Learning: applies to **/*.{ts,tsx} : flag excessive day.js use in performance-critical code; prefer native dat...
Learnt from: CR
PR: calcom/cal.com#0
File: .cursor/rules/review.mdc:0-0
Timestamp: 2025-07-28T11:50:23.946Z
Learning: Applies to **/*.{ts,tsx} : Flag excessive Day.js use in performance-critical code; prefer native Date or Day.js `.utc()` in hot paths like loops

Applied to files:

  • packages/features/insights/hooks/useInsightsBookingParameters.ts
  • packages/lib/server/service/insightsBooking.ts
📚 Learning: applies to **/*.ts : for prisma queries, only select data you need; never use `include`, always use ...
Learnt from: CR
PR: calcom/cal.com#0
File: .cursor/rules/review.mdc:0-0
Timestamp: 2025-07-28T11:50:23.946Z
Learning: Applies to **/*.ts : For Prisma queries, only select data you need; never use `include`, always use `select`

Applied to files:

  • packages/lib/server/service/insightsBooking.ts
📚 Learning: when making localization changes for new features, it's often safer to add new strings rather than m...
Learnt from: bandhan-majumder
PR: calcom/cal.com#22359
File: packages/lib/server/locales/en/common.json:1336-1339
Timestamp: 2025-07-14T16:31:45.233Z
Learning: When making localization changes for new features, it's often safer to add new strings rather than modify existing ones to avoid breaking existing functionality that depends on the original strings. This approach allows for feature-specific customization while maintaining backward compatibility.

Applied to files:

  • apps/web/public/static/locales/en/common.json
🧬 Code Graph Analysis (5)
packages/features/insights/hooks/useInsightsBookingParameters.ts (1)
packages/lib/timezoneConstants.ts (1)
  • CURRENT_TIMEZONE (4-4)
packages/features/insights/components/routing/RoutingFormResponsesTable.tsx (1)
packages/features/insights/hooks/useInsightsRoutingFacetedUniqueValues.ts (1)
  • useInsightsRoutingFacetedUniqueValues (19-111)
packages/lib/server/service/insightsBooking.ts (2)
packages/features/data-table/lib/types.ts (2)
  • ZColumnFilter (172-175)
  • ColumnFilter (167-170)
packages/features/data-table/lib/utils.ts (2)
  • isSingleSelectFilterValue (86-88)
  • isMultiSelectFilterValue (78-80)
packages/features/insights/server/raw-data.schema.ts (1)
packages/features/data-table/lib/types.ts (1)
  • ZColumnFilter (172-175)
packages/features/insights/hooks/useInsightsBookingFacetedUniqueValues.ts (2)
packages/features/data-table/lib/types.ts (1)
  • FacetedValue (220-224)
packages/features/data-table/lib/utils.ts (1)
  • convertFacetedValuesToMap (150-154)
🔇 Additional comments (18)
packages/features/insights/hooks/useInsightsRoutingFacetedUniqueValues.ts (1)

19-19: LGTM! Clean rename to align with domain separation.

The rename from useInsightsFacetedUniqueValues to useInsightsRoutingFacetedUniqueValues improves code organization by making the hook's routing-specific purpose clear.

packages/features/insights/components/routing/RoutingFormResponsesTable.tsx (1)

52-57: Hook usage updated consistently.

The hook instantiation properly uses the renamed useInsightsRoutingFacetedUniqueValues with the same parameters as before.

packages/features/insights/server/raw-data.schema.ts (1)

79-79: LGTM! Schema updated to support generalized column filtering.

The addition of the optional columnFilters field using z.array(ZColumnFilter) aligns perfectly with the refactoring to replace individual filter fields with a flexible column filters mechanism.

packages/features/insights/hooks/useInsightsBookingParameters.ts (2)

4-6: Import updates support the new filtering approach.

The addition of ZDateRangeFilterValue and useColumnFilters imports, along with the existing useFilterValue import, properly supports the transition to the column filters mechanism.


44-44: Return value updated to provide columnFilters.

The return of columnFilters instead of individual filter fields supports the server-side processing of generic column filters.

packages/features/insights/server/trpc-router.ts (2)

323-323: Destructuring updated to use columnFilters.

The function correctly destructures columnFilters from the input instead of individual filter fields, aligning with the new filtering architecture.


334-334: Filters object updated to use columnFilters conditionally.

The conditional inclusion of columnFilters using the spread operator is appropriate and maintains compatibility while supporting the new filtering approach.

packages/features/insights/hooks/useInsightsBookingFacetedUniqueValues.ts (4)

1-16: LGTM!

The imports are well-organized and the status ordering makes logical sense with accepted bookings having the highest priority.


18-46: LGTM!

The hook signature is well-typed and the tRPC queries are configured appropriately with performance optimizations.


74-76: LGTM!

The useCallback dependencies are correctly specified to include only the data sources that affect the callback output.


48-73: Verify status filter case consistency

The UI generates status filter values in lowercase (e.g. "accepted"), but the backend’s SQL condition casts them directly to the BookingStatus enum (Prisma.sql\${status}::"BookingStatus"``). Please confirm that casting lowercase strings to the enum works as expected, or adjust one side to match case.

• Frontend:
‑ packages/features/insights/hooks/useInsightsBookingFacetedUniqueValues.ts (Line 53)
‑ uses status.toLowerCase() for the filter value

• Backend:
‑ packages/lib/server/service/insightsBooking.ts (buildFilterConditions for id === "status")
‑ maps value.data directly via Prisma.sql\${status}::"BookingStatus"``

packages/features/insights/hooks/useInsightsBookings.ts (3)

6-6: LGTM!

The import updates and type changes properly align with the new column-based filtering approach and booking-specific faceted values.

Also applies to: 8-8, 12-15


23-27: LGTM!

The hook replacement maintains the same parameter interface while providing booking-specific faceted values.


32-69: LGTM!

The column definitions are well-structured with appropriate filter types (single-select for eventTypeId and userId, multi-select for status) and consistent configuration. The translation keys and sizing are properly set.

packages/lib/server/service/insightsBooking.ts (4)

6-8: LGTM!

The new imports provide the necessary types and utilities for type-safe column filtering.


118-118: LGTM!

The schema update to use a columnFilters array provides a more flexible and extensible filtering approach.


243-251: LGTM!

The refactored filtering approach is more flexible and allows for multiple column filters to be processed consistently.


281-302: Status value format consistency confirmed.

Prisma’s BookingStatus enum is mapped to lowercase values ("cancelled", "accepted", "rejected", "pending", "awaiting_host"), matching the frontend’s status.toLowerCase() facet values. Casting these lowercase strings to ::"BookingStatus" in your SQL filter is safe and will work as intended.

emrysal
emrysal previously approved these changes Aug 1, 2025
Copy link
Contributor

@emrysal emrysal left a comment

Choose a reason for hiding this comment

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

Looks good, lgtm

@github-actions
Copy link
Contributor

github-actions bot commented Aug 1, 2025

E2E results are ready!

@hbjORbj
Copy link
Contributor

hbjORbj commented Aug 4, 2025

@eunjae-lee Integration test failing here for some reason: https://github.com/calcom/cal.com/actions/runs/16678246253/job/47211368305?pr=22842

Copy link
Contributor

@hbjORbj hbjORbj left a comment

Choose a reason for hiding this comment

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

LGTM!

@emrysal emrysal merged commit a2205d4 into main Aug 4, 2025
62 of 64 checks passed
@emrysal emrysal deleted the eunjae/cal-5448-allow-filtering-all-columns branch August 4, 2025 13:48
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 ✨ feature New feature or request insights area: insights, analytics ready-for-e2e

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants