From 330bf87f081886535ca2e07e06cfb16425ba8d4d Mon Sep 17 00:00:00 2001 From: Nithin David Thomas Date: Sat, 22 Feb 2020 14:24:51 +0530 Subject: [PATCH] Bug : Inbox Filter indicator is removed when a conversation is selected (#535) --- .../widgets/conversation/ConversationCard.vue | 8 +++---- app/javascript/dashboard/helper/URLHelper.js | 7 +++++++ .../dashboard/helper/spec/URLHelper.spec.js | 21 +++++++++++++++++++ .../dashboard/i18n/default-sidebar.js | 1 + .../conversation/ConversationView.vue | 6 ++++++ .../conversation/conversation.routes.js | 12 +++++++++++ 6 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 app/javascript/dashboard/helper/spec/URLHelper.spec.js diff --git a/app/javascript/dashboard/components/widgets/conversation/ConversationCard.vue b/app/javascript/dashboard/components/widgets/conversation/ConversationCard.vue index af91aadd5..ce7040c21 100644 --- a/app/javascript/dashboard/components/widgets/conversation/ConversationCard.vue +++ b/app/javascript/dashboard/components/widgets/conversation/ConversationCard.vue @@ -46,7 +46,7 @@ import getEmojiSVG from '../emoji/utils'; import conversationMixin from '../../../mixins/conversations'; import timeMixin from '../../../mixins/time'; import router from '../../../routes'; -import { frontendURL } from '../../../helper/URLHelper'; +import { frontendURL, conversationUrl } from '../../../helper/URLHelper'; export default { components: { @@ -95,9 +95,9 @@ export default { methods: { cardClick(chat) { - router.push({ - path: frontendURL(`conversations/${chat.id}`), - }); + const { activeInbox } = this; + const path = conversationUrl(activeInbox, chat.id); + router.push({ path: frontendURL(path) }); }, extractMessageText(chatItem) { if (chatItem.content) { diff --git a/app/javascript/dashboard/helper/URLHelper.js b/app/javascript/dashboard/helper/URLHelper.js index 5448a9d6a..94c31cdd3 100644 --- a/app/javascript/dashboard/helper/URLHelper.js +++ b/app/javascript/dashboard/helper/URLHelper.js @@ -4,3 +4,10 @@ export const frontendURL = (path, params) => { const stringifiedParams = params ? `?${queryString.stringify(params)}` : ''; return `/app/${path}${stringifiedParams}`; }; + +export const conversationUrl = (activeInbox, id) => { + const path = activeInbox + ? `inbox/${activeInbox}/conversations/${id}` + : `conversations/${id}`; + return path; +}; diff --git a/app/javascript/dashboard/helper/spec/URLHelper.spec.js b/app/javascript/dashboard/helper/spec/URLHelper.spec.js new file mode 100644 index 000000000..7c8b72f27 --- /dev/null +++ b/app/javascript/dashboard/helper/spec/URLHelper.spec.js @@ -0,0 +1,21 @@ +import { frontendURL, conversationUrl } from '../URLHelper'; + +describe('#URL Helpers', () => { + describe('conversationUrl', () => { + it('should return direct conversation URL if activeInbox is nil', () => { + expect(conversationUrl(undefined, 1)).toBe('conversations/1'); + }); + it('should return ibox conversation URL if activeInbox is not nil', () => { + expect(conversationUrl(2, 1)).toBe('inbox/2/conversations/1'); + }); + }); + + describe('frontendURL', () => { + it('should return url without params if params passed is nil', () => { + expect(frontendURL('main', null)).toBe('/app/main'); + }); + it('should return url without params if params passed is not nil', () => { + expect(frontendURL('main', { ping: 'pong' })).toBe('/app/main?ping=pong'); + }); + }); +}); diff --git a/app/javascript/dashboard/i18n/default-sidebar.js b/app/javascript/dashboard/i18n/default-sidebar.js index 89df2ee3c..6b2c4276b 100644 --- a/app/javascript/dashboard/i18n/default-sidebar.js +++ b/app/javascript/dashboard/i18n/default-sidebar.js @@ -6,6 +6,7 @@ export default { 'home', 'inbox_dashboard', 'inbox_conversation', + 'conversation_through_inbox', 'settings_account_reports', 'billing_deactivated', 'profile_settings', diff --git a/app/javascript/dashboard/routes/dashboard/conversation/ConversationView.vue b/app/javascript/dashboard/routes/dashboard/conversation/ConversationView.vue index a0f4cb42d..9513ccd8e 100644 --- a/app/javascript/dashboard/routes/dashboard/conversation/ConversationView.vue +++ b/app/javascript/dashboard/routes/dashboard/conversation/ConversationView.vue @@ -69,6 +69,12 @@ export default { this.$store.dispatch('setActiveInbox', this.inboxId); } break; + case 'conversation_through_inbox': + if (this.inboxId) { + this.$store.dispatch('setActiveInbox', this.inboxId); + } + this.setActiveChat(); + break; default: this.$store.dispatch('setActiveInbox', null); break; diff --git a/app/javascript/dashboard/routes/dashboard/conversation/conversation.routes.js b/app/javascript/dashboard/routes/dashboard/conversation/conversation.routes.js index 8b47e1304..b147fa6a2 100644 --- a/app/javascript/dashboard/routes/dashboard/conversation/conversation.routes.js +++ b/app/javascript/dashboard/routes/dashboard/conversation/conversation.routes.js @@ -31,5 +31,17 @@ export default { return { conversationId: route.params.conversation_id }; }, }, + { + path: frontendURL('inbox/:inbox_id/conversations/:conversation_id'), + name: 'conversation_through_inbox', + roles: ['administrator', 'agent'], + component: ConversationView, + props: route => { + return { + conversationId: route.params.conversation_id, + inboxId: route.params.inbox_id, + }; + }, + }, ], };