From cae3ac94cd12500af6f8557859e16425842a4d31 Mon Sep 17 00:00:00 2001 From: Nithin David Thomas <1277421+nithindavid@users.noreply.github.com> Date: Tue, 14 Mar 2023 13:09:43 +0530 Subject: [PATCH] feat: Search improvements for conversations (#6645) * feat: Shows search as a popover * Reverts search from popover to page * Fixes review comments on usability * Fixes keyboard navigation issues --- .../dashboard/i18n/locale/en/search.json | 3 +- .../search/components/SearchHeader.vue | 73 +++++---- .../modules/search/components/SearchInput.vue | 51 ++++++ .../components/SearchResultContactItem.vue | 2 +- .../SearchResultConversationItem.vue | 2 +- .../search/components/SearchResultSection.vue | 13 +- .../modules/search/components/SearchTabs.vue | 4 +- .../modules/search/components/SearchView.vue | 148 +++++++++++------- .../conversation/search/PopOverSearch.vue | 2 +- .../store/modules/conversationSearch.js | 3 + 10 files changed, 203 insertions(+), 98 deletions(-) create mode 100644 app/javascript/dashboard/modules/search/components/SearchInput.vue diff --git a/app/javascript/dashboard/i18n/locale/en/search.json b/app/javascript/dashboard/i18n/locale/en/search.json index f3823f134..418572c0c 100644 --- a/app/javascript/dashboard/i18n/locale/en/search.json +++ b/app/javascript/dashboard/i18n/locale/en/search.json @@ -14,7 +14,8 @@ "EMPTY_STATE": "No %{item} found for query '%{query}'", "EMPTY_STATE_FULL": "No results found for query '%{query}'", "PLACEHOLDER_KEYBINDING": "/ to focus", - "INPUT_PLACEHOLDER": "Search message content, contact name, email or phone or conversations", + "INPUT_PLACEHOLDER": "Search messages, contacts or conversations", + "EMPTY_STATE_DEFAULT": "Search by conversation id, email, phone number, messages for better search results.", "BOT_LABEL": "Bot", "READ_MORE": "Read more", "WROTE": "wrote:" diff --git a/app/javascript/dashboard/modules/search/components/SearchHeader.vue b/app/javascript/dashboard/modules/search/components/SearchHeader.vue index ae0d786d9..aa85eddab 100644 --- a/app/javascript/dashboard/modules/search/components/SearchHeader.vue +++ b/app/javascript/dashboard/modules/search/components/SearchHeader.vue @@ -1,5 +1,5 @@ @@ -21,6 +25,7 @@ export default { data() { return { searchQuery: '', + isInputFocused: false, }; }, mounted() { @@ -35,6 +40,12 @@ export default { if (e.key === '/' && document.activeElement.tagName !== 'INPUT') { e.preventDefault(); this.$refs.searchInput.focus(); + } else if ( + e.key === 'Escape' && + document.activeElement.tagName === 'INPUT' + ) { + e.preventDefault(); + this.$refs.searchInput.blur(); } }, debounceSearch(e) { @@ -43,56 +54,50 @@ export default { this.debounce = setTimeout(async () => { if (this.searchQuery.length > 2 || this.searchQuery.match(/^[0-9]+$/)) { this.$emit('search', this.searchQuery); + } else { + this.$emit('search', ''); } }, 500); }, + onFocus() { + this.isInputFocused = true; + }, + onBlur() { + this.isInputFocused = false; + }, }, }; diff --git a/app/javascript/dashboard/modules/search/components/SearchInput.vue b/app/javascript/dashboard/modules/search/components/SearchInput.vue new file mode 100644 index 000000000..6dca5239b --- /dev/null +++ b/app/javascript/dashboard/modules/search/components/SearchInput.vue @@ -0,0 +1,51 @@ + + + + diff --git a/app/javascript/dashboard/modules/search/components/SearchResultContactItem.vue b/app/javascript/dashboard/modules/search/components/SearchResultContactItem.vue index c4c4d157f..c35651356 100644 --- a/app/javascript/dashboard/modules/search/components/SearchResultContactItem.vue +++ b/app/javascript/dashboard/modules/search/components/SearchResultContactItem.vue @@ -64,7 +64,7 @@ export default { } } .contact-details { - margin-left: var(--space-normal); + margin-left: var(--space-small); } .name { margin: 0; diff --git a/app/javascript/dashboard/modules/search/components/SearchResultConversationItem.vue b/app/javascript/dashboard/modules/search/components/SearchResultConversationItem.vue index 2c47a4989..8341f69bd 100644 --- a/app/javascript/dashboard/modules/search/components/SearchResultConversationItem.vue +++ b/app/javascript/dashboard/modules/search/components/SearchResultConversationItem.vue @@ -113,7 +113,7 @@ export default { margin-left: var(--space-smaller); } .conversation-details { - margin-left: var(--space-normal); + margin-left: var(--space-small); flex-grow: 1; min-width: 0; } diff --git a/app/javascript/dashboard/modules/search/components/SearchResultSection.vue b/app/javascript/dashboard/modules/search/components/SearchResultSection.vue index a3295c0d6..eab6f920c 100644 --- a/app/javascript/dashboard/modules/search/components/SearchResultSection.vue +++ b/app/javascript/dashboard/modules/search/components/SearchResultSection.vue @@ -1,6 +1,6 @@