Skip to content

Commit fe226c4

Browse files
author
Andrea Barbasso
committed
[DSC-1661] get showCorrection from rest property
1 parent 276a761 commit fe226c4

3 files changed

Lines changed: 42 additions & 4 deletions

File tree

src/app/search-page/configuration-search-page.component.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { RouteService } from '../core/services/route.service';
99
import { SearchService } from '../core/shared/search/search.service';
1010
import { Router } from '@angular/router';
1111
import { SearchManager } from '../core/browse/search-manager';
12+
import { ConfigurationDataService } from '../core/data/configuration-data.service';
1213

1314
/**
1415
* This component renders a search page using a configuration as input.
@@ -35,7 +36,8 @@ export class ConfigurationSearchPageComponent extends SearchComponent {
3536
@Inject(PLATFORM_ID) public platformId: any,
3637
@Inject(SEARCH_CONFIG_SERVICE) public searchConfigService: SearchConfigurationService,
3738
protected routeService: RouteService,
38-
protected router: Router) {
39-
super(service, searchManager, sidebarService, windowService, searchConfigService, platformId, routeService, router);
39+
protected router: Router,
40+
protected configurationService: ConfigurationDataService,) {
41+
super(service, searchManager, sidebarService, windowService, searchConfigService, platformId, routeService, router, configurationService);
4042
}
4143
}

src/app/shared/search/search.component.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,17 @@ import { SearchFilterConfig } from './models/search-filter-config.model';
3434
import { FilterType } from './models/filter-type.model';
3535
import { getCommunityPageRoute } from '../../community-page/community-page-routing-paths';
3636
import { getCollectionPageRoute } from '../../collection-page/collection-page-routing-paths';
37+
import { ConfigurationDataService } from '../../core/data/configuration-data.service';
3738

3839
let comp: SearchComponent;
3940
let fixture: ComponentFixture<SearchComponent>;
4041
let searchServiceObject: SearchService;
4142
let searchConfigurationServiceObject: SearchConfigurationService;
43+
44+
const configurationDataService = jasmine.createSpyObj('configurationDataService', {
45+
findByPropertyName: createSuccessfulRemoteDataObject$({ values: ['true'] })
46+
});
47+
4248
const store: Store<SearchComponent> = jasmine.createSpyObj('store', {
4349
/* eslint-disable no-empty,@typescript-eslint/no-empty-function */
4450
dispatch: {},
@@ -239,6 +245,10 @@ export function configureSearchComponentTestingModule(compType, additionalDeclar
239245
{
240246
provide: SEARCH_CONFIG_SERVICE,
241247
useValue: searchConfigurationServiceStub
248+
},
249+
{
250+
provide: ConfigurationDataService,
251+
useValue: configurationDataService
242252
}
243253
],
244254
schemas: [NO_ERRORS_SCHEMA]
@@ -329,6 +339,12 @@ describe('SearchComponent', () => {
329339
expect(comp.resultFound.emit).toHaveBeenCalledWith(expectedResults);
330340
}));
331341

342+
it('should show correction badge when item is a correction', fakeAsync(() => {
343+
comp.ngOnInit();
344+
tick(100);
345+
expect(comp.showCorrection).toBe(true);
346+
}));
347+
332348
describe('when the open sidebar button is clicked in mobile view', () => {
333349

334350
beforeEach(() => {

src/app/shared/search/search.component.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import { COMMUNITY_MODULE_PATH } from '../../community-page/community-page-routi
5151
import { SearchManager } from '../../core/browse/search-manager';
5252
import { AlertType } from '../alert/alert-type';
5353
import { isPlatformServer } from '@angular/common';
54+
import { ConfigurationDataService } from '../../core/data/configuration-data.service';
5455

5556
@Component({
5657
selector: 'ds-search',
@@ -192,7 +193,7 @@ export class SearchComponent implements OnInit, OnDestroy {
192193
/**
193194
* Whether to show if the item is a correction
194195
*/
195-
@Input() showCorrection = false;
196+
@Input() showCorrection: boolean;
196197

197198
/**
198199
* Whether to show the view mode switch
@@ -373,7 +374,8 @@ export class SearchComponent implements OnInit, OnDestroy {
373374
@Inject(PLATFORM_ID) public platformId: any,
374375
@Inject(SEARCH_CONFIG_SERVICE) public searchConfigService: SearchConfigurationService,
375376
protected routeService: RouteService,
376-
protected router: Router,) {
377+
protected router: Router,
378+
protected configurationService: ConfigurationDataService,) {
377379
this.isXsOrSm$ = this.windowService.isXsOrSm();
378380
}
379381

@@ -390,6 +392,24 @@ export class SearchComponent implements OnInit, OnDestroy {
390392
return;
391393
}
392394

395+
if (this.showCorrection === null || this.showCorrection === undefined) {
396+
this.subs.push(
397+
this.configurationService.findByPropertyName('context-menu-entry.requestcorrection.enabled').pipe(
398+
getFirstCompletedRemoteData(),
399+
map((res) => {
400+
switch (res?.payload?.values[0]) {
401+
case 'true':
402+
return true;
403+
case 'false':
404+
default:
405+
return false;
406+
}
407+
}),
408+
).subscribe((showCorrection) => {
409+
this.showCorrection = showCorrection;
410+
}));
411+
}
412+
393413
if (this.useUniquePageId) {
394414
// Create an unique pagination id related to the instance of the SearchComponent
395415
this.paginationId = uniqueId(this.paginationId);

0 commit comments

Comments
 (0)