Skip to content

Commit c3b7c35

Browse files
davide-negrettiatarix83
authored andcommitted
[UXP-99] Improvements to carousel-sections component
1 parent a8cc46c commit c3b7c35

3 files changed

Lines changed: 25 additions & 33 deletions

File tree

src/app/shared/explore/section-component/carousel-section/carousel-section.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
<div *ngIf="(searchResults$ | async) && (searchResults$ | async)?.payload?.page.length > 0">
2-
<ds-carousel [items]="(searchResults$ | async)?.payload?.page" [carouselOptions]="carouselOptions"></ds-carousel>
1+
<div *ngIf="(searchResults$ | async)?.length > 0 && !(isLoading$ | async)">
2+
<ds-carousel [items]="(searchResults$ | async)" [carouselOptions]="carouselOptions"></ds-carousel>
33
</div>
44
<div class="text-center" *ngIf="isLoading$ | async">
55
<ds-loading message="{{'loading.default' | translate}}"></ds-loading>

src/app/shared/explore/section-component/carousel-section/carousel-section.component.spec.ts

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
1111
import { SearchService } from '../../../../core/shared/search/search.service';
1212
import { TranslateLoaderMock } from '../../../mocks/translate-loader.mock';
1313
import { CarouselSectionComponent } from './carousel-section.component';
14-
import { SearchResult } from '../../../search/models/search-result.model';
15-
import { DSpaceObject } from '../../../../core/shared/dspace-object.model';
16-
import { createSuccessfulRemoteDataObject, createSuccessfulRemoteDataObject$ } from '../../../remote-data.utils';
14+
import { createSuccessfulRemoteDataObject$ } from '../../../remote-data.utils';
1715
import { ObjectCacheService } from '../../../../core/cache/object-cache.service';
1816
import { UUIDService } from '../../../../core/shared/uuid.service';
1917
import { RemoteDataBuildService } from '../../../../core/cache/builders/remote-data-build.service';
@@ -25,6 +23,7 @@ import { HttpClient } from '@angular/common/http';
2523
import { DSOChangeAnalyzer } from '../../../../core/data/dso-change-analyzer.service';
2624
import { DefaultChangeAnalyzer } from '../../../../core/data/default-change-analyzer.service';
2725
import { cold } from 'jasmine-marbles';
26+
import { ItemSearchResult } from '../../../object-collection/shared/item-search-result.model';
2827

2928
describe('CarouselSectionComponent', () => {
3029
let component: CarouselSectionComponent;
@@ -33,27 +32,23 @@ describe('CarouselSectionComponent', () => {
3332
let searchServiceStub: any;
3433
let notificationService: NotificationsServiceStub;
3534

36-
const searchResult = Object.assign(new SearchResult(), {
37-
indexableObject: Object.assign(new DSpaceObject(), {
38-
id: 'd317835d-7b06-4219-91e2-1191900cb897',
39-
uuid: 'd317835d-7b06-4219-91e2-1191900cb897',
40-
name: 'My first person',
41-
metadata: {
42-
'dc.title': [
43-
{ value: 'Test' }
44-
],
45-
'dc.description.abstract': [
46-
{ value: 'Lorem Ipsum' }
47-
]
48-
},
49-
_links: {
50-
content: { href: 'file-selflink' }
51-
}
52-
})
35+
const searchResult = Object.assign(new ItemSearchResult(), {
36+
id: 'd317835d-7b06-4219-91e2-1191900cb897',
37+
uuid: 'd317835d-7b06-4219-91e2-1191900cb897',
38+
name: 'My first person',
39+
metadata: {
40+
'dc.title': [
41+
{ value: 'Test' }
42+
],
43+
'dc.description.abstract': [
44+
{ value: 'Lorem Ipsum' }
45+
]
46+
},
47+
_links: {
48+
content: { href: 'file-selflink' }
49+
}
5350
});
5451

55-
const searchResultRD = createSuccessfulRemoteDataObject({ page: [searchResult] });
56-
5752
beforeEach(waitForAsync(() => {
5853
searchServiceStub = jasmine.createSpyObj('SearchService', {
5954
search: jasmine.createSpy('search'),
@@ -124,7 +119,7 @@ describe('CarouselSectionComponent', () => {
124119
}));
125120

126121
it('should init search results data properly', (done) => {
127-
const expected = cold('(a|)', { a: searchResultRD });
122+
const expected = cold('(a|)', { a: [searchResult] });
128123
expect(component.searchResults$).toBeObservable(expected);
129124
done();
130125
});

src/app/shared/explore/section-component/carousel-section/carousel-section.component.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,14 @@ import { Component, Input, OnInit } from '@angular/core';
22
import { BehaviorSubject, Observable } from 'rxjs';
33
import { tap } from 'rxjs/operators';
44
import { SortDirection, SortOptions } from '../../../../core/cache/models/sort-options.model';
5-
import { PaginatedList } from '../../../../core/data/paginated-list.model';
6-
import { RemoteData } from '../../../../core/data/remote-data';
75
import { DSpaceObjectType } from '../../../../core/shared/dspace-object-type.model';
8-
import { DSpaceObject } from '../../../../core/shared/dspace-object.model';
9-
import { getFirstCompletedRemoteData } from '../../../../core/shared/operators';
6+
import { getFirstSucceededRemoteListPayload } from '../../../../core/shared/operators';
107
import { SearchService } from '../../../../core/shared/search/search.service';
118
import { PaginationComponentOptions } from '../../../pagination/pagination-component-options.model';
129
import { PaginatedSearchOptions } from '../../../search/models/paginated-search-options.model';
13-
import { SearchResult } from '../../../search/models/search-result.model';
1410
import { CarouselSection } from '../../../../core/layout/models/section.model';
1511
import {CarouselOptions} from '../../../carousel/carousel-options.model';
12+
import { ItemSearchResult } from '../../../object-collection/shared/item-search-result.model';
1613

1714
/**
1815
* Component representing the Carousel component section.
@@ -39,7 +36,7 @@ export class CarouselSectionComponent implements OnInit {
3936
/**
4037
* Search results of provided carousel configurations.
4138
*/
42-
searchResults$: Observable<RemoteData<PaginatedList<SearchResult<DSpaceObject>>>>;
39+
searchResults$: Observable<ItemSearchResult[]>;
4340

4441
/**
4542
* Paginated Search Options of current carousel configurations.
@@ -107,9 +104,9 @@ export class CarouselSectionComponent implements OnInit {
107104
});
108105

109106
this.searchResults$ = this.searchService.search(this.paginatedSearchOptions).pipe(
110-
getFirstCompletedRemoteData(),
107+
getFirstSucceededRemoteListPayload(),
111108
tap(() => this.isLoading$.next(false)),
112-
);
109+
) as Observable<ItemSearchResult[]>;
113110
}
114111

115112
}

0 commit comments

Comments
 (0)