diff --git a/apps/datahub/src/app/organization/organization-details/organization-details.component.html b/apps/datahub/src/app/organization/organization-details/organization-details.component.html index 5391a405be..bfba23a856 100644 --- a/apps/datahub/src/app/organization/organization-details/organization-details.component.html +++ b/apps/datahub/src/app/organization/organization-details/organization-details.component.html @@ -1,4 +1,6 @@ - +
@@ -21,7 +23,7 @@ >
{ const orgHasNoDataset = getHTMLElement('lastPubliDatasets') - console.log(orgHasNoDataset?.outerHTML) - expect(orgHasNoDataset).toBeTruthy() }) }) }) + + describe('when organization changes', () => { + const anotherOrg = someOrganizationsFixture()[1] + beforeEach(() => { + jest.clearAllMocks() + component.organization = anotherOrg + fixture.detectChanges() + }) + it('updates the search filters', () => { + expect(searchFacade.setFilters).toHaveBeenCalledWith({ + orgs: { + [anotherOrg.name]: true, + }, + }) + }) + }) }) diff --git a/apps/datahub/src/app/organization/organization-details/organization-details.component.ts b/apps/datahub/src/app/organization/organization-details/organization-details.component.ts index 2656219bee..bcb5553179 100644 --- a/apps/datahub/src/app/organization/organization-details/organization-details.component.ts +++ b/apps/datahub/src/app/organization/organization-details/organization-details.component.ts @@ -1,13 +1,9 @@ import { - AfterViewInit, ChangeDetectionStrategy, - ChangeDetectorRef, Component, Input, - OnChanges, OnDestroy, OnInit, - SimpleChanges, ViewChild, } from '@angular/core' import { AsyncPipe, NgClass, NgForOf, NgIf } from '@angular/common' @@ -39,7 +35,6 @@ import { combineLatest, distinctUntilChanged, Observable, - of, Subscription, switchMap, } from 'rxjs' @@ -48,6 +43,7 @@ import { RouterLink } from '@angular/router' import { ROUTER_ROUTE_SEARCH } from '@geonetwork-ui/feature/router' import { OrganizationsServiceInterface } from '@geonetwork-ui/common/domain/organizations.service.interface' import { UiWidgetsModule } from '@geonetwork-ui/ui/widgets' +import { startWith } from 'rxjs/operators' @Component({ selector: 'datahub-organization-details', @@ -76,10 +72,7 @@ import { UiWidgetsModule } from '@geonetwork-ui/ui/widgets' NgClass, ], }) -export class OrganizationDetailsComponent - implements OnInit, AfterViewInit, OnDestroy, OnChanges -{ - protected readonly Error = Error +export class OrganizationDetailsComponent implements OnInit, OnDestroy { protected readonly ErrorType = ErrorType protected readonly ROUTER_ROUTE_SEARCH = ROUTER_ROUTE_SEARCH @@ -87,8 +80,6 @@ export class OrganizationDetailsComponent return new Array(this.totalPages).fill(0).map((_, i) => i + 1) } - lastPublishedDatasets$: Observable = of([]) - subscriptions$: Subscription = new Subscription() isSearchFacadeLoading = true @@ -98,51 +89,38 @@ export class OrganizationDetailsComponent isFirstPage = this.currentPage === 1 isLastPage = false - organizationHasChanged$ = new BehaviorSubject(undefined) - - @Input() organization?: Organization + currentOrganization$ = new BehaviorSubject(null) + @Input() set organization(value: Organization) { + this.currentOrganization$.next(value) + } @Input() paginationContainerClass = 'w-full bottom-0 top-auto' @ViewChild(BlockListComponent) list: BlockListComponent + lastPublishedDatasets$: Observable = + this.currentOrganization$.pipe( + switchMap((organization) => + this.organizationsService.getFiltersForOrgs([organization]) + ), + switchMap( + (filters) => + this.searchFacade + .setFilters(filters) + .setSortBy(['desc', 'changeDate']).results$ + ), + startWith([]) + ) + constructor( - private changeDetector: ChangeDetectorRef, private searchFacade: SearchFacade, private organizationsService: OrganizationsServiceInterface ) {} ngOnInit(): void { this.searchFacade.setPageSize(3) - - this.lastPublishedDatasets$ = this.organizationHasChanged$.pipe( - distinctUntilChanged(), - switchMap(() => { - return this.organizationsService - .getFiltersForOrgs([this.organization]) - .pipe( - switchMap((filters) => { - return this.searchFacade - .setFilters(filters) - .setSortBy(['desc', 'changeDate']).results$ - }) - ) - }) - ) - this.manageSubscriptions() } - ngOnChanges(changes: SimpleChanges): void { - if (changes['organization']) { - this.organizationHasChanged$.next() - } - } - - ngAfterViewInit() { - // this is required to show the pagination correctly - this.changeDetector.detectChanges() - } - ngOnDestroy(): void { this.subscriptions$.unsubscribe() } diff --git a/translations/en.json b/translations/en.json index 1c0638f91d..05234a5842 100644 --- a/translations/en.json +++ b/translations/en.json @@ -370,8 +370,8 @@ "organisations.sortBy.nameDesc": "Name Z → A", "organisations.sortBy.recordCountAsc": "Publications 0 → 9", "organisations.sortBy.recordCountDesc": "Publications 9 → 0", - "organization.details.lastPublishedDatasets": "", - "organization.details.lastPublishedDatasets.searchAllButton": "", + "organization.details.lastPublishedDatasets": "Last published datasets", + "organization.details.lastPublishedDatasets.searchAllButton": "Search all", "organization.details.mailContact": "Contact by email", "organization.header.recordCount": "{count, plural, =0{data} one{data} other{datas}}", "pagination.nextPage": "Next page", diff --git a/translations/fr.json b/translations/fr.json index 1198b1c383..a773ee3e60 100644 --- a/translations/fr.json +++ b/translations/fr.json @@ -370,8 +370,8 @@ "organisations.sortBy.nameDesc": "Nom Z → A", "organisations.sortBy.recordCountAsc": "Données 0 → 9", "organisations.sortBy.recordCountDesc": "Données 9 → 0", - "organization.details.lastPublishedDatasets": "", - "organization.details.lastPublishedDatasets.searchAllButton": "", + "organization.details.lastPublishedDatasets": "Dernières données publiées", + "organization.details.lastPublishedDatasets.searchAllButton": "Rechercher tout", "organization.details.mailContact": "Contacter par mail", "organization.header.recordCount": "{count, plural, =0{donnée} one{donnée} other{données}}", "pagination.nextPage": "Page suivante",