Skip to content

feat: implement default filter segments for data tables #22939

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

Draft
wants to merge 22 commits into
base: main
Choose a base branch
from

Conversation

eunjae-lee
Copy link
Contributor

feat: implement default filter segments for data tables

Summary

This PR implements default filter segments for Cal.com's data table system, allowing users to access pre-defined filter combinations like "My Bookings" and "Upcoming Bookings" without having to create them manually. The implementation supports mixed segment ID types (numeric for user segments, string for default segments) and uses a dual database column approach for preference storage.

Key Changes:

  • Database: Added defaultSegmentId VARCHAR column to UserFilterSegmentPreference table with constraints ensuring only one segment type per preference
  • Type System: Introduced DefaultFilterSegment type and CombinedFilterSegment union type to handle mixed ID types throughout the application
  • Core Logic: Updated useSegments hook, DataTableProvider, and repository methods to handle both user and default segments
  • UI: Modified FilterSegmentSelect to group default segments separately with icons, and prevent editing/deleting of default segments
  • Implementation: Added "My Bookings" and "Upcoming Bookings" default segments to the bookings view

Review & Testing Checklist for Human

  • Test mixed segment ID functionality: Switch between user-created segments (numeric IDs) and default segments (string IDs) to ensure state management works correctly across URL changes and component re-renders
  • Verify database migration: Check that the new defaultSegmentId column and constraints were applied correctly, and that existing user preferences still work
  • Test default segment UI grouping: Confirm default segments appear first in dropdown with proper icons, have no submenu actions, and are visually distinguished from user segments
  • Validate date range filters: Test "Upcoming Bookings" default segment to ensure the relative date range preset works correctly and updates dynamically
  • Test segment preference persistence: Verify that selecting default segments saves preferences correctly and persists across page reloads

Recommended Test Plan:

  1. Navigate to bookings page and verify default segments appear in filter dropdown
  2. Select "My Bookings" and confirm it filters to current user's bookings
  3. Select "Upcoming Bookings" and verify it shows future bookings only
  4. Create a custom user segment and verify it appears in "Personal" group
  5. Switch between default and user segments multiple times
  6. Reload page and confirm last selected segment is remembered
  7. Try to edit/delete a default segment (should be prevented)

Diagram

%%{ init : { "theme" : "default" }}%%
graph TD
    BookingsView["apps/web/modules/bookings/views/<br/>bookings-listing-view.tsx"]:::major-edit
    DataTableProvider["packages/features/data-table/<br/>DataTableProvider.tsx"]:::major-edit
    useSegments["packages/features/data-table/hooks/<br/>useSegments.ts"]:::major-edit
    FilterSegmentSelect["packages/features/data-table/components/<br/>segment/FilterSegmentSelect.tsx"]:::major-edit
    SaveSegmentButton["packages/features/data-table/components/<br/>segment/SaveFilterSegmentButton.tsx"]:::minor-edit
    Types["packages/features/data-table/<br/>lib/types.ts"]:::major-edit
    Repository["packages/lib/server/repository/<br/>filterSegment.ts"]:::major-edit
    Schema["packages/prisma/<br/>schema.prisma"]:::minor-edit
    Migration["packages/prisma/migrations/<br/>add_default_segment_id/"]:::major-edit

    BookingsView -->|"defines default segments"| DataTableProvider
    DataTableProvider -->|"passes defaultSegments prop"| useSegments
    useSegments -->|"combines user + default segments"| FilterSegmentSelect
    FilterSegmentSelect -->|"groups and displays segments"| SaveSegmentButton
    Types -->|"defines CombinedFilterSegment"| useSegments
    Types -->|"defines DefaultFilterSegment"| BookingsView
    Repository -->|"handles mixed ID types"| useSegments
    Schema -->|"adds defaultSegmentId column"| Migration
    Migration -->|"database schema change"| Repository

    subgraph Legend
        L1[Major Edit]:::major-edit
        L2[Minor Edit]:::minor-edit
        L3[Context/No Edit]:::context
    end

    classDef major-edit fill:#90EE90
    classDef minor-edit fill:#87CEEB
    classDef context fill:#FFFFFF
Loading

Notes

  • Mixed ID Type Complexity: The most critical aspect to review is the handling of mixed segment ID types (number vs string) throughout the data flow. This required updates to URL parsing, state management, database queries, and UI components.

  • Frontend-Only Approach: Default segments are defined in component code rather than stored in the database, making them easier to deploy but requiring careful coordination between different views.

  • Date Range Recalculation: Default segments with relative date ranges (like "upcoming") are recalculated on each render to stay current, which should be monitored for performance impact.

  • Backward Compatibility: Existing user segments and preferences should continue working unchanged due to the dual-column database approach.

Link to Devin run: https://app.devin.ai/sessions/1c959909a25541de82f2ac0612e08a75
Requested by: @eunjae-lee

devin-ai-integration bot and others added 2 commits August 6, 2025 16:44
- Add defaultSegmentId column to UserFilterSegmentPreference table
- Support mixed segment ID types (number for user segments, string for default segments)
- Add DefaultFilterSegment and CombinedFilterSegment types
- Update useSegments hook to handle default segments with date range recalculation
- Modify FilterSegmentSelect to group and display default segments separately
- Add default segments to bookings view (My Bookings, Upcoming Bookings)
- Prevent editing/deleting of default segments in SaveFilterSegmentButton
- Update DataTableProvider to support defaultSegments prop
- Update parsers and repository to handle mixed segment ID types

Implements frontend-only default segments as specified in the requirements.

Co-Authored-By: eunjae@cal.com <hey@eunjae.dev>
- Update eslint-config-next and @typescript-eslint packages to latest versions
- Fix dependency compatibility issues that were blocking pre-commit hooks

Co-Authored-By: eunjae@cal.com <hey@eunjae.dev>
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR that start with 'DevinAI'.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Copy link
Contributor

coderabbitai bot commented Aug 6, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch devin/1754492880-default-filter-segments

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.

@github-actions github-actions bot added the ❗️ migrations contains migration files label Aug 6, 2025
@keithwillcode keithwillcode added consumer core area: core, team members only labels Aug 6, 2025
Copy link

vercel bot commented Aug 6, 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 8, 2025 2:52pm
cal-eu ⬜️ Ignored (Inspect) Aug 8, 2025 2:52pm

devin-ai-integration bot and others added 2 commits August 7, 2025 14:45
- Update SegmentIdentifier to use discriminated union with 'custom' vs 'default' types
- Refactor setSegmentId to accept object parameters: { id: string; type: 'default' } | { id: number; type: 'custom' }
- Update type definitions with DefaultFilterSegment, CustomFilterSegment, and CombinedFilterSegment
- Modify useSegments hook to handle new segment type structure
- Update FilterSegmentSelect component to work with discriminated unions
- Refactor database preference handling to store segment type alongside ID
- Add proper type safety throughout the data flow
- Remove description property from DefaultFilterSegment type

Co-Authored-By: eunjae@cal.com <hey@eunjae.dev>
…redSegmentId

The test was expecting preferredSegmentId to be a number, but after the discriminated union refactor it now returns { id: number, type: 'custom' } for custom segments. Updated the assertion to use toEqual() for deep object comparison.

Co-Authored-By: eunjae@cal.com <hey@eunjae.dev>
devin-ai-integration bot and others added 8 commits August 8, 2025 11:53
- Remove null from SegmentIdentifier type definition since null/undefined indicate absence of identifier
- Update DataTableProvider and useSegments to handle SegmentIdentifier | null properly
- Fix type safety while maintaining discriminated union functionality
- Ensure setAndPersistSegmentId accepts null values for clearing segments

Co-Authored-By: eunjae@cal.com <hey@eunjae.dev>
…ntification

- Update 'my_bookings' to 'default-my_bookings'
- Update 'upcoming-bookings' to 'default-upcoming-bookings'
- Makes it easier to verify segment type by looking at the ID string
- Maintains all existing discriminated union functionality

Co-Authored-By: eunjae@cal.com <hey@eunjae.dev>
…refix for segment IDs

Co-Authored-By: eunjae@cal.com <hey@eunjae.dev>
… better semantics

Co-Authored-By: eunjae@cal.com <hey@eunjae.dev>
…scriminated union

Co-Authored-By: eunjae@cal.com <hey@eunjae.dev>
… all component files

Co-Authored-By: eunjae@cal.com <hey@eunjae.dev>
devin-ai-integration bot and others added 3 commits August 8, 2025 13:57
…type naming

Co-Authored-By: eunjae@cal.com <hey@eunjae.dev>
…:calcom/cal.com into devin/1754492880-default-filter-segments
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 ❗️ migrations contains migration files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants