From d23b4a45adbdc5493ed1c82ec3e3654fcda7c461 Mon Sep 17 00:00:00 2001 From: fayazara Date: Mon, 12 Dec 2022 21:00:22 +0530 Subject: [PATCH] Update commandbar with the builder --- .../dashboard/api/inbox/conversation.js | 6 ++ .../routes/dashboard/commands/commandbar.vue | 8 ++- .../dashboard/commands/goToCommandHotKeys.js | 48 +++++++++---- package.json | 2 +- yarn.lock | 72 +++++++------------ 5 files changed, 76 insertions(+), 60 deletions(-) diff --git a/app/javascript/dashboard/api/inbox/conversation.js b/app/javascript/dashboard/api/inbox/conversation.js index 8d5f5b82c..ef798f3a9 100644 --- a/app/javascript/dashboard/api/inbox/conversation.js +++ b/app/javascript/dashboard/api/inbox/conversation.js @@ -45,6 +45,12 @@ class ConversationApi extends ApiClient { }); } + textSearch(query) { + return axios.post(`${this.url}/text_search`, null, { + params: { query }, + }); + } + toggleStatus({ conversationId, status, snoozedUntil = null }) { return axios.post(`${this.url}/${conversationId}/toggle_status`, { status, diff --git a/app/javascript/dashboard/routes/dashboard/commands/commandbar.vue b/app/javascript/dashboard/routes/dashboard/commands/commandbar.vue index 1d794d02a..40930b7c4 100644 --- a/app/javascript/dashboard/routes/dashboard/commands/commandbar.vue +++ b/app/javascript/dashboard/routes/dashboard/commands/commandbar.vue @@ -54,12 +54,18 @@ export default { this.setCommandbarData(); }, methods: { - setCommandbarData() { + setCommandbarData(e) { + if (e && e.detail.action.id && e.detail.action.title) { + console.log({ id: e.detail.action.id, title: e.detail.action.id }); + } this.$refs.ninjakeys.data = this.hotKeys; }, onChange(ninjaKeyInstance) { // console.log(ninjaKeyInstance); }, + searchEverything(query) { + console.log(query); + }, }, }; diff --git a/app/javascript/dashboard/routes/dashboard/commands/goToCommandHotKeys.js b/app/javascript/dashboard/routes/dashboard/commands/goToCommandHotKeys.js index 6c6186482..a8f71a35a 100644 --- a/app/javascript/dashboard/routes/dashboard/commands/goToCommandHotKeys.js +++ b/app/javascript/dashboard/routes/dashboard/commands/goToCommandHotKeys.js @@ -25,7 +25,32 @@ const GO_TO_COMMANDS = [ title: 'COMMAND_BAR.COMMANDS.SEARCH_EVEYTHING', section: 'COMMAND_BAR.SECTIONS.CHATWOOT', icon: ICON_CONVERSATION_DASHBOARD, - children: ['Light Theme', 'Dark Theme', 'System Theme'], + builder: searchKey => { + return new Promise(resolve => { + fetch( + `https://staging.chatwoot.com/api/v1/accounts/3/conversations/text_search?q=${searchKey}`, + { + headers: { + 'Content-Type': 'application/json', + api_access_token: '', + }, + } + ) + .then(res => res.json()) + .then(data => { + const { results } = data; + resolve( + results.payload.contacts.map(result => ({ + id: result.id, + title: result.name, + })) + ); + }) + .catch(error => { + resolve([]); + }); + }); + }, role: ['agent'], }, { @@ -192,23 +217,20 @@ export default { commands = commands.filter(command => command.role.includes('agent')); } return commands.map(command => { - return { + const hotKey = { id: command.id, section: this.$t(command.section), title: this.$t(command.title), icon: command.icon, - children: command.children, - handler: () => { - if (command.children) { - // const ninja = this.$refs.ninjakeys; - const ninja = document.querySelector('ninja-keys'); - ninja.open({ parent: command.id }); - return { keepOpen: true }; - } else { - this.openRoute(command.path(this.accountId)); - } - }, }; + if (command.builder) { + hotKey.builder = command.builder; + } else { + hotKey.handler = () => { + this.openRoute(command.path(this.accountId)); + }; + } + return hotKey; }); }, }, diff --git a/package.json b/package.json index a1ae3a325..b973c3f3c 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "js-cookie": "^2.2.1", "marked": "4.0.10", "md5": "^2.3.0", - "ninja-keys": "^1.1.9", + "ninja-keys": "github:fayazara/ninja-keys", "opus-recorder": "^8.0.5", "prosemirror-markdown": "1.5.1", "prosemirror-state": "1.3.4", diff --git a/yarn.lock b/yarn.lock index 2615cdb42..3fe2549da 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1783,23 +1783,6 @@ "@jridgewell/resolve-uri" "^3.0.3" "@jridgewell/sourcemap-codec" "^1.4.10" -"@june-so/analytics-next@^1.36.5": - version "1.36.5" - resolved "https://registry.yarnpkg.com/@june-so/analytics-next/-/analytics-next-1.36.5.tgz#030ba5a7f8fa232597185cdb706e40b7036ca7f8" - integrity sha512-r2sp4VDngeX/ItQrlgmdKpmghg3OmPvhnTOKJ1huaHbFM2uPELpfnMRRngUVzbgbMoMeTf8QtgQVMjnUsl7G1A== - dependencies: - "@lukeed/uuid" "^2.0.0" - "@segment/analytics.js-video-plugins" "^0.2.1" - "@segment/facade" "3.4.7" - "@segment/tsub" "^0.1.9" - dset "^3.0.0" - encoding "^0.1.13" - js-cookie "^2.2.1" - node-fetch "^2.6.1" - spark-md5 "^3.0.1" - tslib "^2.1.0" - unfetch "^4.1.0" - "@lit/reactive-element@^1.0.0", "@lit/reactive-element@^1.1.0": version "1.1.1" resolved "https://registry.yarnpkg.com/@lit/reactive-element/-/reactive-element-1.1.1.tgz#523b29e529e881fce47bab764ea1b8058fd45796" @@ -10994,38 +10977,38 @@ listr@^0.14.3: p-map "^2.0.0" rxjs "^6.3.3" -lit-element@^3.0.0, lit-element@^3.1.0: - version "3.1.1" - resolved "https://registry.yarnpkg.com/lit-element/-/lit-element-3.1.1.tgz#562d5ccbc8ba0c01d8ba4a0ac3576263167d2ccb" - integrity sha512-14ClnMAU8EXnzC+M2/KDd3SFmNUn1QUw1+GxWkEMwGV3iaH8ObunMlO5svzvaWlkSV0WlxJCi40NGnDVJ2XZKQ== +lit-element@^3.2.0: + version "3.2.2" + resolved "https://registry.yarnpkg.com/lit-element/-/lit-element-3.2.2.tgz#d148ab6bf4c53a33f707a5168e087725499e5f2b" + integrity sha512-6ZgxBR9KNroqKb6+htkyBwD90XGRiqKDHVrW/Eh0EZ+l+iC+u+v+w3/BA5NGi4nizAVHGYvQBHUDuSmLjPp7NQ== dependencies: - "@lit/reactive-element" "^1.1.0" - lit-html "^2.1.0" + "@lit/reactive-element" "^1.3.0" + lit-html "^2.2.0" -lit-html@^2.0.0, lit-html@^2.1.0: - version "2.1.1" - resolved "https://registry.yarnpkg.com/lit-html/-/lit-html-2.1.1.tgz#f4da485798a0d967514d31730d387350fafb79f7" - integrity sha512-E4BImK6lopAYanJpvcGaAG8kQFF1ccIulPu2BRNZI7acFB6i4ujjjsnaPVFT1j/4lD9r8GKih0Y8d7/LH8SeyQ== +lit-html@^2.2.0, lit-html@^2.5.0: + version "2.5.0" + resolved "https://registry.yarnpkg.com/lit-html/-/lit-html-2.5.0.tgz#9d4c0bb3652a6b10bc4ccdb627dfa9eff1215474" + integrity sha512-bLHosg1XL3JRUcKdSVI0sLCs0y1wWrj2sqqAN3cZ7bDDPNgmDHH29RV48x6Wz3ZmkxIupaE+z7uXSZ/pXWAO1g== dependencies: "@types/trusted-types" "^2.0.2" -lit@2.0.2: - version "2.0.2" - resolved "https://registry.yarnpkg.com/lit/-/lit-2.0.2.tgz#5e6f422924e0732258629fb379556b6d23f7179c" - integrity sha512-hKA/1YaSB+P+DvKWuR2q1Xzy/iayhNrJ3aveD0OQ9CKn6wUjsdnF/7LavDOJsKP/K5jzW/kXsuduPgRvTFrFJw== +lit@2.2.6: + version "2.2.6" + resolved "https://registry.yarnpkg.com/lit/-/lit-2.2.6.tgz#4ef223e88517c000b0c01baf2e3535e61a75a5b5" + integrity sha512-K2vkeGABfSJSfkhqHy86ujchJs3NR9nW1bEEiV+bXDkbiQ60Tv5GUausYN2mXigZn8lC1qXuc46ArQRKYmumZw== dependencies: - "@lit/reactive-element" "^1.0.0" - lit-element "^3.0.0" - lit-html "^2.0.0" + "@lit/reactive-element" "^1.3.0" + lit-element "^3.2.0" + lit-html "^2.2.0" lit@^2.0.0: - version "2.1.1" - resolved "https://registry.yarnpkg.com/lit/-/lit-2.1.1.tgz#65f43abca945988f696391f762c645ba51966b0b" - integrity sha512-yqDqf36IhXwOxIQSFqCMgpfvDCRdxLCLZl7m/+tO5C9W/OBHUj17qZpiMBT35v97QMVKcKEi1KZ3hZRyTwBNsQ== + version "2.5.0" + resolved "https://registry.yarnpkg.com/lit/-/lit-2.5.0.tgz#3a425d69ff8483effb2026957b86ae45de0bc51a" + integrity sha512-DtnUP6vR3l4Q8nRPPNBD+UxbAhwJPeky+OVbi3pdgMqm0g57xFSl1Sj64D1rIB+nVNdiVVg8YxB0hqKjvdadZA== dependencies: - "@lit/reactive-element" "^1.1.0" - lit-element "^3.1.0" - lit-html "^2.1.0" + "@lit/reactive-element" "^1.5.0" + lit-element "^3.2.0" + lit-html "^2.5.0" load-json-file@^1.0.0: version "1.1.0" @@ -11822,14 +11805,13 @@ nice-try@^1.0.4: resolved "https://registry.yarnpkg.com/nice-try/-/nice-try-1.0.5.tgz#a3378a7696ce7d223e88fc9b764bd7ef1089e366" integrity sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ== -ninja-keys@^1.1.9: - version "1.1.9" - resolved "https://registry.yarnpkg.com/ninja-keys/-/ninja-keys-1.1.9.tgz#0251c8635f5cb019f5efd667b69b12c293c5cd26" - integrity sha512-XJabKFQIQ2pivNSKA3I/6hm9S7yPhJ2xXDFfWZFOPtDTBOv5xCaqOczrlIaESXPMgjk3xL0izFWUDjSn8ByVvw== +"ninja-keys@github:fayazara/ninja-keys": + version "1.2.2" + resolved "https://codeload.github.com/fayazara/ninja-keys/tar.gz/e4c0f32d1554447ff14bd76cef8e3142785758cb" dependencies: "@material/mwc-icon" "0.25.3" hotkeys-js "3.8.7" - lit "2.0.2" + lit "2.2.6" no-case@^3.0.4: version "3.0.4"