RED-3800: Fixed search error on refresh.

This commit is contained in:
Nicoleta Panaghiu 2023-05-03 09:54:11 +03:00
parent c64c238619
commit 1af8807874

View File

@ -52,27 +52,7 @@ export class SearchScreenComponent extends ListingComponent<ISearchListItem> imp
{ label: _('search-screen.cols.pages'), width: 'auto' },
];
readonly searchResults$ = combineLatest([this._queryChanged, this._filtersChanged$]).pipe(
tap(() => this._loadingService.start()),
tap(([query, [dossierIds, workflowStatus, assignee, dossierTemplateIds, onlyActive]]) =>
this._updateNavigation(query, dossierIds, workflowStatus, assignee, dossierTemplateIds, onlyActive),
),
switchMap(([query, [dossierIds, workflowStatus, assignee, dossierTemplateIds, onlyActive]]) =>
this._platformSearchService.search({
query,
dossierIds,
dossierTemplateIds,
workflowStatus,
assignee,
includeDeletedDossiers: false,
includeArchivedDossiers: !onlyActive,
}),
),
map(searchResult => this._toMatchedDocuments(searchResult)),
map(docs => this._toListItems(docs)),
tap(result => this.entitiesService.setEntities(result)),
tap(() => this._loadingService.stop()),
);
readonly searchResults$ = new Observable<ISearchListItem[]>();
readonly dossierTemplates$ = this._dossierTemplateService.loadAll().pipe(tap(templates => this._addTemplateFilter(templates)));
@ -90,6 +70,30 @@ export class SearchScreenComponent extends ListingComponent<ISearchListItem> imp
private readonly _userService: UserService,
) {
super();
if (!Object.keys(this._activatedRoute.snapshot.queryParams).length) {
this._router.navigate(['main']).then();
}
this.searchResults$ = combineLatest([this._queryChanged$, this._filtersChanged$]).pipe(
tap(() => this._loadingService.start()),
tap(([query, [dossierIds, workflowStatus, assignee, dossierTemplateIds, onlyActive]]) =>
this._updateNavigation(query, dossierIds, workflowStatus, assignee, dossierTemplateIds, onlyActive),
),
switchMap(([query, [dossierIds, workflowStatus, assignee, dossierTemplateIds, onlyActive]]) =>
this._platformSearchService.search({
query,
dossierIds,
dossierTemplateIds,
workflowStatus,
assignee,
includeDeletedDossiers: false,
includeArchivedDossiers: !onlyActive,
}),
),
map(searchResult => this._toMatchedDocuments(searchResult)),
map(docs => this._toListItems(docs)),
tap(result => this.entitiesService.setEntities(result)),
tap(() => this._loadingService.stop()),
);
this.searchService.skip = true;
this.sortingService.setSortingOption({ column: 'searchKey', order: SortingOrders.desc });
this._initFilters();
@ -119,7 +123,7 @@ export class SearchScreenComponent extends ListingComponent<ISearchListItem> imp
return this._activatedRoute.snapshot.queryParamMap.get('query');
}
private get _queryChanged(): Observable<string> {
private get _queryChanged$(): Observable<string> {
return this.searchService.valueChanges$.pipe(
startWith(this._routeQuery),
tap(query => (this.searchService.searchValue = query)),