-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Search #7237
Merged
Search #7237
Changes from all commits
Commits
Show all changes
57 commits
Select commit
Hold shift + click to select a range
dd5055d
fix test
ijreilly 0904917
Merge branch 'main' of github.com:twentyhq/twenty into search
ijreilly 81d6005
Comments with twenty orm hints
ijreilly c343155
Merge branch 'main' of github.com:twentyhq/twenty into search
ijreilly 8d76f96
WIP - search with query builder and trgm works (prereq: add trgm exte…
ijreilly ed90ee9
WIP
ijreilly 66f8747
wip - Add search parameter
ijreilly 77f4063
wip - search on trigram works in front
ijreilly 0989b70
ts_vector works
ijreilly b758fc8
wip
ijreilly 570b9d3
wip - spilo dockerfile works
ijreilly c612fc0
Merge branch 'main' of github.com:twentyhq/twenty into search
ijreilly 324ac9b
Merge branch 'main' of github.com:twentyhq/twenty into search
ijreilly 3cbccd3
implementation of search endpoint
ijreilly 6d1092f
Add limit arg to search endpoint
ijreilly 552b4e0
Add feature flag
ijreilly b258648
wip
ijreilly cc4764a
Merge branch 'main' of github.com:twentyhq/twenty into search
ijreilly 3401747
wip - searchvector created and works but typeorm issue + no indexes yet
ijreilly a1213c5
split emails in two words for tsvector
ijreilly 51dcb01
Add searchVector to custom object entity
ijreilly 0716119
create searchVector field at custom object creation
ijreilly fc053e3
Handle gin index creation with decorator
ijreilly 7e50d5a
Merge branch 'main' of github.com:twentyhq/twenty into search
ijreilly 3929800
remove merge conflict trace
ijreilly 1d67d22
wip
ijreilly 2a1103c
Merge branch 'main' of github.com:twentyhq/twenty into search
ijreilly 24c7d6e
generate graphql for front
ijreilly 6b1d822
wip
ijreilly 4059b61
Add typeOrmMetadata column
ijreilly 3eec4ef
Merge branch 'main' of github.com:twentyhq/twenty into search
ijreilly 1cdbe30
wip
ijreilly 2c70842
Merge branch 'main' of github.com:twentyhq/twenty into search
ijreilly b08b5aa
wip
ijreilly 5a23053
Fix infinite loop
ijreilly dff5266
Use .getMany()
ijreilly b1001c7
Merge branch 'main' of github.com:twentyhq/twenty into search
ijreilly 85a00c9
Concatenate phone fields for ts vector column expressoin
ijreilly 3fa7252
Remove phones from person label identifier
ijreilly 9a06c25
Remove code from paradedb tests
ijreilly 581045b
clean code
ijreilly eb39b2d
Merge branch 'main' of github.com:twentyhq/twenty into search
ijreilly 88a4d19
minor improvements
ijreilly 1c52263
Extend sync-index to standard indexes on custom objects
ijreilly 3d7bbac
Add feature flag in FE
ijreilly 5605645
Fix standard index factory issue
ijreilly ef9ab33
Merge branch 'main' of github.com:twentyhq/twenty into search
ijreilly b05c027
Code improvements
ijreilly 54c17d1
Fix index creation
ijreilly 4652fc7
Fix SQL injection breach
ijreilly cae5738
Refactor generateFields
ijreilly 5771352
Nullify searchVector when deletedAt is not null
ijreilly d404c22
improve code quality
ijreilly 2e95942
Fix escapedWord
ijreilly c6fe5f9
improve code quality
ijreilly adfc8ee
Fix BTREE indexes inclusion of deletedAt + add tests
ijreilly 1bed77f
Follow conventions for addIndexType
ijreilly File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
...es/twenty-front/src/modules/object-record/graphql/types/RecordGqlOperationSearchResult.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { RecordGqlConnection } from '@/object-record/graphql/types/RecordGqlConnection'; | ||
|
||
export type RecordGqlOperationSearchResult = { | ||
[objectNamePlural: string]: RecordGqlConnection; | ||
}; |
94 changes: 94 additions & 0 deletions
94
packages/twenty-front/src/modules/object-record/hooks/useSearchRecords.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { useQuery, WatchQueryFetchPolicy } from '@apollo/client'; | ||
import { useRecoilValue } from 'recoil'; | ||
|
||
import { currentWorkspaceMemberState } from '@/auth/states/currentWorkspaceMemberState'; | ||
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem'; | ||
import { ObjectMetadataItemIdentifier } from '@/object-metadata/types/ObjectMetadataItemIdentifier'; | ||
import { getRecordsFromRecordConnection } from '@/object-record/cache/utils/getRecordsFromRecordConnection'; | ||
import { RecordGqlOperationGqlRecordFields } from '@/object-record/graphql/types/RecordGqlOperationGqlRecordFields'; | ||
import { RecordGqlOperationSearchResult } from '@/object-record/graphql/types/RecordGqlOperationSearchResult'; | ||
import { RecordGqlOperationVariables } from '@/object-record/graphql/types/RecordGqlOperationVariables'; | ||
import { useSearchRecordsQuery } from '@/object-record/hooks/useSearchRecordsQuery'; | ||
import { ObjectRecord } from '@/object-record/types/ObjectRecord'; | ||
import { getSearchRecordsQueryResponseField } from '@/object-record/utils/getSearchRecordsQueryResponseField'; | ||
import { SnackBarVariant } from '@/ui/feedback/snack-bar-manager/components/SnackBar'; | ||
import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar'; | ||
import { useMemo } from 'react'; | ||
import { logError } from '~/utils/logError'; | ||
|
||
export type UseSearchRecordsParams = ObjectMetadataItemIdentifier & | ||
RecordGqlOperationVariables & { | ||
onError?: (error?: Error) => void; | ||
skip?: boolean; | ||
recordGqlFields?: RecordGqlOperationGqlRecordFields; | ||
fetchPolicy?: WatchQueryFetchPolicy; | ||
searchInput?: string; | ||
}; | ||
|
||
export const useSearchRecords = <T extends ObjectRecord = ObjectRecord>({ | ||
objectNameSingular, | ||
searchInput, | ||
limit, | ||
skip, | ||
recordGqlFields, | ||
fetchPolicy, | ||
}: UseSearchRecordsParams) => { | ||
const currentWorkspaceMember = useRecoilValue(currentWorkspaceMemberState); | ||
const { objectMetadataItem } = useObjectMetadataItem({ | ||
objectNameSingular, | ||
}); | ||
const { searchRecordsQuery } = useSearchRecordsQuery({ | ||
objectNameSingular, | ||
recordGqlFields, | ||
}); | ||
|
||
const { enqueueSnackBar } = useSnackBar(); | ||
|
||
const { data, loading, error } = useQuery<RecordGqlOperationSearchResult>( | ||
searchRecordsQuery, | ||
{ | ||
skip: | ||
skip || !objectMetadataItem || !currentWorkspaceMember || !searchInput, | ||
variables: { | ||
search: searchInput, | ||
limit: limit, | ||
}, | ||
fetchPolicy: fetchPolicy, | ||
onError: (error) => { | ||
logError( | ||
`useSearchRecords for "${objectMetadataItem.namePlural}" error : ` + | ||
error, | ||
); | ||
enqueueSnackBar( | ||
`Error during useSearchRecords for "${objectMetadataItem.namePlural}", ${error.message}`, | ||
{ | ||
variant: SnackBarVariant.Error, | ||
}, | ||
); | ||
}, | ||
}, | ||
); | ||
|
||
const queryResponseField = getSearchRecordsQueryResponseField( | ||
objectMetadataItem.namePlural, | ||
); | ||
|
||
const result = data?.[queryResponseField]; | ||
|
||
const records = useMemo( | ||
() => | ||
result | ||
? (getRecordsFromRecordConnection({ | ||
recordConnection: result, | ||
}) as T[]) | ||
: [], | ||
[result], | ||
); | ||
|
||
return { | ||
objectMetadataItem, | ||
records: records, | ||
loading, | ||
error, | ||
}; | ||
}; |
33 changes: 33 additions & 0 deletions
33
packages/twenty-front/src/modules/object-record/hooks/useSearchRecordsQuery.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { useRecoilValue } from 'recoil'; | ||
|
||
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem'; | ||
import { objectMetadataItemsState } from '@/object-metadata/states/objectMetadataItemsState'; | ||
import { RecordGqlOperationGqlRecordFields } from '@/object-record/graphql/types/RecordGqlOperationGqlRecordFields'; | ||
import { generateSearchRecordsQuery } from '@/object-record/utils/generateSearchRecordsQuery'; | ||
|
||
export const useSearchRecordsQuery = ({ | ||
objectNameSingular, | ||
recordGqlFields, | ||
computeReferences, | ||
}: { | ||
objectNameSingular: string; | ||
recordGqlFields?: RecordGqlOperationGqlRecordFields; | ||
computeReferences?: boolean; | ||
}) => { | ||
const { objectMetadataItem } = useObjectMetadataItem({ | ||
objectNameSingular, | ||
}); | ||
|
||
const objectMetadataItems = useRecoilValue(objectMetadataItemsState); | ||
|
||
const searchRecordsQuery = generateSearchRecordsQuery({ | ||
objectMetadataItem, | ||
objectMetadataItems, | ||
recordGqlFields, | ||
computeReferences, | ||
}); | ||
|
||
return { | ||
searchRecordsQuery, | ||
}; | ||
}; |
40 changes: 40 additions & 0 deletions
40
packages/twenty-front/src/modules/object-record/utils/generateSearchRecordsQuery.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import gql from 'graphql-tag'; | ||
|
||
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem'; | ||
import { mapObjectMetadataToGraphQLQuery } from '@/object-metadata/utils/mapObjectMetadataToGraphQLQuery'; | ||
import { RecordGqlOperationGqlRecordFields } from '@/object-record/graphql/types/RecordGqlOperationGqlRecordFields'; | ||
import { getSearchRecordsQueryResponseField } from '@/object-record/utils/getSearchRecordsQueryResponseField'; | ||
import { capitalize } from '~/utils/string/capitalize'; | ||
|
||
export type QueryCursorDirection = 'before' | 'after'; | ||
|
||
export const generateSearchRecordsQuery = ({ | ||
objectMetadataItem, | ||
objectMetadataItems, | ||
recordGqlFields, | ||
computeReferences, | ||
}: { | ||
objectMetadataItem: ObjectMetadataItem; | ||
objectMetadataItems: ObjectMetadataItem[]; // TODO - what is this used for? | ||
recordGqlFields?: RecordGqlOperationGqlRecordFields; | ||
computeReferences?: boolean; | ||
}) => gql` | ||
query Search${capitalize(objectMetadataItem.namePlural)}($search: String, $limit: Int) { | ||
${getSearchRecordsQueryResponseField(objectMetadataItem.namePlural)}(searchInput: $search, limit: $limit){ | ||
edges { | ||
node ${mapObjectMetadataToGraphQLQuery({ | ||
objectMetadataItems, | ||
objectMetadataItem, | ||
recordGqlFields, | ||
computeReferences, | ||
})} | ||
} | ||
pageInfo { | ||
hasNextPage | ||
hasPreviousPage | ||
startCursor | ||
endCursor | ||
} | ||
} | ||
} | ||
`; |
4 changes: 4 additions & 0 deletions
4
packages/twenty-front/src/modules/object-record/utils/getSearchRecordsQueryResponseField.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { capitalize } from '~/utils/string/capitalize'; | ||
|
||
export const getSearchRecordsQueryResponseField = (objectNamePlural: string) => | ||
`search${capitalize(objectNamePlural)}`; |
8 changes: 8 additions & 0 deletions
8
packages/twenty-front/src/modules/opportunities/Opportunity.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export type Opportunity = { | ||
__typename: 'Opportunity'; | ||
id: string; | ||
createdAt: string; | ||
updatedAt?: string; | ||
deletedAt?: string | null; | ||
name: string | null; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
style: QueryCursorDirection is defined but not used in this file. Consider removing if unnecessary.