Skip to content

Commit

Permalink
feat(reference): add props.searchProperty for reference fields
Browse files Browse the repository at this point in the history
  • Loading branch information
serhii-zubkov committed Feb 18, 2024
1 parent 006c5eb commit cb17319
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/frontend/components/property-type/reference/edit.tsx
Expand Up @@ -36,6 +36,7 @@ const Edit: FC<CombinedProps> = (props) => {
const optionRecords = await api.searchRecords({
resourceId,
query: inputValue,
searchProperty: property.props.searchProperty,
})
return optionRecords.map((optionRecord: RecordJSON) => ({
value: optionRecord.id,
Expand Down
1 change: 1 addition & 0 deletions src/frontend/components/property-type/reference/filter.tsx
Expand Up @@ -22,6 +22,7 @@ const Filter: React.FC<FilterPropertyProps> = (props) => {
const records = await api.searchRecords({
resourceId: property.reference as string,
query: inputValue,
searchProperty: property.props.searchProperty,
})

const loadedOptions = records.map((r) => ({ value: r.id, label: r.title }))
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/utils/api-client.ts
Expand Up @@ -143,15 +143,15 @@ class ApiClient {
async searchRecords({ resourceId, query, searchProperty }: {
resourceId: string;
query: string;
searchProperty?: string;
searchProperty?: any;
}): Promise<Array<RecordJSON>> {
if (globalAny.isOnServer) { return [] }
const actionName = 'search'
const response = await this.resourceAction({
resourceId,
actionName,
query,
...(searchProperty ? { params: { searchProperty } } : undefined),
...(searchProperty ? { params: { ...searchProperty } } : undefined),
})
checkResponse(response)
return response.data.records
Expand Down

0 comments on commit cb17319

Please sign in to comment.