Skip to content

Commit

Permalink
[form-builder] Support additional filter to reference input
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxars committed Dec 18, 2019
1 parent 63964c7 commit d90e42c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Expand Up @@ -19,12 +19,16 @@ type PreviewSnapshot = {
title: string
description: string
}
type SearchOptions = {
filter?: string
filterParams?: {[key: string]: any}
}
export type Props = {
value?: Reference
type: Type
markers: Array<Marker>
readOnly?: boolean
onSearch: (query: string, type: Type) => ObservableI<Array<SearchHit>>
onSearch: (query: string, type: Type, options: SearchOptions) => ObservableI<Array<SearchHit>>
getPreviewSnapshot: (Reference, Type) => ObservableI<PreviewSnapshot>
onChange: (event: PatchEvent) => void
level: number
Expand Down Expand Up @@ -117,12 +121,13 @@ export default class ReferenceInput extends React.Component<Props, State> {
}
search = (query: string) => {
const {type, onSearch} = this.props
const options = type.options || {}
this.setState({
isFetching: true
})
this.subscriptions.replace(
'search',
onSearch(query, type).subscribe((items: Array<SearchHit>) => {
onSearch(query, type, options).subscribe((items: Array<SearchHit>) => {
const updatedCache = items.reduce((cache, item) => {
cache[item._id] = item
return cache
Expand Down
Expand Up @@ -7,8 +7,8 @@ export function getPreviewSnapshot(value, referenceType) {
return observeForPreview(value, referenceType).pipe(map((result: any) => result.snapshot))
}

export function search(textTerm, referenceType) {
const doSearch = createWeightedSearch(referenceType.to, client)
export function search(textTerm, referenceType, options) {
const doSearch = createWeightedSearch(referenceType.to, client, options)
return doSearch(textTerm, {includeDrafts: false}).pipe(
map((results: any[]) => results.map(res => res.hit))
)
Expand Down

0 comments on commit d90e42c

Please sign in to comment.