From 24ffa6c63ac3dde14acacc11571e772a0c29f50e Mon Sep 17 00:00:00 2001 From: Yura Bondarenko Date: Fri, 25 Jun 2021 09:32:45 +0200 Subject: [PATCH] 79730: Replace component ID with unique number --- src/app/core/core.module.ts | 4 +++- src/app/core/shared/sequence.service.ts | 24 +++++++++++++++++++ .../search-filter.component.spec.ts | 4 +++- .../search-filter/search-filter.component.ts | 14 +++++++---- 4 files changed, 39 insertions(+), 7 deletions(-) create mode 100644 src/app/core/shared/sequence.service.ts diff --git a/src/app/core/core.module.ts b/src/app/core/core.module.ts index 615c2b3977..3c34e5ec35 100644 --- a/src/app/core/core.module.ts +++ b/src/app/core/core.module.ts @@ -162,6 +162,7 @@ import { UsageReport } from './statistics/models/usage-report.model'; import { RootDataService } from './data/root-data.service'; import { Root } from './data/root.model'; import { SearchConfig } from './shared/search/search-filters/search-config.model'; +import { SequenceService } from './shared/sequence.service'; /** * When not in production, endpoint responses can be mocked for testing purposes @@ -282,7 +283,8 @@ const PROVIDERS = [ FilteredDiscoveryPageResponseParsingService, { provide: NativeWindowService, useFactory: NativeWindowFactory }, VocabularyService, - VocabularyTreeviewService + VocabularyTreeviewService, + SequenceService, ]; /** diff --git a/src/app/core/shared/sequence.service.ts b/src/app/core/shared/sequence.service.ts new file mode 100644 index 0000000000..2340ffb259 --- /dev/null +++ b/src/app/core/shared/sequence.service.ts @@ -0,0 +1,24 @@ +/** + * The contents of this file are subject to the license and copyright + * detailed in the LICENSE and NOTICE files at the root of the source + * tree and available online at + * + * http://www.dspace.org/license/ + */ +import { Injectable } from '@angular/core'; + +@Injectable() +/** + * Provides unique sequential numbers + */ +export class SequenceService { + private value: number; + + constructor() { + this.value = 0; + } + + public next(): number { + return ++this.value; + } +} diff --git a/src/app/shared/search/search-filters/search-filter/search-filter.component.spec.ts b/src/app/shared/search/search-filters/search-filter/search-filter.component.spec.ts index 228eef9a20..a686b00b77 100644 --- a/src/app/shared/search/search-filters/search-filter/search-filter.component.spec.ts +++ b/src/app/shared/search/search-filters/search-filter/search-filter.component.spec.ts @@ -12,6 +12,7 @@ import { SearchFilterConfig } from '../../search-filter-config.model'; import { FilterType } from '../../filter-type.model'; import { SearchConfigurationServiceStub } from '../../../testing/search-configuration-service.stub'; import { SEARCH_CONFIG_SERVICE } from '../../../../+my-dspace-page/my-dspace-page.component'; +import { SequenceService } from '../../../../core/shared/sequence.service'; describe('SearchFilterComponent', () => { let comp: SearchFilterComponent; @@ -65,7 +66,8 @@ describe('SearchFilterComponent', () => { provide: SearchFilterService, useValue: mockFilterService }, - { provide: SEARCH_CONFIG_SERVICE, useValue: new SearchConfigurationServiceStub() } + { provide: SEARCH_CONFIG_SERVICE, useValue: new SearchConfigurationServiceStub() }, + { provide: SequenceService, useValue: new SequenceService() }, ], schemas: [NO_ERRORS_SCHEMA] }).overrideComponent(SearchFilterComponent, { diff --git a/src/app/shared/search/search-filters/search-filter/search-filter.component.ts b/src/app/shared/search/search-filters/search-filter/search-filter.component.ts index 57c4f991db..0f7f763b45 100644 --- a/src/app/shared/search/search-filters/search-filter/search-filter.component.ts +++ b/src/app/shared/search/search-filters/search-filter/search-filter.component.ts @@ -10,6 +10,7 @@ import { isNotEmpty } from '../../../empty.util'; import { SearchService } from '../../../../core/shared/search/search.service'; import { SearchConfigurationService } from '../../../../core/shared/search/search-configuration.service'; import { SEARCH_CONFIG_SERVICE } from '../../../../+my-dspace-page/my-dspace-page.component'; +import { SequenceService } from '../../../../core/shared/sequence.service'; @Component({ selector: 'ds-search-filter', @@ -62,10 +63,15 @@ export class SearchFilterComponent implements OnInit { */ active$: Observable; + private readonly sequenceId: number; + constructor( private filterService: SearchFilterService, private searchService: SearchService, - @Inject(SEARCH_CONFIG_SERVICE) private searchConfigService: SearchConfigurationService) { + @Inject(SEARCH_CONFIG_SERVICE) private searchConfigService: SearchConfigurationService, + private sequenceService: SequenceService, + ) { + this.sequenceId = this.sequenceService.next(); } /** @@ -141,13 +147,11 @@ export class SearchFilterComponent implements OnInit { } get regionId(): string { - // tslint:disable-next-line:no-string-literal - return `search-filter-region-${this.constructor['ɵcmp'].id}`; + return `search-filter-region-${this.sequenceId}`; } get toggleId(): string { - // tslint:disable-next-line:no-string-literal - return `search-filter-toggle-${this.constructor['ɵcmp'].id}`; + return `search-filter-toggle-${this.sequenceId}`; } /**