Skip to content

Commit

Permalink
feat(me): fix mutliple identical searchs in the header + simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
jahow committed Sep 23, 2024
1 parent 9a33ea8 commit a5f8b7b
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<div class="menu-title" translate="">dashboard.labels.catalog</div>
<a
class="menu-item"
(click)="resetMainSearch()"
routerLink="/catalog/search"
routerLinkActive="btn-active"
#rlaAll="routerLinkActive"
Expand Down Expand Up @@ -56,7 +57,6 @@
<div class="menu-title" translate="">dashboard.labels.mySpace</div>
<a
class="menu-item"
(click)="resetMainSearch()"
routerLink="/my-space/my-records"
routerLinkActive="btn-active"
#rlaMyRecords="routerLinkActive"
Expand All @@ -66,7 +66,6 @@
</a>
<a
class="menu-item"
(click)="resetMainSearch()"
routerLink="/my-space/my-draft"
routerLinkActive="btn-active"
#rlaMyDraft="routerLinkActive"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<div class="py-3 px-12 flex justify-between w-full">
<div class="w-2/3">
<!-- FIXME: (itemSelected) should not be required -->
<gn-ui-fuzzy-search
#fuzzySearch
(itemSelected)="handleItemSelection($event)"
style="--gn-ui-text-input-border-size: 0px"
></gn-ui-fuzzy-search>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { CommonModule } from '@angular/common'
import { ChangeDetectionStrategy, Component } from '@angular/core'
import { ChangeDetectionStrategy, Component, ViewChild } from '@angular/core'
import { MatIconModule } from '@angular/material/icon'
import { LetDirective } from '@ngrx/component'
import {
FeatureSearchModule,
FuzzySearchComponent,
SearchService,
} from '@geonetwork-ui/feature/search'
import { UiElementsModule } from '@geonetwork-ui/ui/elements'
import { AvatarServiceInterface } from '@geonetwork-ui/api/repository'
import { PlatformServiceInterface } from '@geonetwork-ui/common/domain/platform.service.interface'
import { TranslateModule } from '@ngx-translate/core'
import { CatalogRecord } from '@geonetwork-ui/common/domain/model/record'
import { RouterFacade } from '@geonetwork-ui/feature/router'

@Component({
selector: 'md-editor-search-header',
Expand All @@ -30,12 +32,18 @@ import { CatalogRecord } from '@geonetwork-ui/common/domain/model/record'
export class SearchHeaderComponent {
public placeholder$ = this.avatarService.getPlaceholder()
activeBtn = false
@ViewChild('fuzzySearch') fuzzySearch: FuzzySearchComponent

constructor(
public platformService: PlatformServiceInterface,
private avatarService: AvatarServiceInterface,
private searchService: SearchService
) {}
private searchService: SearchService,
private routerFacade: RouterFacade
) {
this.routerFacade.currentRoute$.subscribe(() => {
this.fuzzySearch?.autocomplete?.clear()
})
}

handleItemSelection(item: CatalogRecord) {
this.searchService.updateFilters({ any: item.title })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
ChangeDetectorRef,
Component,
ElementRef,
OnInit,
TemplateRef,
ViewChild,
ViewContainerRef,
Expand Down Expand Up @@ -62,7 +61,7 @@ export const allSearchFields = [
RecordsListComponent,
],
})
export class AllRecordsComponent implements OnInit {
export class AllRecordsComponent {
@ViewChild('importRecordButton', { read: ElementRef })
importRecordButton!: ElementRef
@ViewChild('template') template!: TemplateRef<any>
Expand All @@ -85,11 +84,6 @@ export class AllRecordsComponent implements OnInit {
private cdr: ChangeDetectorRef
) {}

ngOnInit(): void {
this.searchFacade.setConfigRequestFields(allSearchFields)
this.searchFacade.setPageSize(15)
}

createRecord() {
this.router.navigate(['/create']).catch((err) => console.error(err))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
ChangeDetectorRef,
Component,
ElementRef,
OnDestroy,
OnInit,
TemplateRef,
ViewChild,
Expand All @@ -17,11 +16,10 @@ import {
ResultsTableContainerComponent,
SearchFacade,
} from '@geonetwork-ui/feature/search'
import { Subscription } from 'rxjs'
import { PlatformServiceInterface } from '@geonetwork-ui/common/domain/platform.service.interface'
import { UiElementsModule } from '@geonetwork-ui/ui/elements'
import { CatalogRecord } from '@geonetwork-ui/common/domain/model/record'
import { ActivatedRoute, Router } from '@angular/router'
import { Router } from '@angular/router'
import { Overlay, OverlayRef } from '@angular/cdk/overlay'
import { TemplatePortal } from '@angular/cdk/portal'
import { allSearchFields } from '../all-records/all-records.component'
Expand All @@ -48,10 +46,7 @@ import { ImportRecordComponent } from '@geonetwork-ui/feature/editor'
FeatureSearchModule,
],
})
export class MyRecordsComponent implements OnInit, OnDestroy {
private sub: Subscription
ownerId: string

export class MyRecordsComponent implements OnInit {
@ViewChild('importRecordButton', { read: ElementRef })
private importRecordButton!: ElementRef
@ViewChild('template') template!: TemplateRef<any>
Expand All @@ -61,7 +56,6 @@ export class MyRecordsComponent implements OnInit, OnDestroy {

constructor(
private router: Router,
private activedRoute: ActivatedRoute,
protected searchFacade: SearchFacade,
private platformService: PlatformServiceInterface,
private fieldsService: FieldsService,
Expand All @@ -74,8 +68,7 @@ export class MyRecordsComponent implements OnInit, OnDestroy {
this.searchFacade.setConfigRequestFields(allSearchFields)
this.searchFacade.setPageSize(15)

this.sub = this.platformService.getMe().subscribe((user) => {
this.ownerId = user.id
this.platformService.getMe().subscribe((user) => {
this.fieldsService
.buildFiltersFromFieldValues({ owner: user.id })
.subscribe((filters) => {
Expand Down Expand Up @@ -132,8 +125,4 @@ export class MyRecordsComponent implements OnInit, OnDestroy {
this.cdr.markForCheck()
}
}

ngOnDestroy(): void {
this.sub.unsubscribe()
}
}
10 changes: 8 additions & 2 deletions apps/metadata-editor/src/app/records/records-list.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CommonModule } from '@angular/common'
import { Component } from '@angular/core'
import { Component, OnInit } from '@angular/core'
import { MatIconModule } from '@angular/material/icon'
import { Router } from '@angular/router'
import { CatalogRecord } from '@geonetwork-ui/common/domain/model/record'
Expand All @@ -13,6 +13,7 @@ import { UiElementsModule } from '@geonetwork-ui/ui/elements'
import { TranslateModule } from '@ngx-translate/core'
import { UiInputsModule } from '@geonetwork-ui/ui/inputs'
import { RecordsCountComponent } from './records-count/records-count.component'
import { allSearchFields } from './all-records/all-records.component'

@Component({
selector: 'md-editor-records-list',
Expand All @@ -30,13 +31,18 @@ import { RecordsCountComponent } from './records-count/records-count.component'
RecordsCountComponent,
],
})
export class RecordsListComponent {
export class RecordsListComponent implements OnInit {
constructor(
private router: Router,
public searchFacade: SearchFacade,
private searchService: SearchService
) {}

ngOnInit(): void {
this.searchFacade.setConfigRequestFields(allSearchFields)
this.searchFacade.setPageSize(15)
}

paginate(page: number) {
this.searchService.setPage(page)
}
Expand Down
2 changes: 1 addition & 1 deletion libs/feature/router/src/lib/default/state/router.facade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { MdViewActions } from '@geonetwork-ui/feature/record'
import { RouterService } from '../router.service'
import { RouterReducerState } from '@ngrx/router-store'
import { select, Store } from '@ngrx/store'
import { distinctUntilChanged, filter, map, take, tap } from 'rxjs/operators'
import { distinctUntilChanged, filter, map, take } from 'rxjs/operators'
import {
ROUTER_ROUTE_DATASET,
ROUTER_ROUTE_SEARCH,
Expand Down

0 comments on commit a5f8b7b

Please sign in to comment.