feat: add booking status filter to /insights#22842
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎ |
WalkthroughThis set of changes refactors the filtering mechanism for booking insights in the application. It introduces a new hook ( Estimated code review effort🎯 3 (Moderate) | ⏱️ ~15–20 minutes Assessment against linked issues
Assessment against linked issues: Out-of-scope changesNo 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 detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ 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)
✨ 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. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
| userId, | ||
| teamId, | ||
| isAll, | ||
| }); |
There was a problem hiding this comment.
just renaming useInsightsFacetedUniqueValues to useInsightsRoutingFacetedUniqueValues.
| @@ -0,0 +1,76 @@ | |||
| import type { Table } from "@tanstack/react-table"; | |||
There was a problem hiding this comment.
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"] }); | ||
|
|
There was a problem hiding this comment.
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", { |
There was a problem hiding this comment.
adding "status" (booking status) column
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. |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
apps/web/public/static/locales/en/common.json (1)
3432-3432: Align label capitalisation with existing stringsMost 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
📒 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 useinclude, always useselect
Ensure thecredential.keyfield is never returned from tRPC endpoints or APIs
Files:
packages/features/insights/hooks/useInsightsBookingFacetedUniqueValues.tspackages/features/insights/server/trpc-router.tspackages/features/insights/hooks/useInsightsRoutingFacetedUniqueValues.tspackages/lib/server/service/insightsBooking.tspackages/features/insights/hooks/useInsightsBookingParameters.tspackages/features/insights/server/raw-data.schema.tspackages/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.tspackages/features/insights/server/trpc-router.tspackages/features/insights/hooks/useInsightsRoutingFacetedUniqueValues.tspackages/features/insights/components/routing/RoutingFormResponsesTable.tsxpackages/lib/server/service/insightsBooking.tspackages/features/insights/hooks/useInsightsBookingParameters.tspackages/features/insights/server/raw-data.schema.tspackages/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.tspackages/features/insights/server/trpc-router.tspackages/features/insights/hooks/useInsightsRoutingFacetedUniqueValues.tspackages/features/insights/components/routing/RoutingFormResponsesTable.tsxpackages/lib/server/service/insightsBooking.tspackages/features/insights/hooks/useInsightsBookingParameters.tspackages/features/insights/server/raw-data.schema.tspackages/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.tspackages/features/insights/server/trpc-router.tspackages/features/insights/hooks/useInsightsRoutingFacetedUniqueValues.tspackages/features/insights/components/routing/RoutingFormResponsesTable.tsxpackages/lib/server/service/insightsBooking.tspackages/features/insights/hooks/useInsightsBookingParameters.tspackages/features/insights/server/raw-data.schema.tspackages/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.tspackages/features/insights/server/trpc-router.tspackages/features/insights/hooks/useInsightsRoutingFacetedUniqueValues.tspackages/features/insights/components/routing/RoutingFormResponsesTable.tsxpackages/lib/server/service/insightsBooking.tspackages/features/insights/hooks/useInsightsBookingParameters.tspackages/features/insights/server/raw-data.schema.tspackages/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.tspackages/lib/server/service/insightsBooking.tspackages/features/insights/hooks/useInsightsBookingParameters.tspackages/features/insights/server/raw-data.schema.tspackages/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.tspackages/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
useInsightsFacetedUniqueValuestouseInsightsRoutingFacetedUniqueValuesimproves 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 unifiedcolumnFiltersapproach 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
useInsightsFacetedUniqueValuestouseInsightsRoutingFacetedUniqueValues, maintaining consistency across the codebase.
52-57: LGTM: Hook usage updated correctly.The instantiation correctly uses the renamed
useInsightsRoutingFacetedUniqueValueshook 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
columnFiltersfield usingz.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
DummyTableRowtype changes appropriately support the new filtering capabilities:
bookingUserId→userIdprovides clearer naming- Addition of
status: BookingStatusdirectly 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
useInsightsBookingFacetedUniqueValuesfollows 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
columnFiltersfrom 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
statusOrderobject 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
columnFiltersarray properly centralizes filter handling with appropriate validation.
243-251: LGTM! Clean refactoring to process column filters.The iteration over
columnFilterswith 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.
There was a problem hiding this comment.
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
useInsightsRoutingFacetedUniqueValueshook.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 consistencyMost 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
📒 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 useinclude, always useselect
Ensure thecredential.keyfield is never returned from tRPC endpoints or APIs
Files:
packages/features/insights/hooks/useInsightsBookingParameters.tspackages/lib/server/service/insightsBooking.tspackages/features/insights/hooks/useInsightsBookings.tspackages/features/insights/server/trpc-router.tspackages/features/insights/server/raw-data.schema.tspackages/features/insights/hooks/useInsightsBookingFacetedUniqueValues.tspackages/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.tspackages/features/insights/components/routing/RoutingFormResponsesTable.tsxpackages/lib/server/service/insightsBooking.tspackages/features/insights/hooks/useInsightsBookings.tspackages/features/insights/server/trpc-router.tspackages/features/insights/server/raw-data.schema.tspackages/features/insights/hooks/useInsightsBookingFacetedUniqueValues.tspackages/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.tspackages/features/insights/components/routing/RoutingFormResponsesTable.tsxpackages/lib/server/service/insightsBooking.tspackages/features/insights/hooks/useInsightsBookings.tspackages/features/insights/server/trpc-router.tspackages/features/insights/server/raw-data.schema.tspackages/features/insights/hooks/useInsightsBookingFacetedUniqueValues.tspackages/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.tspackages/features/insights/components/routing/RoutingFormResponsesTable.tsxpackages/lib/server/service/insightsBooking.tspackages/features/insights/hooks/useInsightsBookings.tspackages/features/insights/server/trpc-router.tspackages/features/insights/server/raw-data.schema.tspackages/features/insights/hooks/useInsightsBookingFacetedUniqueValues.tspackages/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.tspackages/features/insights/components/routing/RoutingFormResponsesTable.tsxpackages/lib/server/service/insightsBooking.tspackages/features/insights/hooks/useInsightsBookings.tspackages/features/insights/server/trpc-router.tspackages/features/insights/server/raw-data.schema.tspackages/features/insights/hooks/useInsightsBookingFacetedUniqueValues.tspackages/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.tspackages/lib/server/service/insightsBooking.tspackages/features/insights/hooks/useInsightsBookings.tspackages/features/insights/server/trpc-router.tspackages/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.tspackages/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
useInsightsFacetedUniqueValuestouseInsightsRoutingFacetedUniqueValuesimproves 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
useInsightsRoutingFacetedUniqueValueswith 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
columnFiltersfield usingz.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
ZDateRangeFilterValueanduseColumnFiltersimports, along with the existinguseFilterValueimport, properly supports the transition to the column filters mechanism.
44-44: Return value updated to provide columnFilters.The return of
columnFiltersinstead 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
columnFiltersfrom 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
columnFiltersusing 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 consistencyThe UI generates status filter values in lowercase (e.g.
"accepted"), but the backend’s SQL condition casts them directly to theBookingStatusenum (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)
‑ usesstatus.toLowerCase()for the filter value• Backend:
‑ packages/lib/server/service/insightsBooking.ts (buildFilterConditions forid === "status")
‑ mapsvalue.datadirectly viaPrisma.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
BookingStatusenum is mapped to lowercase values ("cancelled","accepted","rejected","pending","awaiting_host"), matching the frontend’sstatus.toLowerCase()facet values. Casting these lowercase strings to::"BookingStatus"in your SQL filter is safe and will work as intended.
E2E results are ready! |
|
@eunjae-lee Integration test failing here for some reason: https://github.com/calcom/cal.com/actions/runs/16678246253/job/47211368305?pr=22842 |
What does this PR do?
This PR adds "booking status" filter to the /insights page (including a bit of refactoring)
Visual Demo (For contributors especially)
Mandatory Tasks (DO NOT REMOVE)
How should this be tested?
Visit /insights and try the "Booking status" filter