From e5134c9ef5624c3daf20212ee7343303edfaaccc Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Mon, 20 Mar 2023 15:46:29 +0530 Subject: [PATCH] [CW-53] feat: allow downloading heatmap report (#6683) * feat: add control header slot * feat: add download API call * feat: add conversation traffic template * feat: allow downloading heatmap content * feat: wire up download * fix: grid layout for mobile * chore: revert formatting * revert: en.yml file * feat: add conversation traffic text * feat: disable rule for map block * test: conversation traffic * fix: timezone offset * feat: download report in UTC * feat: add UTC warning * chore: revert formatting * feat: add traffic text * chore: fix whitespace change --- .../api/v2/accounts/reports_controller.rb | 5 + app/helpers/api/v2/accounts/reports_helper.rb | 21 ++++ app/javascript/dashboard/api/reports.js | 6 ++ .../settings/reports/LiveReports.vue | 20 ++++ .../components/overview/MetricCard.vue | 96 +++++++++++++------ .../dashboard/store/modules/reports.js | 22 ++++- .../accounts/reports/conversation_traffic.erb | 12 +++ config/locales/en.yml | 4 + config/routes.rb | 1 + .../api/v2/accounts/report_controller_spec.rb | 35 +++++++ 10 files changed, 192 insertions(+), 30 deletions(-) create mode 100644 app/views/api/v2/accounts/reports/conversation_traffic.erb diff --git a/app/controllers/api/v2/accounts/reports_controller.rb b/app/controllers/api/v2/accounts/reports_controller.rb index dedeb17bf..a9fc5d4b4 100644 --- a/app/controllers/api/v2/accounts/reports_controller.rb +++ b/app/controllers/api/v2/accounts/reports_controller.rb @@ -32,6 +32,11 @@ class Api::V2::Accounts::ReportsController < Api::V1::Accounts::BaseController generate_csv('teams_report', 'api/v2/accounts/reports/teams') end + def conversation_traffic + @report_data = generate_conversations_heatmap_report + generate_csv('conversation_traffic_reports', 'api/v2/accounts/reports/conversation_traffic') + end + def conversations return head :unprocessable_entity if params[:type].blank? diff --git a/app/helpers/api/v2/accounts/reports_helper.rb b/app/helpers/api/v2/accounts/reports_helper.rb index 0604eba2f..b15683afd 100644 --- a/app/helpers/api/v2/accounts/reports_helper.rb +++ b/app/helpers/api/v2/accounts/reports_helper.rb @@ -27,6 +27,27 @@ module Api::V2::Accounts::ReportsHelper end end + def generate_conversations_heatmap_report + report_params = { + type: :account, + group_by: 'hour', + since: params[:since], + until: params[:until], + metric: 'conversations_count', + business_hours: false + } + data = V2::ReportBuilder.new(Current.account, report_params).build + + # data format is { timestamp: 1231242342, value: 3} + # we need to convert it to { date: "2020-01-01", hour: 12, value: 3} + # + # the generated report is **always** in UTC timezone + data.map do |d| + date = Time.zone.at(d[:timestamp]).to_s + [date, d[:value]] + end + end + def generate_report(report_params) V2::ReportBuilder.new( Current.account, diff --git a/app/javascript/dashboard/api/reports.js b/app/javascript/dashboard/api/reports.js index 29fefeec8..dbd795f3c 100644 --- a/app/javascript/dashboard/api/reports.js +++ b/app/javascript/dashboard/api/reports.js @@ -59,6 +59,12 @@ class ReportsAPI extends ApiClient { }); } + getConversationTrafficCSV({ from: since, to: until }) { + return axios.get(`${this.url}/conversation_traffic`, { + params: { since, until }, + }); + } + getLabelReports({ from: since, to: until, businessHours }) { return axios.get(`${this.url}/labels`, { params: { since, until, business_hours: businessHours }, diff --git a/app/javascript/dashboard/routes/dashboard/settings/reports/LiveReports.vue b/app/javascript/dashboard/routes/dashboard/settings/reports/LiveReports.vue index 5de08717f..7acfc6251 100644 --- a/app/javascript/dashboard/routes/dashboard/settings/reports/LiveReports.vue +++ b/app/javascript/dashboard/routes/dashboard/settings/reports/LiveReports.vue @@ -40,6 +40,17 @@ +
-
{{ header }}
- - {{ $t('OVERVIEW_REPORTS.LIVE') }} - + +
+
{{ header }}
+ + {{ + $t('OVERVIEW_REPORTS.LIVE') + }} + +
+
+ +
+
@@ -42,37 +51,66 @@ export default {