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): fixed many bugs in the WhereBuilder relationship select menu #10553

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

GermanJablo
Copy link
Contributor

@GermanJablo GermanJablo commented Jan 13, 2025

Following #10551, I found and fixed a handful more bugs:

  • When writing to the input, the results that were already there were not cleaned, causing incorrect results to appear.
  • the scroll was causing an infinite loop that showed repeated elements
  • optimization: only the required field is selected (not required)
  • refs are set to the initial value to avoid a state where nothing can be searched

Comment on lines -80 to +88
depth?: number
limit?: number
page?: number
where: Where
} = {
const query = {
depth: 0,
limit: maxResultsPerRequest,
page: pageIndex,
select: {
[fieldToSearch]: true,
},
where: {
and: [],
},
} as Where,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • simplified types using inference when possible
  • use select to bring only the field we are interested in

Comment on lines +116 to +122
if (data.nextPage) {
nextPageByRelationshipRef.current.set(relationSlug, data.nextPage)
} else {
partiallyLoadedRelationshipSlugs.current =
partiallyLoadedRelationshipSlugs.current.filter(
(partiallyLoadedRelation) => partiallyLoadedRelation !== relationSlug,
)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we leave the if (!debounceSearch), when we reach the end of the scroll, the results will start repeating to infinity.
Note that the setting of the two refs must occur even if nothing is written in the search input.

@@ -209,7 +205,9 @@ export const RelationshipField: React.FC<Props> = (props) => {
}, [hasMany, hasMultipleRelations, value, options])

const handleInputChange = (input: string) => {
dispatchOptions({ type: 'CLEAR', i18n, required: false })
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this line is not added, when writing something the results that are in the select will not disappear, even if they do not meet the new search term.

const relationSlug = partiallyLoadedRelationshipSlugs.current[0]
partiallyLoadedRelationshipSlugs.current = relationSlugs
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both refs are reset to the initial values ​​of the component.
If this line is not added, when scrolling to a last page, nothing else can be searched again.

@GermanJablo GermanJablo changed the title fix(ui): clear current results in WhereBuilder on input change fix(ui): fixed many bugs in the WhereBuilder relationship select menu Jan 13, 2025
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.

2 participants