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:
Aditya Sharma
2023-01-02 23:30:10 +05:30
committed by GitHub
parent b6234848fb
commit 712ff8265e
3 changed files with 53 additions and 3 deletions

View File

@@ -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;
};