diff --git a/galaxyui/src/app/search/search.component.ts b/galaxyui/src/app/search/search.component.ts index 942198dd5..cad9e1cac 100644 --- a/galaxyui/src/app/search/search.component.ts +++ b/galaxyui/src/app/search/search.component.ts @@ -32,6 +32,9 @@ import { EmptyStateConfig } from 'patternfly-ng/empty-state/empty-state-conf import { PaginationConfig } from 'patternfly-ng/pagination/pagination-config'; import { PaginationEvent } from 'patternfly-ng/pagination/pagination-event'; +import { NotificationService } from 'patternfly-ng/notification/notification-service/notification.service'; +import { NotificationType } from 'patternfly-ng/notification/notification-type'; + import { ContentTypes } from '../enums/content-types.enum'; import { CloudPlatform } from '../resources/cloud-platforms/cloud-platform'; import { ContentSearchService } from '../resources/content-search/content-search.service'; @@ -93,7 +96,8 @@ export class SearchComponent implements OnInit, AfterViewInit { private route: ActivatedRoute, private router: Router, private contentSearch: ContentSearchService, - private location: Location + private location: Location, + private notificationService: NotificationService, ) {} ngOnInit() { @@ -199,20 +203,41 @@ export class SearchComponent implements OnInit, AfterViewInit { this.preparePlatforms(data.platforms); this.prepareContentTypes(data.contentTypes); this.prepareCloudPlatforms(data.cloudPlatforms); - if (!data.content.results.length && !Object.keys(params).length) { - // No vendors exists - const default_params = {vendor: false}; - this.setSortConfig(); - this.setAppliedFilters(default_params); - this.searchContent(); + + // If there is an error on the search API, the content search services + // returns nothing, so we have to check if results actually exist. + if (data.content.results) { + if (!data.content.results.length && !Object.keys(params).length) { + // No vendors exists + const default_params = {vendor: false}; + this.setSortConfig(); + this.setAppliedFilters(default_params); + this.searchContent(); + } else { + this.setSortConfig(params['order_by']); + this.setPageSize(params); + this.setAppliedFilters(params); + this.prepareContent(data.content.results, data.content.count); + this.setQuery(); + this.pageLoading = false; + } } else { + this.notificationService.message( + NotificationType.WARNING, + 'Error', + 'Invalid search query', + false, + null, + null, + ); + this.setSortConfig(params['order_by']); this.setPageSize(params); this.setAppliedFilters(params); - this.prepareContent(data.content.results, data.content.count); - this.setQuery(); + this.pageLoading = false; } + }); }); } @@ -348,13 +373,24 @@ export class SearchComponent implements OnInit, AfterViewInit { private setPageSize(params: any) { if (params['page_size']) { - this.paginationConfig.pageSize = params['page_size']; - this.pageSize = params['page_size']; - this.pageNumber = 1; + let pageSize = Number(params['page_size']); + + if (Number.isNaN(pageSize)) { + pageSize = 10; + } + + this.paginationConfig.pageSize = pageSize; + this.pageSize = pageSize; } if (params['page']) { - this.paginationConfig.pageNumber = params['page']; - this.pageNumber = params['page']; + let pageNumber = Number(params['page']); + + if (Number.isNaN(pageNumber)) { + pageNumber = 1; + } + + this.paginationConfig.pageNumber = pageNumber; + this.pageNumber = pageNumber; } }