-
Notifications
You must be signed in to change notification settings - Fork 2k
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
base: main
Are you sure you want to change the base?
Conversation
depth?: number | ||
limit?: number | ||
page?: number | ||
where: Where | ||
} = { | ||
const query = { | ||
depth: 0, | ||
limit: maxResultsPerRequest, | ||
page: pageIndex, | ||
select: { | ||
[fieldToSearch]: true, | ||
}, | ||
where: { | ||
and: [], | ||
}, | ||
} as Where, |
There was a problem hiding this comment.
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
if (data.nextPage) { | ||
nextPageByRelationshipRef.current.set(relationSlug, data.nextPage) | ||
} else { | ||
partiallyLoadedRelationshipSlugs.current = | ||
partiallyLoadedRelationshipSlugs.current.filter( | ||
(partiallyLoadedRelation) => partiallyLoadedRelation !== relationSlug, | ||
) |
There was a problem hiding this comment.
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 }) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
Following #10551, I found and fixed a handful more bugs: