From b656db3a84d8208fa790241c7690e248350c6370 Mon Sep 17 00:00:00 2001 From: Bernat Date: Thu, 29 Aug 2019 08:32:46 +0200 Subject: [PATCH] #1645 refactor search panel --- e2e/paths/04-item-module/01_summary.spec.js | 1 + .../04-item-module/08_create_and_clone.spec.js | 3 +++ e2e/paths/04-item-module/09_regularize.spec.js | 2 ++ front/core/components/searchbar/searchbar.js | 14 +++++++++----- modules/item/front/index/index.html | 1 + 5 files changed, 16 insertions(+), 5 deletions(-) diff --git a/e2e/paths/04-item-module/01_summary.spec.js b/e2e/paths/04-item-module/01_summary.spec.js index 1cbfc4af8..25e442feb 100644 --- a/e2e/paths/04-item-module/01_summary.spec.js +++ b/e2e/paths/04-item-module/01_summary.spec.js @@ -11,6 +11,7 @@ describe('Item summary path', () => { it('should search for an item', async() => { const result = await nightmare + .clearInput(selectors.itemsIndex.searchItemInput) .write(selectors.itemsIndex.searchItemInput, 'Ranged weapon longbow 2m') .waitToClick(selectors.itemsIndex.searchButton) .waitForNumberOfElements(selectors.itemsIndex.searchResult, 1) diff --git a/e2e/paths/04-item-module/08_create_and_clone.spec.js b/e2e/paths/04-item-module/08_create_and_clone.spec.js index b5e33cc4a..8f4952fb1 100644 --- a/e2e/paths/04-item-module/08_create_and_clone.spec.js +++ b/e2e/paths/04-item-module/08_create_and_clone.spec.js @@ -11,6 +11,7 @@ describe('Item Create/Clone path', () => { it(`should search for the item Infinity Gauntlet to confirm it isn't created yet`, async() => { const result = await nightmare + .clearInput(selectors.itemsIndex.searchItemInput) .write(selectors.itemsIndex.searchItemInput, 'Infinity Gauntlet') .waitToClick(selectors.itemsIndex.searchButton) .waitForNumberOfElements(selectors.itemsIndex.searchResult, 0) @@ -95,6 +96,7 @@ describe('Item Create/Clone path', () => { it(`should search for the item Infinity Gauntlet`, async() => { const result = await nightmare + .clearInput(selectors.itemsIndex.searchItemInput) .write(selectors.itemsIndex.searchItemInput, 'Infinity Gauntlet') .waitToClick(selectors.itemsIndex.searchButton) .waitForNumberOfElements(selectors.itemsIndex.searchResult, 1) @@ -117,6 +119,7 @@ describe('Item Create/Clone path', () => { it('should search for the item Infinity Gauntlet and find two', async() => { const result = await nightmare .waitToClick(selectors.itemTags.goToItemIndexButton) + .clearInput(selectors.itemsIndex.searchItemInput) .write(selectors.itemsIndex.searchItemInput, 'Infinity Gauntlet') .waitToClick(selectors.itemsIndex.searchButton) .waitForNumberOfElements(selectors.itemsIndex.searchResult, 2) diff --git a/e2e/paths/04-item-module/09_regularize.spec.js b/e2e/paths/04-item-module/09_regularize.spec.js index 1a9159655..242414372 100644 --- a/e2e/paths/04-item-module/09_regularize.spec.js +++ b/e2e/paths/04-item-module/09_regularize.spec.js @@ -29,6 +29,7 @@ describe('Item regularize path', () => { it('should search for the item', async() => { const resultCount = await nightmare + .clearInput(selectors.itemsIndex.searchItemInput) .write(selectors.itemsIndex.searchItemInput, 'Ranged weapon pistol 9mm') .waitToClick(selectors.itemsIndex.searchButton) .waitForNumberOfElements(selectors.itemsIndex.searchResult, 1) @@ -134,6 +135,7 @@ describe('Item regularize path', () => { it('should search for the item once again', async() => { const resultCount = await nightmare + .clearInput(selectors.itemsIndex.searchItemInput) .write(selectors.itemsIndex.searchItemInput, 'Ranged weapon pistol 9mm') .waitToClick(selectors.itemsIndex.searchButton) .waitForNumberOfElements(selectors.itemsIndex.searchResult, 1) diff --git a/front/core/components/searchbar/searchbar.js b/front/core/components/searchbar/searchbar.js index 69e826c8c..6412e67bc 100644 --- a/front/core/components/searchbar/searchbar.js +++ b/front/core/components/searchbar/searchbar.js @@ -28,7 +28,6 @@ export default class Controller extends Component { () => this.onStateChange()); this._filter = null; - this.searchString = ''; this.autoLoad = false; } @@ -58,6 +57,10 @@ export default class Controller extends Component { this.doSearch(); } + get shownFilter() { + return this._filter != null ? this._filter : this.suggestedFilter; + } + openPanel(event) { if (event.defaultPrevented) return; event.preventDefault(); @@ -65,7 +68,8 @@ export default class Controller extends Component { this.$panelScope = this.$.$new(); this.$panel = this.$compile(`<${this.panel}/>`)(this.$panelScope); let panel = this.$panel.isolateScope().$ctrl; - panel.filter = this._filter; + if (this.shownFilter) + panel.filter = JSON.parse(JSON.stringify(this.shownFilter)); panel.onSubmit = filter => this.onPanelSubmit(filter); this.$.popover.parent = this.element; @@ -94,13 +98,12 @@ export default class Controller extends Component { } doSearch() { - let filter = this._filter; + this.searchString = this.getStringFromObject(this.shownFilter); + let filter = this._filter; if (filter == null && this.autoload) filter = {}; - this.searchString = this.getStringFromObject(filter); - if (this.onSearch) this.onSearch({$params: filter}); @@ -214,6 +217,7 @@ ngModule.component('vnSearchbar', { template: require('./searchbar.html'), bindings: { filter: '