From 086bd4723b0a8c58a5c6b99c77c326023fb89b48 Mon Sep 17 00:00:00 2001 From: Mark Cooper Date: Thu, 8 Sep 2022 11:06:44 -0700 Subject: [PATCH] Resolve feedback Inject environment rather than importing it Redo the configuration for better consistency across pages --- config/config.example.yml | 24 ++++++++------- .../community-list-service.spec.ts | 5 +++- .../community-list-service.ts | 23 ++++++++------ ...top-level-community-list.component.spec.ts | 3 ++ .../top-level-community-list.component.ts | 13 ++++---- src/config/app-config.interface.ts | 6 ++-- .../browse-communities-config.interface.ts | 12 -------- src/config/community-list-config.interface.ts | 5 ++++ src/config/default-app-config.ts | 30 +++++++++++-------- src/config/homepage-config.interface.ts | 4 ++- src/environments/environment.test.ts | 23 +++++++------- 11 files changed, 84 insertions(+), 64 deletions(-) delete mode 100644 src/config/browse-communities-config.interface.ts create mode 100644 src/config/community-list-config.interface.ts diff --git a/config/config.example.yml b/config/config.example.yml index 19129f93ee..7a878094d2 100644 --- a/config/config.example.yml +++ b/config/config.example.yml @@ -175,9 +175,20 @@ browseBy: # The absolute lowest year to display in the dropdown (only used when no lowest date can be found for all items) defaultLowerLimit: 1900 -browseCommunities: - communityListPageSize: 20 - topLevelPageSize: 5 +communityList: + # No. of communities to list per expansion (show more) + pageSize: 20 + +homePage: + recentSubmissions: + # The number of item showing in recent submission components + pageSize: 5 + # Sort record of recent submission + sortField: 'dc.date.accessioned' + topLevelCommunityList: + # No. of communities to list per page on the home page + # This will always round to the nearest number from the list of page sizes. e.g. if you set it to 7 it'll use 10 + pageSize: 5 # Item Config item: @@ -268,10 +279,3 @@ mediaViewer: info: enableEndUserAgreement: true enablePrivacyStatement: true -# Home Page -homePage: - recentSubmissions: - # The number of item showing in recent submission components - pageSize: 5 - # Sort record of recent submission - sortField: 'dc.date.accessioned' diff --git a/src/app/community-list-page/community-list-service.spec.ts b/src/app/community-list-page/community-list-service.spec.ts index 401ffe0b11..410dd9f804 100644 --- a/src/app/community-list-page/community-list-service.spec.ts +++ b/src/app/community-list-page/community-list-service.spec.ts @@ -15,6 +15,8 @@ import { Collection } from '../core/shared/collection.model'; import { PageInfo } from '../core/shared/page-info.model'; import { FlatNode } from './flat-node.model'; import { FindListOptions } from '../core/data/find-list-options.model'; +import { APP_CONFIG } from 'src/config/app-config.interface'; +import { environment } from 'src/environments/environment.test'; describe('CommunityListService', () => { let store: StoreMock; @@ -191,13 +193,14 @@ describe('CommunityListService', () => { }; TestBed.configureTestingModule({ providers: [CommunityListService, + { provide: APP_CONFIG, useValue: environment }, { provide: CollectionDataService, useValue: collectionDataServiceStub }, { provide: CommunityDataService, useValue: communityDataServiceStub }, { provide: Store, useValue: StoreMock }, ], }); store = TestBed.inject(Store as any); - service = new CommunityListService(communityDataServiceStub, collectionDataServiceStub, store); + service = new CommunityListService(environment, communityDataServiceStub, collectionDataServiceStub, store); }); it('should create', inject([CommunityListService], (serviceIn: CommunityListService) => { diff --git a/src/app/community-list-page/community-list-service.ts b/src/app/community-list-page/community-list-service.ts index 07080d712f..99e9dbeb0d 100644 --- a/src/app/community-list-page/community-list-service.ts +++ b/src/app/community-list-page/community-list-service.ts @@ -1,5 +1,5 @@ /* eslint-disable max-classes-per-file */ -import { Injectable } from '@angular/core'; +import { Inject, Injectable } from '@angular/core'; import { createSelector, Store } from '@ngrx/store'; import { combineLatest as observableCombineLatest, Observable, of as observableOf } from 'rxjs'; @@ -23,7 +23,7 @@ import { followLink } from '../shared/utils/follow-link-config.model'; import { FlatNode } from './flat-node.model'; import { ShowMoreFlatNode } from './show-more-flat-node.model'; import { FindListOptions } from '../core/data/find-list-options.model'; -import { environment } from 'src/environments/environment'; +import { AppConfig, APP_CONFIG } from 'src/config/app-config.interface'; // Helper method to combine an flatten an array of observables of flatNode arrays export const combineAndFlatten = (obsList: Observable[]): Observable => @@ -81,8 +81,6 @@ const communityListStateSelector = (state: AppState) => state.communityList; const expandedNodesSelector = createSelector(communityListStateSelector, (communityList: CommunityListState) => communityList.expandedNodes); const loadingNodeSelector = createSelector(communityListStateSelector, (communityList: CommunityListState) => communityList.loadingNode); -export const MAX_COMCOLS_PER_PAGE = environment.browseCommunities.communityListPageSize; - /** * Service class for the community list, responsible for the creating of the flat list used by communityList dataSource * and connection to the store to retrieve and save the state of the community list @@ -90,8 +88,15 @@ export const MAX_COMCOLS_PER_PAGE = environment.browseCommunities.communityListP @Injectable() export class CommunityListService { - constructor(private communityDataService: CommunityDataService, private collectionDataService: CollectionDataService, - private store: Store) { + private pageSize: number; + + constructor( + @Inject(APP_CONFIG) protected appConfig: AppConfig, + private communityDataService: CommunityDataService, + private collectionDataService: CollectionDataService, + private store: Store + ) { + this.pageSize = appConfig.communityList.pageSize; } private configOnePage: FindListOptions = Object.assign(new FindListOptions(), { @@ -146,7 +151,7 @@ export class CommunityListService { private getTopCommunities(options: FindListOptions): Observable> { return this.communityDataService.findTop({ currentPage: options.currentPage, - elementsPerPage: MAX_COMCOLS_PER_PAGE, + elementsPerPage: this.pageSize, sort: { field: options.sort.field, direction: options.sort.direction @@ -217,7 +222,7 @@ export class CommunityListService { let subcoms = []; for (let i = 1; i <= currentCommunityPage; i++) { const nextSetOfSubcommunitiesPage = this.communityDataService.findByParent(community.uuid, { - elementsPerPage: MAX_COMCOLS_PER_PAGE, + elementsPerPage: this.pageSize, currentPage: i }, followLink('subcommunities', { findListOptions: this.configOnePage }), @@ -242,7 +247,7 @@ export class CommunityListService { let collections = []; for (let i = 1; i <= currentCollectionPage; i++) { const nextSetOfCollectionsPage = this.collectionDataService.findByParent(community.uuid, { - elementsPerPage: MAX_COMCOLS_PER_PAGE, + elementsPerPage: this.pageSize, currentPage: i }) .pipe( diff --git a/src/app/home-page/top-level-community-list/top-level-community-list.component.spec.ts b/src/app/home-page/top-level-community-list/top-level-community-list.component.spec.ts index 17feaa9bbf..fcddccd89e 100644 --- a/src/app/home-page/top-level-community-list/top-level-community-list.component.spec.ts +++ b/src/app/home-page/top-level-community-list/top-level-community-list.component.spec.ts @@ -32,6 +32,8 @@ import { SearchConfigurationService } from '../../core/shared/search/search-conf import { ConfigurationProperty } from '../../core/shared/configuration-property.model'; import { createPaginatedList } from '../../shared/testing/utils.test'; import { SearchConfigurationServiceStub } from '../../shared/testing/search-configuration-service.stub'; +import { APP_CONFIG } from 'src/config/app-config.interface'; +import { environment } from 'src/environments/environment.test'; describe('TopLevelCommunityList Component', () => { let comp: TopLevelCommunityListComponent; @@ -151,6 +153,7 @@ describe('TopLevelCommunityList Component', () => { ], declarations: [TopLevelCommunityListComponent], providers: [ + { provide: APP_CONFIG, useValue: environment }, { provide: CommunityDataService, useValue: communityDataServiceStub }, { provide: HostWindowService, useValue: new HostWindowServiceStub(0) }, { provide: PaginationService, useValue: paginationService }, diff --git a/src/app/home-page/top-level-community-list/top-level-community-list.component.ts b/src/app/home-page/top-level-community-list/top-level-community-list.component.ts index 662e9361de..7d58f57196 100644 --- a/src/app/home-page/top-level-community-list/top-level-community-list.component.ts +++ b/src/app/home-page/top-level-community-list/top-level-community-list.component.ts @@ -1,4 +1,4 @@ -import { ChangeDetectionStrategy, Component, OnInit, OnDestroy } from '@angular/core'; +import { ChangeDetectionStrategy, Component, OnInit, OnDestroy, Inject } from '@angular/core'; import { BehaviorSubject, combineLatest as observableCombineLatest, Subscription } from 'rxjs'; @@ -12,7 +12,7 @@ import { PaginationComponentOptions } from '../../shared/pagination/pagination-c import { hasValue } from '../../shared/empty.util'; import { switchMap } from 'rxjs/operators'; import { PaginationService } from '../../core/pagination/pagination.service'; -import { environment } from 'src/environments/environment'; +import { AppConfig, APP_CONFIG } from 'src/config/app-config.interface'; /** * this component renders the Top-Level Community list @@ -51,11 +51,14 @@ export class TopLevelCommunityListComponent implements OnInit, OnDestroy { */ currentPageSubscription: Subscription; - constructor(private cds: CommunityDataService, - private paginationService: PaginationService) { + constructor( + @Inject(APP_CONFIG) protected appConfig: AppConfig, + private cds: CommunityDataService, + private paginationService: PaginationService + ) { this.config = new PaginationComponentOptions(); this.config.id = this.pageId; - this.config.pageSize = environment.browseCommunities.topLevelPageSize; + this.config.pageSize = appConfig.homePage.topLevelCommunityList.pageSize; this.config.currentPage = 1; this.sortConfig = new SortOptions('dc.title', SortDirection.ASC); } diff --git a/src/config/app-config.interface.ts b/src/config/app-config.interface.ts index 5794fe3ac1..6fe55aa328 100644 --- a/src/config/app-config.interface.ts +++ b/src/config/app-config.interface.ts @@ -17,7 +17,9 @@ import { BrowseByConfig } from './browse-by-config.interface'; import { BundleConfig } from './bundle-config.interface'; import { ActuatorsConfig } from './actuators.config'; import { InfoConfig } from './info-config.interface'; +import { CommunityListConfig } from './community-list-config.interface'; import { HomeConfig } from './homepage-config.interface'; + interface AppConfig extends Config { ui: UIServerConfig; rest: ServerConfig; @@ -31,7 +33,8 @@ interface AppConfig extends Config { defaultLanguage: string; languages: LangConfig[]; browseBy: BrowseByConfig; - browseCommunities: BrowseCommunitiesConfig; + communityList: CommunityListConfig; + homePage: HomeConfig; item: ItemConfig; collection: CollectionPageConfig; themes: ThemeConfig[]; @@ -39,7 +42,6 @@ interface AppConfig extends Config { bundle: BundleConfig; actuators: ActuatorsConfig info: InfoConfig; - homePage: HomeConfig; } /** diff --git a/src/config/browse-communities-config.interface.ts b/src/config/browse-communities-config.interface.ts deleted file mode 100644 index 201a8235e0..0000000000 --- a/src/config/browse-communities-config.interface.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { Config } from './config.interface'; - -export interface BrowseCommunitiesConfig extends Config { - /** - * Number of entries in the expandable community list (per show more). - */ - communityListPageSize: number; - /** - * Number of entries in the paginated (home page) top level community list. - */ - topLevelPageSize: number; -} diff --git a/src/config/community-list-config.interface.ts b/src/config/community-list-config.interface.ts new file mode 100644 index 0000000000..5263e9e748 --- /dev/null +++ b/src/config/community-list-config.interface.ts @@ -0,0 +1,5 @@ +import { Config } from './config.interface'; + +export interface CommunityListConfig extends Config { + pageSize: number; +} diff --git a/src/config/default-app-config.ts b/src/config/default-app-config.ts index 81bb1b1ab5..9bb16250fb 100644 --- a/src/config/default-app-config.ts +++ b/src/config/default-app-config.ts @@ -17,7 +17,9 @@ import { UIServerConfig } from './ui-server-config.interface'; import { BundleConfig } from './bundle-config.interface'; import { ActuatorsConfig } from './actuators.config'; import { InfoConfig } from './info-config.interface'; +import { CommunityListConfig } from './community-list-config.interface'; import { HomeConfig } from './homepage-config.interface'; + export class DefaultAppConfig implements AppConfig { production = false; @@ -210,10 +212,21 @@ export class DefaultAppConfig implements AppConfig { defaultLowerLimit: 1900 }; - browseCommunities: BrowseCommunitiesConfig = { - communityListPageSize: 20, - topLevelPageSize: 5 - } + communityList: CommunityListConfig = { + pageSize: 20 + }; + + homePage: HomeConfig = { + recentSubmissions: { + //The number of item showing in recent submission components + pageSize: 5, + //sort record of recent submission + sortField: 'dc.date.accessioned', + }, + topLevelCommunityList: { + pageSize: 5 + } + }; // Item Config item: ItemConfig = { @@ -345,13 +358,4 @@ export class DefaultAppConfig implements AppConfig { enableEndUserAgreement: true, enablePrivacyStatement: true }; - // Home Pages - homePage: HomeConfig = { - recentSubmissions: { - //The number of item showing in recent submission components - pageSize: 5, - //sort record of recent submission - sortField: 'dc.date.accessioned', - } - }; } diff --git a/src/config/homepage-config.interface.ts b/src/config/homepage-config.interface.ts index 1f955358e0..df5d29cfe0 100644 --- a/src/config/homepage-config.interface.ts +++ b/src/config/homepage-config.interface.ts @@ -16,5 +16,7 @@ export interface HomeConfig extends Config { sortField: string; } - + topLevelCommunityList: { + pageSize: number; + }; } diff --git a/src/environments/environment.test.ts b/src/environments/environment.test.ts index a0b382ec7c..733c4b308c 100644 --- a/src/environments/environment.test.ts +++ b/src/environments/environment.test.ts @@ -204,9 +204,18 @@ export const environment: BuildConfig = { // The absolute lowest year to display in the dropdown (only used when no lowest date can be found for all items) defaultLowerLimit: 1900, }, - browseCommunities: { - communityListPageSize: 20, - topLevelPageSize: 5 + communityList: { + pageSize: 20 + }, + homePage: { + recentSubmissions: { + pageSize: 5, + //sort record of recent submission + sortField: 'dc.date.accessioned', + }, + topLevelCommunityList: { + pageSize: 5 + } }, item: { edit: { @@ -256,12 +265,4 @@ export const environment: BuildConfig = { enableEndUserAgreement: true, enablePrivacyStatement: true, }, - //Home Page - homePage: { - recentSubmissions: { - pageSize: 5, - //sort record of recent submission - sortField: 'dc.date.accessioned', - } - } };