From adbd2af19052bf215b215a199eb2d927712d15d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Dierick?= Date: Thu, 4 Mar 2021 16:07:08 +0100 Subject: [PATCH 1/3] chore: disable matomo on non-hosted environments --- config/environment.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/environment.js b/config/environment.js index c15b80818c..bd824e7e31 100644 --- a/config/environment.js +++ b/config/environment.js @@ -14,7 +14,7 @@ module.exports = function(environment) { metricsAdapters: [ { name: 'Matomo', - environments: ['development', 'test', 'cypress-test', 'production'], + environments: ['production'], config: { scriptUrl: 'https://dev-kaleidos-matomo.redpencil.io', // Can optionally be CDN-sourced trackerUrl: 'https://dev-kaleidos-matomo.redpencil.io', From e6edcda7f28322d639b52a096bff327cbf6565a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Dierick?= Date: Fri, 5 Mar 2021 15:53:59 +0100 Subject: [PATCH 2/3] refactor: publication-search in separate component + focus-out handling --- .../publication-case-search/component.js | 56 +++++++++++++++++++ .../publication-case-search/template.hbs | 40 +++++++++++++ app/pods/publications/controller.js | 37 ------------ app/pods/publications/template.hbs | 40 +------------ 4 files changed, 97 insertions(+), 76 deletions(-) create mode 100644 app/pods/components/publications/publication-case-search/component.js create mode 100644 app/pods/components/publications/publication-case-search/template.hbs diff --git a/app/pods/components/publications/publication-case-search/component.js b/app/pods/components/publications/publication-case-search/component.js new file mode 100644 index 0000000000..d17bf2865b --- /dev/null +++ b/app/pods/components/publications/publication-case-search/component.js @@ -0,0 +1,56 @@ +import Component from '@glimmer/component'; +import { action } from '@ember/object'; +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; + yield timeout(500); + yield this.search.perform(this.searchText); + } + + @action + showResults() { + this.isShowingResults = true; + } + + @action + hideResults() { + console.log('In hide'); + this.isShowingResults = false; + } + + @restartableTask + *search() { + const filter = { + ':has:publicationFlowNumber': 'true', + }; + filter[`${this.searchModifier}${this.searchFields.join(',')}`] = `${this.searchText}*`; + this.searchResults = yield search('cases', 0, 10, null, filter, (item) => { + const entry = item.attributes; + entry.id = item.id; + return entry; + }); + this.showResults(); + } +} diff --git a/app/pods/components/publications/publication-case-search/template.hbs b/app/pods/components/publications/publication-case-search/template.hbs new file mode 100644 index 0000000000..ff79bda654 --- /dev/null +++ b/app/pods/components/publications/publication-case-search/template.hbs @@ -0,0 +1,40 @@ + +{{#if this.isShowingResults}} +
+ {{#each this.searchResults as |result|}} + + + {{#if result.subcaseSubTitle}} + {{result.subcaseSubTitle}} + {{else if result.subcaseTitle}} + {{result.subcaseTitle}} + {{else if result.shortTitle}} + {{result.shortTitle}} + {{else if result.title}} + {{result.title}} + {{/if}} +
+ {{result.publicationFlowNumber}} +
+
+ {{else}} + {{ t "no-results-found" }} + {{/each}} +
+{{/if}} \ No newline at end of file diff --git a/app/pods/publications/controller.js b/app/pods/publications/controller.js index a6385883b9..1044ec4c5d 100644 --- a/app/pods/publications/controller.js +++ b/app/pods/publications/controller.js @@ -4,9 +4,6 @@ import { action, set } from '@ember/object'; 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 PublicationsController extends Controller { @service publicationService; @@ -15,9 +12,6 @@ export default class PublicationsController extends Controller { @tracked hasError = false; @tracked numberIsAlreadyUsed = false; @tracked isCreatingPublication = false; - @tracked searchText; - @tracked showSearchResults = false; - @tracked searchResults; @tracked showLoader = false; @tracked isShowPublicationFilterModal = false; @@ -40,37 +34,6 @@ export default class PublicationsController extends Controller { longTitle: null, }; - @restartableTask - *debouncedSearchTask(event) { - this.searchText = event.target.value; - yield timeout(500); - yield this.search(this.searchText); - } - - @action - async search() { - const filter = { - ':has:publicationFlowNumber': 1, - }; - if (this.searchText.length === 0 || this.searchText === '') { - this.showSearchResults = false; - } else { - this.textSearchFields = ['title', 'publicationFlowNumber', 'publicationFlowRemark', 'shortTitle', 'subcaseTitle', 'subcaseSubTitle', 'publicationFlowNumacNumbers', 'publicationFlowId']; - const searchModifier = ':phrase_prefix:'; - const textSearchKey = this.textSearchFields.join(','); - filter[`${searchModifier}${textSearchKey}`] = `${this.searchText}*`; - this.showSearchResults = true; - this.searchResults = await search('cases', 0, 10, null, filter, (item) => { - const entry = item.attributes; - entry.id = item.id; - return entry; - }); - if (this.searchResults.length === 0) { - this.searchResults = false; - } - } - } - get getError() { return this.hasError; } diff --git a/app/pods/publications/template.hbs b/app/pods/publications/template.hbs index 4c62e0b5d9..7c5a9e00f0 100644 --- a/app/pods/publications/template.hbs +++ b/app/pods/publications/template.hbs @@ -16,45 +16,7 @@ - - {{#if showSearchResults}} -
- {{#each this.searchResults as |result|}} - - - {{#if result.subcaseSubTitle}} - {{result.subcaseSubTitle}} - {{else if result.subcaseTitle}} - {{result.subcaseTitle}} - {{else if result.shortTitle}} - {{result.shortTitle}} - {{else if result.title}} - {{result.title}} - {{/if}} -
- {{result.publicationFlowNumber}} -
-
- {{else}} - {{ t "no-results-found" }} - {{/each}} -
- {{/if}} +
From ff4707dd17d9b3a4bb41694ae6bba210af4b1499 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Dierick?= Date: Mon, 8 Mar 2021 09:18:02 +0100 Subject: [PATCH 3/3] refactor: more natural search ui-behaviour --- .../publication-case-search/component.js | 28 +++++++++++++++---- .../publication-case-search/template.hbs | 2 +- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/app/pods/components/publications/publication-case-search/component.js b/app/pods/components/publications/publication-case-search/component.js index d17bf2865b..b703ad7eb2 100644 --- a/app/pods/components/publications/publication-case-search/component.js +++ b/app/pods/components/publications/publication-case-search/component.js @@ -1,5 +1,6 @@ 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'; @@ -25,8 +26,13 @@ export default class PublicationsPublicationCaseSearchComponent extends Componen @restartableTask *debouncedSearch(event) { this.searchText = event.target.value; - yield timeout(500); - yield this.search.perform(this.searchText); + if (!isEmpty(this.searchText)) { + yield timeout(500); + yield this.search.perform(); + } else { + this.searchResults = []; + this.hideResults(); + } } @action @@ -36,21 +42,31 @@ export default class PublicationsPublicationCaseSearchComponent extends Componen @action hideResults() { - console.log('In hide'); 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(',')}`] = `${this.searchText}*`; - this.searchResults = yield search('cases', 0, 10, null, filter, (item) => { + 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; }); - this.showResults(); + return searchResults; } } diff --git a/app/pods/components/publications/publication-case-search/template.hbs b/app/pods/components/publications/publication-case-search/template.hbs index ff79bda654..0b924f6751 100644 --- a/app/pods/components/publications/publication-case-search/template.hbs +++ b/app/pods/components/publications/publication-case-search/template.hbs @@ -7,7 +7,7 @@ value={{this.searchText}} {{on "input" (perform this.debouncedSearch)}} {{on "focusout" this.hideResults}} - {{on "focusin" (if this.search.lastSuccessful this.showResults)}} + {{on "focusin" (if this.search.lastSuccessful this.showResults this.hideResults)}} @enter={{perform this.search}} @autocomplete="off" />