Skip to content

Commit

Permalink
Merge pull request #508 from geonetwork/orgs-from-groups
Browse files Browse the repository at this point in the history
Add the possibility to load organizations from group instead of metadata
  • Loading branch information
jahow committed Jun 21, 2023
2 parents 71545b9 + 48e5506 commit 4f619f6
Show file tree
Hide file tree
Showing 54 changed files with 2,216 additions and 1,154 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'
import { KeyFiguresComponent } from './key-figures.component'
import { of } from 'rxjs'
import {
OrganisationsService,
OrganisationsServiceInterface,
RecordsService,
} from '@geonetwork-ui/feature/catalog'
import { TranslateModule } from '@ngx-translate/core'
Expand Down Expand Up @@ -32,7 +32,7 @@ describe('KeyFiguresComponent', () => {
useClass: RecordsServiceMock,
},
{
provide: OrganisationsService,
provide: OrganisationsServiceInterface,
useClass: OrganisationsServiceMock,
},
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core'
import { ChangeDetectionStrategy, Component } from '@angular/core'
import { startWith } from 'rxjs/operators'
import {
OrganisationsService,
OrganisationsServiceInterface,
RecordsService,
} from '@geonetwork-ui/feature/catalog'
import { ROUTER_ROUTE_SEARCH } from '@geonetwork-ui/feature/router'
Expand All @@ -24,6 +24,6 @@ export class KeyFiguresComponent {

constructor(
private catalogRecords: RecordsService,
private catalogOrgs: OrganisationsService
private catalogOrgs: OrganisationsServiceInterface
) {}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<div class="container-lg mx-auto mt-8">
<gn-ui-organisations></gn-ui-organisations>
<gn-ui-organisations
(orgSelect)="searchByOrganisation($event)"
></gn-ui-organisations>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,47 @@ import { NO_ERRORS_SCHEMA } from '@angular/core'
import { ComponentFixture, TestBed } from '@angular/core/testing'

import { OrganisationsPageComponent } from './organisations-page.component'
import { SearchService } from '@geonetwork-ui/feature/search'
import { OrganisationsServiceInterface } from '@geonetwork-ui/feature/catalog'
import { of } from 'rxjs'

class SearchServiceMock {
setFilters = jest.fn()
}

class OrganisationsServiceMock {
getFiltersForOrgs = jest.fn((orgs) =>
of({
orgs: orgs.reduce((prev, curr) => ({ ...prev, [curr.name]: true }), {}),
})
)
}

describe('OrganisationsPageComponent', () => {
let component: OrganisationsPageComponent
let fixture: ComponentFixture<OrganisationsPageComponent>
let searchService: SearchService
let orgsService: OrganisationsServiceInterface

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [OrganisationsPageComponent],
schemas: [NO_ERRORS_SCHEMA],
providers: [
{
provide: SearchService,
useClass: SearchServiceMock,
},
{
provide: OrganisationsServiceInterface,
useClass: OrganisationsServiceMock,
},
],
}).compileComponents()

searchService = TestBed.inject(SearchService)
orgsService = TestBed.inject(OrganisationsServiceInterface)

fixture = TestBed.createComponent(OrganisationsPageComponent)
component = fixture.componentInstance
fixture.detectChanges()
Expand All @@ -21,4 +51,24 @@ describe('OrganisationsPageComponent', () => {
it('should create', () => {
expect(component).toBeTruthy()
})

describe('#searchByOrganisation', () => {
beforeEach(() => {
component.searchByOrganisation({
name: 'MyOrg',
})
})
it('generates filters for the org', () => {
expect(orgsService.getFiltersForOrgs).toHaveBeenCalledWith([
{ name: 'MyOrg' },
])
})
it('updates filters to filter on the org', () => {
expect(searchService.setFilters).toHaveBeenCalledWith({
orgs: {
MyOrg: true,
},
})
})
})
})
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
import { ChangeDetectionStrategy, Component } from '@angular/core'
import { Organisation } from '@geonetwork-ui/util/shared'
import { SearchService } from '@geonetwork-ui/feature/search'
import { OrganisationsServiceInterface } from '@geonetwork-ui/feature/catalog'

@Component({
selector: 'datahub-organisations-page',
templateUrl: './organisations-page.component.html',
styleUrls: ['./organisations-page.component.css'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class OrganisationsPageComponent {}
export class OrganisationsPageComponent {
constructor(
private searchService: SearchService,
private orgsService: OrganisationsServiceInterface
) {}

searchByOrganisation(organisation: Organisation) {
this.orgsService
.getFiltersForOrgs([organisation])
.subscribe((filters) => this.searchService.setFilters(filters))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
AggregationsTypesEnum,
SearchFilters,
} from '@geonetwork-ui/util/shared'
import { BehaviorSubject } from 'rxjs'
import { BehaviorSubject, of } from 'rxjs'
import { SearchFiltersComponent } from './search-filters.component'
import { TranslateModule } from '@ngx-translate/core'
import { By } from '@angular/platform-browser'
Expand Down Expand Up @@ -66,9 +66,17 @@ class SearchServiceMock {
}

class FieldsServiceMock {
getFiltersForValues = jest.fn((fieldName, values) => ({
['filter_' + fieldName]: {},
}))
buildFiltersFromFieldValues = jest.fn((fieldValues) =>
of(
Object.keys(fieldValues).reduce(
(prev, curr) => ({
...prev,
['filter_' + curr]: {},
}),
{}
)
)
)
}

describe('SearchFiltersComponent', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ export class SearchFiltersComponent {
}

clearFilters() {
const filters = this.filters.reduce(
(prev, curr) => ({
...prev,
...this.fieldsService.getFiltersForValues(curr.fieldName, []),
}),
const fieldNames = this.filters.map((component) => component.fieldName)
const fieldValues = fieldNames.reduce(
(prev, curr) => ({ ...prev, [curr]: [] }),
{}
)
this.searchService.updateFilters(filters)
this.fieldsService
.buildFiltersFromFieldValues(fieldValues)
.subscribe((filters) => {
this.searchService.updateFilters(filters)
})
}
}
2 changes: 1 addition & 1 deletion libs/feature/catalog/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ export * from './lib/feature-catalog.module'
export * from './lib/sources/sources.service'
export * from './lib/sources/sources.model'
export * from './lib/records/records.service'
export * from './lib/organisations/organisations.service'
export * from './lib/organisations/service'
51 changes: 49 additions & 2 deletions libs/feature/catalog/src/lib/feature-catalog.module.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,48 @@
import { NgModule } from '@angular/core'
import { SiteTitleComponent } from './site-title/site-title.component'
import { UiCatalogModule } from '@geonetwork-ui/ui/catalog'
import { ApiModule } from '@geonetwork-ui/data-access/gn4'
import {
ApiModule,
GroupsApiService,
SearchApiService,
} from '@geonetwork-ui/data-access/gn4'
import { CommonModule } from '@angular/common'
import { SourceLabelComponent } from './source-label/source-label.component'
import { UtilI18nModule } from '@geonetwork-ui/util/i18n'
import { OrganisationsComponent } from './organisations/organisations.component'
import { UiLayoutModule } from '@geonetwork-ui/ui/layout'
import { TranslateModule } from '@ngx-translate/core'
import { TranslateModule, TranslateService } from '@ngx-translate/core'
import { UiElementsModule } from '@geonetwork-ui/ui/elements'
import {
OrganisationsFromMetadataService,
OrganisationsServiceInterface,
} from './organisations/service'
import {
ElasticsearchService,
ORGANIZATIONS_STRATEGY,
OrganizationsStrategy,
} from '@geonetwork-ui/util/shared'
import { OrganisationsFromGroupsService } from './organisations/service/organisations-from-groups.service'

const organizationsServiceFactory = (
strategy: OrganizationsStrategy,
esService: ElasticsearchService,
searchApiService: SearchApiService,
groupsApiService: GroupsApiService,
translateService: TranslateService
) =>
strategy === 'groups'
? new OrganisationsFromGroupsService(
esService,
searchApiService,
groupsApiService,
translateService
)
: new OrganisationsFromMetadataService(
esService,
searchApiService,
groupsApiService
)

@NgModule({
declarations: [
Expand All @@ -26,5 +60,18 @@ import { UiElementsModule } from '@geonetwork-ui/ui/elements'
UiElementsModule,
],
exports: [SiteTitleComponent, SourceLabelComponent, OrganisationsComponent],
providers: [
{
provide: OrganisationsServiceInterface,
useFactory: organizationsServiceFactory,
deps: [
ORGANIZATIONS_STRATEGY,
ElasticsearchService,
SearchApiService,
GroupsApiService,
TranslateService,
],
},
],
})
export class FeatureCatalogModule {}
44 changes: 0 additions & 44 deletions libs/feature/catalog/src/lib/group/group.service.spec.ts

This file was deleted.

15 changes: 0 additions & 15 deletions libs/feature/catalog/src/lib/group/group.service.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
class="h-[300px]"
ghostClass="h-full mb-36"
*ngFor="let organisation of organisations$ | async; trackBy: trackByIndex"
[showContent]="organisation.description !== null"
[showContent]="!!organisation.name"
>
<gn-ui-organisation-preview
[organisation]="organisation"
(clickedOrganisation)="searchByOrganisation($event)"
(clickedOrganisation)="orgSelect.emit($event)"
></gn-ui-organisation-preview>
</gn-ui-content-ghost>
</div>
Expand Down
Loading

0 comments on commit 4f619f6

Please sign in to comment.