Skip to content

Conversation

@eunjae-lee
Copy link
Contributor

@eunjae-lee eunjae-lee commented Jan 24, 2026

What does this PR do?

Adds a scalable solution for handling stale filter segment data by validating filters at the caller level when segments are applied.

Background: Filter segments store activeFilters as generic JSON. When referenced entities (users, event types, teams) are removed, the filter data becomes stale. Rather than coupling entity deletion logic with filter segment updates (as attempted in #26506), this PR validates filters at the point of consumption.

Changes:

  • Add optional validateActiveFilters prop to DataTableProvider that filters out invalid values when a segment is applied
  • Create useActiveFiltersValidator hook in bookings module that validates userId, eventTypeId, and teamId filters against accessible resources
  • Invalid values are filtered in memory without being persisted back to the backend
  • Timing fix: Delay segment filter application until validator data is loaded to prevent errors and UI flash

Related to #26506 (alternative approach)

Updates since last revision

  • Fixed critical timing issue: validator now returns "loading" state while data is fetching
  • Added pending segment handling in DataTableProvider to delay filter application until validator is ready
  • Exposed isValidatorPending in context so consumers can disable data fetching while waiting
  • Updated BookingListContainer to disable bookings query while validator is pending
  • Added type guard for accessibleEventTypeIds to ensure number[] type

Mandatory Tasks (DO NOT REMOVE)

  • I have self-reviewed the code (A decent size PR without self-review might be rejected).
  • I confirm automated tests are in place that prove my fix is effective or that my feature works.
  • I have updated the developer docs in /docs if this PR makes changes that would require a documentation change. N/A - internal API change only.

How should this be tested?

  1. Create a filter segment on the bookings page with a user filter containing a specific team member
  2. Remove that team member from the team
  3. Navigate to bookings page and select the saved segment
  4. Expected: The invalid user ID should be silently filtered out, and the segment should apply with only valid filter values
  5. No flash: The bookings list should not briefly show unfiltered results before showing filtered results

Test configuration: 16 unit tests are included covering all validation scenarios.

Human Review Checklist

  • Verify the timing logic: setSegmentId calls state setters before setting pendingSegmentRef, ensuring a re-render occurs so isValidatorPending updates correctly
  • Confirm isValidatorPending computation (validateActiveFilters === "loading" && pendingSegmentRef.current !== null) correctly gates the bookings query
  • Verify the useEffect that applies pending segment runs when isValidatorReady changes from false to true
  • Confirm as number type casts in validation logic are safe for the expected filter value types (userId, eventTypeId, teamId are always numbers)
  • Verify the type guard .filter((v): v is number => typeof v === "number") for eventTypeIds doesn't accidentally filter out valid IDs

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

…ment validation

- Add validateActiveFilters prop to DataTableProvider to filter out inaccessible values
- Create useActiveFiltersValidator hook in bookings module to validate filter values
- Integrate validator in bookings-view.tsx to validate userId, eventTypeId, teamId filters
- Add comprehensive tests for the filter validation logic

This provides a scalable solution for handling stale filter segment data by validating
filters at the caller level using already-fetched accessible resource IDs.

Co-Authored-By: eunjae@cal.com <hey@eunjae.dev>
@devin-ai-integration
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' or '@devin'.
  • 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

devin-ai-integration bot and others added 2 commits January 24, 2026 14:48
Co-Authored-By: eunjae@cal.com <hey@eunjae.dev>
- Change useActiveFiltersValidator to return 'loading' state while data is fetching
- Add pending segment handling in DataTableProvider to delay filter application
- Expose isValidatorPending in context for consumers to disable queries
- Update BookingListContainer to disable bookings query while validator is pending

This prevents both errors from invalid filters and flash from fetching without filters.

Co-Authored-By: eunjae@cal.com <hey@eunjae.dev>
@github-actions github-actions bot added consumer Medium priority Created by Linear-GitHub Sync teams area: teams, round robin, collective, managed event-types 🐛 bug Something isn't working labels Jan 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐛 bug Something isn't working consumer Medium priority Created by Linear-GitHub Sync size/XL teams area: teams, round robin, collective, managed event-types

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove team members from filter segment when removed from team

2 participants