Skip to content
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

fix(ui): relationship filter renders stale values when changing fields #11080

Merged
merged 19 commits into from
Feb 11, 2025

Conversation

jacobsfletch
Copy link
Member

@jacobsfletch jacobsfletch commented Feb 10, 2025

Fixes #9873. The relationship filter in the "where" builder renders stale values when switching between fields or adding additional "and" conditions. This was because the RelationshipFilter component was not responding to changes in the relationTo prop and failing to reset internal state when these events took place.

While it sounds like a simple fix, it was actually quite extensive. The RelationshipFilter component was previously relying on a useEffect that had a callback in its dependencies. This was causing the effect to run uncontrollably using old references. To avoid this, we use the new useEffectEvent approach which allows the underlying effect to run much more precisely. Same with the Condition component that wraps it. We now run callbacks directly within event handlers as much as possible, and rely on useEffectEvent only for debounced value changes.

This component was also unnecessarily complex...and still is to some degree. Previously, it was maintaining two separate refs, one to track the relationships that have yet to fully load, and another to track the next pages of each relationship that need to load on the next run. These have been combined into a single ref that tracks both simultaneously, as this data is interrelated.

This change also does some much needed housekeeping to the WhereBuilder by improving types, defaulting the operator field, etc.

Related: #11023 and #11032

Unrelated: finds a few more instances where the new addListFilter helper from #11026 could be used. Also removes a few duplicative tests.

@jacobsfletch jacobsfletch changed the title fix(ui): stale values in the relationship filter fix(ui): relationship filter renders stale values when changing fields Feb 10, 2025
@jacobsfletch jacobsfletch merged commit da6511e into main Feb 11, 2025
67 checks passed
@jacobsfletch jacobsfletch deleted the fix/changing-condition-field-should-update-values branch February 11, 2025 14:45
Copy link
Contributor

🚀 This is included in version v3.23.0

jacobsfletch added a commit that referenced this pull request Feb 11, 2025
…11008)

Fixes #10440. When `filterOptions` are set on a relationship field,
those same filters are not applied to the `Filter` component within the
list view. This is because `filterOptions` is not being thread into the
`RelationshipFilter` component responsible for populating the available
options.

To do this, we first need to be resolve the filter options on the server
as they accept functions. Once resolved, they can be prop-drilled into
the proper component and appended onto the client-side "where" query.

Reliant on #11080.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Collection List View "Where and" query not working properly with relationships
1 participant