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 in multi object pickers #7909

Merged
merged 15 commits into from
Oct 24, 2024
Merged

Use search in multi object pickers #7909

merged 15 commits into from
Oct 24, 2024

Conversation

ijreilly
Copy link
Collaborator

Fixes #3298.
We still have some existing glitches in the picker yet to fix.

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 enhances the search functionality in multi-object pickers by introducing a new combined search records query and refactoring existing hooks.

  • Added useGenerateCombinedSearchRecordsQuery hook in packages/twenty-front/src/modules/object-record/multiple-objects/hooks/useGenerateCombinedSearchRecordsQuery.ts for generating dynamic GraphQL queries across multiple object types
  • Introduced isObjectMetadataItemSearchable utility in packages/twenty-front/src/modules/object-record/multiple-objects/hooks/utils/isObjectMetadataItemSearchable.ts to determine searchable objects
  • Modified useMultiObjectSearchMatchesSearchFilterAndSelectedItemsQuery and useMultiObjectSearchMatchesSearchFilterAndToSelectQuery hooks to integrate the new search parameter and query generation
  • Removed useSearchFilterPerMetadataItem hook, indicating a significant refactor in search logic
  • Implemented formatSearchResults function to process and standardize search results across different object types

5 file(s) reviewed, 7 comment(s)
Edit PR Review Bot Settings | Greptile

query CombinedSearchRecords(
${filterPerMetadataItemArray},
${limitPerMetadataItemArray},
$search: String,
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 adding a non-null constraint to the $search parameter if it's required

Comment on lines 8 to 16
export const isObjectMetadataItemSearchable = (
objectMetadataItem: ObjectMetadataItem,
) => {
return (
objectMetadataItem.isCustom ||
SEARCHABLE_STANDARD_OBJECTS_NAMES_PLURAL.includes(
objectMetadataItem.namePlural,
)
);
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Function looks correct, but consider adding a comment explaining the logic behind determining searchability

Comment on lines +19 to +32
export const formatSearchResults = (
searchResults: MultiObjectRecordQueryResult | undefined,
): MultiObjectRecordQueryResult => {
if (!searchResults) {
return {};
}

return Object.entries(searchResults).reduce((acc, [key, value]) => {
let newKey = key.replace(/^search/, '');
newKey = newKey.charAt(0).toLowerCase() + newKey.slice(1);
acc[newKey] = value;
return acc;
}, {} as MultiObjectRecordQueryResult);
};
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 moving this utility function to a separate file for better code organization

const {
loading: selectedAndMatchesSearchFilterObjectRecordsLoading,
data: selectedAndMatchesSearchFilterObjectRecordsQueryResult,
} = useQuery<MultiObjectRecordQueryResult>(
multiSelectQueryForSelectedIds ?? EMPTY_QUERY,
multiSelectSearchQueryForSelectedIds ?? EMPTY_QUERY,
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: multiSelectSearchQueryForSelectedIds is used here, but multiSelectQueryForSelectedIds is used in the skip condition. This inconsistency could lead to unexpected behavior

...selectedAndMatchesSearchFilterTextFilterPerMetadataItem,
...orderByFieldPerMetadataItem,
...limitPerMetadataItem,
},
skip: !isDefined(multiSelectQueryForSelectedIds),
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: ensure multiSelectQueryForSelectedIds is still needed, or if it should be replaced with multiSelectSearchQueryForSelectedIds

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! Left a comment!

'people',
'opportunities',
];
export const isObjectMetadataItemSearchable = (
Copy link
Member

Choose a reason for hiding this comment

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

I think this name is confusing because technically 'notes' are now searchable as well. If you want this util to be specific to multi objects search maybe we can find a better name? If it could work for notes then let's add it!

@ijreilly ijreilly merged commit c7bc301 into main Oct 24, 2024
18 checks passed
@ijreilly ijreilly deleted the search-in-multi-pickers branch October 24, 2024 11:43
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.

Find unique logic for multi-object request and pickers
2 participants