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

Use search instead of findMany in relation pickers #7798

Merged
merged 7 commits into from
Oct 18, 2024

Conversation

ijreilly
Copy link
Collaborator

@ijreilly ijreilly commented Oct 17, 2024

First step of ##3298.
Here we update the search endpoint to allow for a filter argument, which we currently use in the relation pickers to restrict or exclude ids from search.
In a future PR we will try to simplify the search logic in the FE

@ijreilly ijreilly marked this pull request as ready for review October 17, 2024 16:20
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

This pull request updates the search functionality in relation pickers to allow for a filter argument, addressing the first step of issue #3298. Key changes include:

  • Removed ObjectMetadataItemsRelationPickerEffect component, simplifying the search logic
  • Updated useSearchRecords hook to include a filter parameter for more flexible querying
  • Modified GraphqlQuerySearchResolverService to apply filters to the query builder
  • Added a 'filter' argument to the SearchResolverArgs interface in the server-side resolver builder
  • Updated useFilteredSearchEntityQuery to use useSearchRecords instead of useFindManyRecords
  • Adjusted generateSearchRecordsQuery to include the filter argument in GraphQL queries

These changes lay the groundwork for improving multi-object requests and pickers across the application.

13 file(s) reviewed, 9 comment(s)
Edit PR Review Bot Settings | Greptile

@@ -11,6 +11,7 @@ export const GotoHotkeys = () => {

return nonSystemActiveObjectMetadataItems.map((objectMetadataItem) => (
<GoToHotkeyItemEffect
key={`go-to-hokey-item-${objectMetadataItem.id}`}
Copy link
Contributor

Choose a reason for hiding this comment

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

syntax: typo in 'hokey', should be 'hotkey'

Comment on lines 35 to 41
const { loading: selectedRecordsLoading, records: selectedRecords } =
useFindManyRecords({
useSearchRecords({
objectNameSingular,
filter: selectedIdsFilter,
orderBy: [{ [orderByField]: sortOrder }],
skip: !selectedIds.length,
searchInput: searchFilter,
});
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: This query might return unnecessary records. Consider adding a limit to avoid performance issues with large datasets.

Comment on lines 43 to 51
const {
loading: filteredSelectedRecordsLoading,
records: filteredSelectedRecords,
} = useFindManyRecords({
} = useSearchRecords({
objectNameSingular,
filter: makeAndFilterVariables([...searchFilters, selectedIdsFilter]),
orderBy: [{ [orderByField]: sortOrder }],
filter: selectedIdsFilter,
skip: !selectedIds.length,
searchInput: searchFilter,
});
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: This query seems redundant as it's identical to the previous one. Consider removing or clarifying its purpose.

Comment on lines 53 to 56
const notFilterIds = [...selectedIds, ...excludeRecordIds];
const notFilter = notFilterIds.length
? { not: { id: { in: notFilterIds } } }
: undefined;
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: The notFilter logic might not work as expected with the new search implementation. Verify that excluded records are properly filtered out.

Comment on lines 9 to 10
// TODO: use this for all search queries, because we need selectedEntities and entitiesToSelect each time we want to search
// Filtered entities to select are
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Consider removing or updating this TODO comment as it may no longer be relevant after the changes.

Comment on lines +84 to +87
searchTerms === ''
? `"${SEARCH_VECTOR_FIELD.name}" IS NOT NULL`
: `"${SEARCH_VECTOR_FIELD.name}" @@ to_tsquery(:searchTerms)`,
searchTerms === '' ? {} : { searchTerms },
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Consider extracting this condition into a separate method for better readability

@FelixMalfait
Copy link
Member

Great!

Copy link
Member

@Weiko Weiko left a comment

Choose a reason for hiding this comment

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

LGTM!

@ijreilly ijreilly merged commit 6fef125 into main Oct 18, 2024
18 checks passed
@ijreilly ijreilly deleted the search-in-multi-pickers branch October 18, 2024 12:50
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.

3 participants