Skip to content

Commit

Permalink
Merge branch 'geonetwork:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
gkeimeHDF committed May 30, 2023
2 parents 2f75e3f + 73b796f commit 5005de3
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<div id="angular-app-root">
<gn-ui-fuzzy-search class="text-[18px]"> </gn-ui-fuzzy-search>
<gn-ui-fuzzy-search #searchInput class="text-[18px]"></gn-ui-fuzzy-search>
</div>
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import {
AfterViewChecked,
ChangeDetectionStrategy,
Component,
Input,
ViewChild,
ViewEncapsulation,
} from '@angular/core'
import { SearchFacade, SearchService } from '@geonetwork-ui/feature/search'
import { MetadataRecord } from '@geonetwork-ui/util/shared'
import { BaseComponent } from '../base.component'
import { FuzzySearchComponent } from '@geonetwork-ui/feature/search'

@Component({
selector: 'wc-gn-search-input',
Expand All @@ -14,4 +19,30 @@ import { BaseComponent } from '../base.component'
encapsulation: ViewEncapsulation.ShadowDom,
providers: [SearchFacade, SearchService],
})
export class GnSearchInputComponent extends BaseComponent {}
export class GnSearchInputComponent
extends BaseComponent
implements AfterViewChecked
{
@Input() openOnSearch: string
@Input() openOnSelect: string
@ViewChild('searchInput') searchInput: FuzzySearchComponent

ngAfterViewChecked() {
if (this.openOnSearch) {
this.searchInput.inputSubmitted.subscribe(this.search.bind(this))
}
if (this.openOnSelect) {
this.searchInput.itemSelected.subscribe(this.select.bind(this))
}
}

search(any: string) {
const landingPage = this.openOnSearch.replace(/\$\{search}/, any)
window.open(landingPage, '_self').focus()
}

select(record: MetadataRecord) {
const landingPage = this.openOnSelect.replace(/\$\{uuid}/, record.uuid)
window.open(landingPage, '_self').focus()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
<script src="gn-wc.js"></script>
<gn-search-input
api-url="https://dev.geo2france.fr/geonetwork/srv/api"
open-on-search="https://dev.geo2france.fr/datahub/home/search/?q=${search}"
open-on-select="https://dev.geo2france.fr/datahub/dataset/${uuid}"
primary-color="#0f4395"
secondary-color="#8bc832"
main-color="#555"
Expand Down
1 change: 1 addition & 0 deletions libs/feature/search/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ export * from './lib/utils/service/search.service'
export * from './lib/utils/service/fields.service'
export * from './lib/results-list/results-list.container.component'
export * from './lib/filter-dropdown/filter-dropdown.component'
export * from './lib/fuzzy-search/fuzzy-search.component'
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,20 @@ describe('FuzzySearchComponent', () => {
})
describe('when output is defined', () => {
beforeEach(() => {
jest.resetAllMocks()
outputValue = null
component.inputSubmitted.subscribe((event) => (outputValue = event))
jest.spyOn(component.inputSubmitted, 'emit')
component.handleInputSubmission('blarg')
})
it('updates the search filters as well', () => {
expect(searchServiceMock.updateFilters).toHaveBeenCalledWith({
expect(searchServiceMock.updateFilters).not.toHaveBeenCalledWith({
any: 'blarg',
})
})
it('emits inputSubmitted', () => {
expect(component.inputSubmitted.emit).toHaveBeenCalledWith('blarg')
})
})
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { SearchService } from '../utils/service/search.service'
export class FuzzySearchComponent implements OnInit {
@ViewChild(AutocompleteComponent) autocomplete: AutocompleteComponent
@Output() itemSelected = new EventEmitter<MetadataRecord>()
@Output() inputSubmited = new EventEmitter<string>()
@Output() inputSubmitted = new EventEmitter<string>()
searchInputValue$: Observable<{ title: string }>

displayWithFn: (MetadataRecord) => string = (record) => record?.title
Expand Down Expand Up @@ -76,6 +76,10 @@ export class FuzzySearchComponent implements OnInit {
}

handleInputSubmission(any: string) {
this.searchService.updateFilters({ any })
if (this.inputSubmitted.observers.length > 0) {
this.inputSubmitted.emit(any)
} else {
this.searchService.updateFilters({ any })
}
}
}

0 comments on commit 5005de3

Please sign in to comment.