feat: add search title only filter for search options (#4587)
* feat: search title only filter * fix: page reload will keep settings * fix: working with additional filters * style changes
This commit is contained in:
@@ -385,14 +385,35 @@ export default class DocumentsStore extends BaseStore<Document> {
|
||||
};
|
||||
|
||||
@action
|
||||
searchTitles = async (query: string) => {
|
||||
searchTitles = async (query: string, options?: SearchParams) => {
|
||||
const compactedOptions = omitBy(options, (o) => !o);
|
||||
const res = await client.post("/documents.search_titles", {
|
||||
...compactedOptions,
|
||||
query,
|
||||
});
|
||||
invariant(res?.data, "Search response should be available");
|
||||
|
||||
// add the documents and associated policies to the store
|
||||
res.data.forEach(this.add);
|
||||
this.addPolicies(res.policies);
|
||||
|
||||
// store a reference to the document model in the search cache instead
|
||||
// of the original result from the API.
|
||||
const results: SearchResult[] = compact(
|
||||
res.data.map((result: SearchResult) => {
|
||||
const document = this.data.get(result.id);
|
||||
if (!document) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
document,
|
||||
};
|
||||
})
|
||||
);
|
||||
const existing = this.searchCache.get(query) || [];
|
||||
// splice modifies any existing results, taking into account pagination
|
||||
existing.splice(0, existing.length, ...results);
|
||||
this.searchCache.set(query, existing);
|
||||
return res.data;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user