Skip to content

Commit

Permalink
fix: records, i18n, test
Browse files Browse the repository at this point in the history
  • Loading branch information
f-necas committed Oct 4, 2023
1 parent fa6bc61 commit e92361e
Show file tree
Hide file tree
Showing 16 changed files with 80 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,18 @@ <h2 class="text-xl mr-4 font-title" translate>
(toggled)="toggleSpatialFilter($event)"
></gn-ui-check-toggle>
</div>
<div class="sm:col-span-2" *ngIf="userId">
<div class="sm:col-span-2" *ngIf="userId && isOpen">
<gn-ui-check-toggle
[title]="'search.filters.myRecordsHelp' | translate"
[label]="'search.filters.myRecords' | translate"
[color]="'secondary'"
[value]="myRecordsFilterEnabled() | async"
[value]="myRecordsFilterEnabled$ | async"
(toggled)="toggleMyRecordsFilter($event)"
></gn-ui-check-toggle>
</div>
<div
class="sm:col-span-2"
*ngIf="!userId && (myRecordsFilterEnabled() | async)"
*ngIf="!userId && (myRecordsFilterEnabled$ | async) && isOpen"
>
<gn-ui-button
type="light"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ describe('SearchFiltersComponent', () => {
fixture.detectChanges()
})
it('does not show up', () => {
expect(getCheckToggleDebugElement().length).toBe(1)
expect(getCheckToggleDebugElement().length).toBeFalsy()
})
})
describe('when panel is opened & a spatial filter is unavailable', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
SearchService,
} from '@geonetwork-ui/feature/search'
import { getOptionalSearchConfig } from '@geonetwork-ui/util/app-config'
import { switchMap } from 'rxjs'
import { Observable, switchMap } from 'rxjs'
import { map } from 'rxjs/operators'

@Component({
Expand All @@ -28,6 +28,17 @@ export class SearchFiltersComponent implements OnInit {
searchConfig: { fieldName: string; title: string }[]
isOpen = false
userId: string
myRecordsFilterEnabled$: Observable<boolean> =
this.searchFacade.searchFilters$.pipe(
switchMap((filters) => {
return this.fieldsService.readFieldValuesFromFilters(filters)
}),
map((fieldValues) =>
fieldValues['owner'] && Array.isArray(fieldValues['owner'])
? fieldValues['owner'].length > 0
: !!fieldValues['owner']
)
)

constructor(
public searchFacade: SearchFacade,
Expand Down Expand Up @@ -82,20 +93,6 @@ export class SearchFiltersComponent implements OnInit {
.subscribe((filters) => this.searchService.updateFilters(filters))
}

myRecordsFilterEnabled() {
return this.searchFacade.searchFilters$.pipe(
switchMap((filters) => {
return this.fieldsService.readFieldValuesFromFilters(filters)
}),
map((fieldValues) => {
if (fieldValues['owner'] && Array.isArray(fieldValues['owner'])) {
return fieldValues['owner'].length > 0
}
return !!fieldValues['owner']
})
)
}

clearFilters() {
const fieldNames = this.filters.map((component) => component.fieldName)
const fieldValues = fieldNames.reduce(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ComponentFixture, TestBed } from '@angular/core/testing'
import { MyRecordsComponent } from './my-records.component'
import { SearchFacade } from '@geonetwork-ui/feature/search'
import { FieldsService, SearchFacade } from '@geonetwork-ui/feature/search'
import { Component, importProvidersFrom, Input } from '@angular/core'
import { TranslateModule } from '@ngx-translate/core'
import { RecordsListComponent } from '../records-list.component'
import { BehaviorSubject } from 'rxjs'
import { BehaviorSubject, of } from 'rxjs'
import { USER_FIXTURE } from '@geonetwork-ui/common/fixtures'
import { AuthService } from '@geonetwork-ui/api/repository/gn4'
import { EditorRouterService } from '../../router.service'
Expand Down Expand Up @@ -33,6 +33,11 @@ class AuthServiceMock {
authReady = jest.fn(() => this._authSubject$)
_authSubject$ = new BehaviorSubject({})
}

class FieldsServiceMock {
buildFiltersFromFieldValues = jest.fn((val) => of(val))
}

describe('MyRecordsComponent', () => {
let component: MyRecordsComponent
let fixture: ComponentFixture<MyRecordsComponent>
Expand All @@ -42,6 +47,10 @@ describe('MyRecordsComponent', () => {
TestBed.configureTestingModule({
providers: [
importProvidersFrom(TranslateModule.forRoot()),
{
provide: FieldsService,
useClass: FieldsServiceMock,
},
{
provide: SearchFacade,
useClass: SearchFacadeMock,
Expand Down Expand Up @@ -86,7 +95,9 @@ describe('MyRecordsComponent', () => {

describe('datahub url', () => {
it('get correct url', () => {
expect(component.getDatahubUrl()).toEqual('/datahub/?owner=46798')
expect(component.getDatahubUrl()).toEqual(
'http://localhost/datahub/?owner=46798'
)
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Component, OnDestroy, OnInit } from '@angular/core'
import { CommonModule } from '@angular/common'
import { TranslateModule } from '@ngx-translate/core'
import { RecordsListComponent } from '../records-list.component'
import { SearchFacade } from '@geonetwork-ui/feature/search'
import { FieldsService, SearchFacade } from '@geonetwork-ui/feature/search'
import { AuthService } from '@geonetwork-ui/api/repository/gn4'
import { EditorRouterService } from '../../router.service'
import { Subscription } from 'rxjs'
Expand All @@ -19,6 +19,7 @@ export class MyRecordsComponent implements OnInit, OnDestroy {
private ownerId: string

constructor(
public fieldsService: FieldsService,
public searchFacade: SearchFacade,
private authService: AuthService,
private router: EditorRouterService
Expand All @@ -28,12 +29,23 @@ export class MyRecordsComponent implements OnInit, OnDestroy {
this.searchFacade.resetSearch()
this.sub = this.authService.user$.subscribe((user) => {
this.ownerId = user.id
this.searchFacade.updateFilters({ owner: user.id })
this.fieldsService
.buildFiltersFromFieldValues({ owner: user.id })
.subscribe((filters) => {
this.searchFacade.updateFilters(filters)
})
})
}

getDatahubUrl(): string {
return `${this.router.getDatahubSearchRoute()}?owner=${this.ownerId}`
const url = new URL(
`${this.router.getDatahubSearchRoute()}`,
this.router.getDatahubSearchRoute().startsWith('http')
? this.router.getDatahubSearchRoute()
: window.location.toString()
)
url.searchParams.append('owner', this.ownerId)
return url.toString()
}

ngOnDestroy(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
<div class="flex justify-center gap-8 items-baseline">
<h1 class="text-[56px] font-title grow">{{ title }}</h1>
<a
class="text-[30px]"
class="text-[30px] hover:underline"
*ngIf="linkToDatahub"
[href]="linkToDatahub"
target="_blank"
>
{{ searchFacade.resultsHits$ | async }}
<span>{{ 'record.metadata.publications' | translate }}</span>
</a>
</div>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { SearchFacade, SearchService } from '@geonetwork-ui/feature/search'
import { UiSearchModule } from '@geonetwork-ui/ui/search'
import { UiElementsModule } from '@geonetwork-ui/ui/elements'
import { SortByField } from '@geonetwork-ui/common/domain/search'
import { TranslateModule } from '@ngx-translate/core'

const includes = [
'uuid',
Expand All @@ -25,7 +26,13 @@ const includes = [
templateUrl: './records-list.component.html',
styleUrls: ['./records-list.component.css'],
standalone: true,
imports: [CommonModule, MatIconModule, UiSearchModule, UiElementsModule],
imports: [
CommonModule,
MatIconModule,
UiSearchModule,
UiElementsModule,
TranslateModule,
],
})
export class RecordsListComponent {
@Input() title: string
Expand Down
1 change: 0 additions & 1 deletion libs/feature/search/src/lib/state/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ export class SetSpatialFilterEnabled extends AbstractAction implements Action {
super(id)
}
}

export type SearchActions =
| AddSearch
| SetConfigFilters
Expand Down
4 changes: 4 additions & 0 deletions libs/feature/search/src/lib/utils/service/search.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,8 @@ export class SearchService implements SearchServiceI {
setPage(page: number): void {
this.facade.paginate(page)
}

resetSearch(): void {
this.facade.resetSearch()
}
}
4 changes: 3 additions & 1 deletion translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@
"search.error.receivedError": "Ein Fehler wurde empfangen",
"search.error.recordNotFound": "Der Datensatz mit der Kennung \"{ id }\" konnte nicht gefunden werden.",
"search.field.any.placeholder": "Suche nach Datensätzen, Diensten und Karten ...",
"search.field.location.placeholder": "",
"search.field.sortBy": "Sortieren nach:",
"search.filters.clear": "Zurücksetzen",
"search.filters.format": "Formate",
Expand All @@ -231,6 +230,9 @@
"search.filters.license.unknown": "Unbekannt oder nicht vorhanden",
"search.filters.maximize": "Erweitern",
"search.filters.minimize": "Minimieren",
"search.filters.myRecords": "",
"search.filters.myRecordsHelp": "",
"search.filters.otherRecords": "",
"search.filters.publisher": "Organisationen",
"search.filters.representationType": "",
"search.filters.resourceType": "",
Expand Down
7 changes: 3 additions & 4 deletions translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@
"search.error.receivedError": "An error was received",
"search.error.recordNotFound": "The record with identifier \"{ id }\" could not be found.",
"search.field.any.placeholder": "Search datasets, services and maps ...",
"search.field.location.placeholder": "",
"search.field.sortBy": "Sort by:",
"search.filters.clear": "Reset",
"search.filters.format": "Formats",
Expand All @@ -231,13 +230,13 @@
"search.filters.license.unknown": "Unknown or absent",
"search.filters.maximize": "Expand",
"search.filters.minimize": "Minimize",
"search.filters.myRecords": "Show only my records",
"search.filters.myRecordsHelp": "When this is enabled, records only created by myself are shown; records created by others will not show up.",
"search.filters.otherRecords": "Showing records from another person",
"search.filters.publisher": "Organizations",
"search.filters.representationType": "Representation type",
"search.filters.resourceType": "Resource type",
"search.filters.standard": "Standard",
"search.filters.myRecords": "Show only my records",
"search.filters.myRecordsHelp": "When this is enabled, records only created by myself are shown; records created by others will not show up.",
"search.filters.otherRecords": "Showing records from another person",
"search.filters.title": "Filter your results",
"search.filters.topic": "Topic",
"search.filters.useSpatialFilter": "Show records in the area of interest first",
Expand Down
4 changes: 3 additions & 1 deletion translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@
"search.error.receivedError": "",
"search.error.recordNotFound": "",
"search.field.any.placeholder": "",
"search.field.location.placeholder": "",
"search.field.sortBy": "",
"search.filters.clear": "",
"search.filters.format": "",
Expand All @@ -231,6 +230,9 @@
"search.filters.license.unknown": "",
"search.filters.maximize": "",
"search.filters.minimize": "",
"search.filters.myRecords": "",
"search.filters.myRecordsHelp": "",
"search.filters.otherRecords": "",
"search.filters.publisher": "",
"search.filters.representationType": "",
"search.filters.resourceType": "",
Expand Down
4 changes: 3 additions & 1 deletion translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@
"search.error.receivedError": "Erreur retournée",
"search.error.recordNotFound": "Cette donnée n'a pu être trouvée.",
"search.field.any.placeholder": "Rechercher une fiche de métadonnée...",
"search.field.location.placeholder": "",
"search.field.sortBy": "Trier par :",
"search.filters.clear": "Réinitialiser",
"search.filters.format": "Formats",
Expand All @@ -231,6 +230,9 @@
"search.filters.license.unknown": "Non-reconnue ou absente",
"search.filters.maximize": "Agrandir",
"search.filters.minimize": "Réduire",
"search.filters.myRecords": "Voir mes données",
"search.filters.myRecordsHelp": "Quand activé, n'affiche que les données créées avec mon utilisateur. Les données créées par les autres utilisateurs ne sont pas affichées.",
"search.filters.otherRecords": "Affichage des données d'un autre utilisateur",
"search.filters.publisher": "Organisations",
"search.filters.representationType": "Type de représentation",
"search.filters.resourceType": "Type de ressource",
Expand Down
4 changes: 3 additions & 1 deletion translations/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@
"search.error.receivedError": "",
"search.error.recordNotFound": "",
"search.field.any.placeholder": "",
"search.field.location.placeholder": "",
"search.field.sortBy": "",
"search.filters.clear": "",
"search.filters.format": "",
Expand All @@ -231,6 +230,9 @@
"search.filters.license.unknown": "",
"search.filters.maximize": "",
"search.filters.minimize": "",
"search.filters.myRecords": "",
"search.filters.myRecordsHelp": "",
"search.filters.otherRecords": "",
"search.filters.publisher": "",
"search.filters.representationType": "",
"search.filters.resourceType": "",
Expand Down
4 changes: 3 additions & 1 deletion translations/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@
"search.error.receivedError": "",
"search.error.recordNotFound": "",
"search.field.any.placeholder": "",
"search.field.location.placeholder": "",
"search.field.sortBy": "",
"search.filters.clear": "",
"search.filters.format": "",
Expand All @@ -231,6 +230,9 @@
"search.filters.license.unknown": "",
"search.filters.maximize": "",
"search.filters.minimize": "",
"search.filters.myRecords": "",
"search.filters.myRecordsHelp": "",
"search.filters.otherRecords": "",
"search.filters.publisher": "",
"search.filters.representationType": "",
"search.filters.resourceType": "",
Expand Down
4 changes: 3 additions & 1 deletion translations/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@
"search.error.receivedError": "",
"search.error.recordNotFound": "",
"search.field.any.placeholder": "",
"search.field.location.placeholder": "",
"search.field.sortBy": "",
"search.filters.clear": "",
"search.filters.format": "",
Expand All @@ -231,6 +230,9 @@
"search.filters.license.unknown": "",
"search.filters.maximize": "",
"search.filters.minimize": "",
"search.filters.myRecords": "",
"search.filters.myRecordsHelp": "",
"search.filters.otherRecords": "",
"search.filters.publisher": "",
"search.filters.representationType": "",
"search.filters.resourceType": "",
Expand Down

0 comments on commit e92361e

Please sign in to comment.