feat(bookings): add sort by booking creation date#29651
Conversation
Adds a tab-independent Sort control (Newest first / Oldest first / Default) to the bookings list, ordering by createdAt. Exposes sortCreated on the bookings query input; the handler's getOrderBy already maps it to createdAt ordering. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Welcome to Cal.diy, @karimqpn! Thanks for opening this pull request. A few things to keep in mind:
A maintainer will review your PR soon. Thanks for contributing! |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe booking list now supports sorting by booking creation date. The bookings input schema accepts an optional 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
apps/web/modules/bookings/components/BookingListContainer.tsx (1)
310-345: 🎯 Functional Correctness | 🟡 MinorSorting changes do not reset pagination offset
When a user changes the sort order while on a paginated page, the
offsetremains stale. This can result in an empty or misaligned page until the user manually navigates. TheonSortCreatedChangehandler (line 377) only updates the sort state without resetting the page index.Wrap the
setSortCreatedhandler to reset the page index when sort changes:Code Location
export function BookingListContainer(props: BookingListContainerProps) { const { limit, offset, setPageIndex, isValidatorPending } = useDataTable(); const { eventTypeIds, teamIds, userIds, dateRange, attendeeName, attendeeEmail, bookingUid } = useBookingFilters(); const [sortCreated, setSortCreated] = useState<SortCreatedOrder>(undefined); + const handleSortChange = useCallback((value: SortCreatedOrder) => { + setPageIndex(0); + setSortCreated(value); + }, [setPageIndex, setSortCreated]); + const queryInput = useMemo( () => ({ limit, offset, filters: { statuses: [props.status], eventTypeIds, teamIds, userIds, attendeeName, attendeeEmail, bookingUid, afterStartDate: dateRange?.startDate ? dayjs(dateRange?.startDate).startOf("day").toISOString() : undefined, beforeEndDate: dateRange?.endDate ? dayjs(dateRange?.endDate).endOf("day").toISOString() : undefined, }, sort: sortCreated ? { sortCreated } : undefined, }), [ limit, offset, props.status, eventTypeIds, teamIds, userIds, attendeeName, attendeeEmail, bookingUid, dateRange, sortCreated, ] ); // ... inside return ... - onSortCreatedChange={setSortCreated} + onSortCreatedChange={handleSortChange}🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/web/modules/bookings/components/BookingListContainer.tsx` around lines 310 - 345, The sort change flow in BookingListContainer keeps the current pagination offset, which can leave the user on a stale page after changing order. Update the sort handler used by onSortCreatedChange to also reset the page index/offset whenever setSortCreated is called, so queryInput is rebuilt from the first page after a sort change and pagination stays aligned.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@apps/web/modules/bookings/components/BookingListContainer.tsx`:
- Around line 310-345: The sort change flow in BookingListContainer keeps the
current pagination offset, which can leave the user on a stale page after
changing order. Update the sort handler used by onSortCreatedChange to also
reset the page index/offset whenever setSortCreated is called, so queryInput is
rebuilt from the first page after a sort change and pagination stays aligned.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 9cedabce-4329-4a29-9faf-1b9c25848395
📒 Files selected for processing (3)
apps/web/modules/bookings/components/BookingListContainer.tsxpackages/i18n/locales/en/common.jsonpackages/trpc/server/routers/viewer/bookings/get.schema.ts
Addresses CodeRabbit review on calcom#29651: changing the sort while on a paginated page kept a stale offset, which could land on an empty page. The sort handler now resets the page index before updating sort state. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Thanks @coderabbitai — good catch. Fixed in cfba8ba: |
|
Tip For best results, initiate chat on the files or code changes.
If you found this review helpful, would you consider giving us a shout-out on X? Thank you for using CodeRabbit! |
What
Adds a tab-independent Sort control (Newest first / Oldest first / Default) to the bookings list, ordering bookings by when they were created (
createdAt).Why
Users want to review bookings in the order they came in ("new bookings in created order"), independent of the upcoming/past/cancelled tab they're on.
How
sortCreatedon the bookings query input (get.schema.ts). The handler'sgetOrderByalready mapssortCreated→.orderBy("createdAt", …), so no handler change was needed.BookingListContainer.tsx: aSortButtondropdown plus liftedsortCreatedstate wired into the query. When unset (Default), the existing per-status default ordering is preserved.sort,newest_first,oldest_first.Testing
getOrderByreturns{ key: "createdAt", order }forsortCreated, and the input schema now accepts it. No new type errors introduced (confirmed by diffing the web type-check against a clean baseline).Verified locally
Notes / why this is low-risk
sortCreated; this is primarily input-schema + UI wiring.🤖 Generated with Claude Code