-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'DES/enhancement/#705-vl-refactor' into DES/enhancement/…
…705-vl-refactor/icon
- Loading branch information
Showing
5 changed files
with
114 additions
and
77 deletions.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
app/pods/components/publications/publication-case-search/component.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import Component from '@glimmer/component'; | ||
import { action } from '@ember/object'; | ||
import { isEmpty } from '@ember/utils'; | ||
import { tracked } from '@glimmer/tracking'; | ||
import { timeout } from 'ember-concurrency'; | ||
import { restartableTask } from 'ember-concurrency-decorators'; | ||
import search from 'frontend-kaleidos/utils/mu-search'; | ||
|
||
export default class PublicationsPublicationCaseSearchComponent extends Component { | ||
@tracked searchText; | ||
@tracked isShowingResults = false; | ||
@tracked searchResults; | ||
|
||
searchFields = Object.freeze([ | ||
'title', | ||
'publicationFlowNumber', | ||
'publicationFlowRemark', | ||
'shortTitle', | ||
'subcaseTitle', | ||
'subcaseSubTitle', | ||
'publicationFlowNumacNumbers', | ||
'publicationFlowId' | ||
]); | ||
searchModifier = Object.freeze(':phrase_prefix:'); | ||
|
||
@restartableTask | ||
*debouncedSearch(event) { | ||
this.searchText = event.target.value; | ||
if (!isEmpty(this.searchText)) { | ||
yield timeout(500); | ||
yield this.search.perform(); | ||
} else { | ||
this.searchResults = []; | ||
this.hideResults(); | ||
} | ||
} | ||
|
||
@action | ||
showResults() { | ||
this.isShowingResults = true; | ||
} | ||
|
||
@action | ||
hideResults() { | ||
this.isShowingResults = false; | ||
} | ||
|
||
@restartableTask | ||
*search() { | ||
if (!isEmpty(this.searchText)) { | ||
this.searchResults = yield this.searchPublications.perform(this.searchText); | ||
this.showResults(); | ||
} else { | ||
this.searchResults = []; | ||
this.hideResults(); | ||
} | ||
} | ||
|
||
@restartableTask | ||
*searchPublications(searchTerm) { | ||
const filter = { | ||
':has:publicationFlowNumber': 'true', | ||
}; | ||
filter[`${this.searchModifier}${this.searchFields.join(',')}`] = searchTerm; | ||
const searchResults = yield search('cases', 0, 10, null, filter, (item) => { | ||
const entry = item.attributes; | ||
entry.id = item.id; | ||
return entry; | ||
}); | ||
return searchResults; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
app/pods/components/publications/publication-case-search/template.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<WebComponents::AuInput | ||
class="auk-input--block" | ||
@icon="search" | ||
@type="text" | ||
data-test-trigger-search-input | ||
@placeholder={{t "search-placeholder"}} | ||
value={{this.searchText}} | ||
{{on "input" (perform this.debouncedSearch)}} | ||
{{on "focusout" this.hideResults}} | ||
{{on "focusin" (if this.search.lastSuccessful this.showResults this.hideResults)}} | ||
@enter={{perform this.search}} | ||
@autocomplete="off" | ||
/> | ||
{{#if this.isShowingResults}} | ||
<div class="autocomplete-results auk-search-results-list"> | ||
{{#each this.searchResults as |result|}} | ||
<WebComponents::AuDropdown::Item @class="auk-search-results-list__item"> | ||
<LinkTo | ||
data-test-publication-search-result | ||
@route="publications.publication.documents" | ||
@model={{result.publicationFlowId}} | ||
> | ||
{{#if result.subcaseSubTitle}} | ||
{{result.subcaseSubTitle}} | ||
{{else if result.subcaseTitle}} | ||
{{result.subcaseTitle}} | ||
{{else if result.shortTitle}} | ||
{{result.shortTitle}} | ||
{{else if result.title}} | ||
{{result.title}} | ||
{{/if}} | ||
<br> | ||
<span class="auk-u-muted auk-u-text-small">{{result.publicationFlowNumber}}</span> | ||
</LinkTo> | ||
</WebComponents::AuDropdown::Item> | ||
{{else}} | ||
{{ t "no-results-found" }} | ||
{{/each}} | ||
</div> | ||
{{/if}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters