mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
[CST-4882] Show error message if the search query fails - Handle error 422 (invalid query) separately
This commit is contained in:
@@ -10,5 +10,5 @@
|
|||||||
</ds-viewable-collection>
|
</ds-viewable-collection>
|
||||||
</div>
|
</div>
|
||||||
<ds-loading *ngIf="isLoading()" message="{{'loading.mydspace-results' | translate}}"></ds-loading>
|
<ds-loading *ngIf="isLoading()" message="{{'loading.mydspace-results' | translate}}"></ds-loading>
|
||||||
<ds-error *ngIf="searchResults?.hasFailed && (!searchResults?.errorMessage || searchResults?.statusCode != 400)" message="{{'error.search-results' | translate}}"></ds-error>
|
<ds-error *ngIf="showError(searchResults)" message="{{errorMessageLabel(searchResults) | translate}}"></ds-error>
|
||||||
<h3 *ngIf="searchResults?.payload?.page.length == 0" class="text-center text-muted" ><span>{{'mydspace.results.no-results' | translate}}</span></h3>
|
<h3 *ngIf="searchResults?.payload?.page.length == 0" class="text-center text-muted" ><span>{{'mydspace.results.no-results' | translate}}</span></h3>
|
||||||
|
@@ -58,4 +58,12 @@ export class MyDSpaceResultsComponent {
|
|||||||
isLoading() {
|
isLoading() {
|
||||||
return !this.searchResults || isEmpty(this.searchResults) || this.searchResults.isLoading;
|
return !this.searchResults || isEmpty(this.searchResults) || this.searchResults.isLoading;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
showError(searchResults: RemoteData<PaginatedList<SearchResult<DSpaceObject>>>): boolean {
|
||||||
|
return searchResults?.hasFailed && (!searchResults?.errorMessage || searchResults?.statusCode !== 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
errorMessageLabel(searchResults: RemoteData<PaginatedList<SearchResult<DSpaceObject>>>): string {
|
||||||
|
return (searchResults?.statusCode === 422) ? 'error.invalid-search-query' : 'error.search-results';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
<ds-alert [type]="'alert-danger'" [dismissible]="false">
|
<ds-alert [type]="AlertTypeEnum.Error" [dismissible]="false">
|
||||||
{{ message }}
|
<!-- Using [innerHTML] instead of {{message}} allows to render HTML code -->
|
||||||
|
<span [innerHTML]="message"></span>
|
||||||
</ds-alert>
|
</ds-alert>
|
||||||
|
@@ -36,7 +36,7 @@ describe('ErrorComponent (inline template)', () => {
|
|||||||
comp = fixture.componentInstance; // ErrorComponent test instance
|
comp = fixture.componentInstance; // ErrorComponent test instance
|
||||||
|
|
||||||
// query for the message <label> by CSS element selector
|
// query for the message <label> by CSS element selector
|
||||||
de = fixture.debugElement.query(By.css('label'));
|
de = fixture.debugElement.query(By.css('ds-alert'));
|
||||||
el = de.nativeElement;
|
el = de.nativeElement;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -3,6 +3,7 @@ import { Component, Input } from '@angular/core';
|
|||||||
import { TranslateService } from '@ngx-translate/core';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
|
|
||||||
import { Subscription } from 'rxjs';
|
import { Subscription } from 'rxjs';
|
||||||
|
import { AlertType } from '../alert/aletr-type';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-error',
|
selector: 'ds-error',
|
||||||
@@ -13,6 +14,12 @@ export class ErrorComponent {
|
|||||||
|
|
||||||
@Input() message = 'Error...';
|
@Input() message = 'Error...';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The AlertType enumeration
|
||||||
|
* @type {AlertType}
|
||||||
|
*/
|
||||||
|
public AlertTypeEnum = AlertType;
|
||||||
|
|
||||||
private subscription: Subscription;
|
private subscription: Subscription;
|
||||||
|
|
||||||
constructor(private translate: TranslateService) {
|
constructor(private translate: TranslateService) {
|
||||||
|
@@ -1331,6 +1331,8 @@
|
|||||||
|
|
||||||
"error.search-results": "Error fetching search results",
|
"error.search-results": "Error fetching search results",
|
||||||
|
|
||||||
|
"error.invalid-search-query": "Search query is not valid. Please check <a href=\"https://solr.apache.org/guide/query-syntax-and-parsing.html\" target=\"_blank\">Solr query syntax</a> best practices for further information about this error.",
|
||||||
|
|
||||||
"error.sub-collections": "Error fetching sub-collections",
|
"error.sub-collections": "Error fetching sub-collections",
|
||||||
|
|
||||||
"error.sub-communities": "Error fetching sub-communities",
|
"error.sub-communities": "Error fetching sub-communities",
|
||||||
|
Reference in New Issue
Block a user