fix: Update agent metrics query to show data from current account (#4557)

* Update agent metrics query to fetch data from current account
This commit is contained in:
Aswin Dev P.S 2022-04-26 18:22:13 +05:30 committed by GitHub
parent 3a5e34fccb
commit 1bf2da180b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 21 additions and 18 deletions

View file

@ -4,7 +4,7 @@ class V2::ReportBuilder
attr_reader :account, :params attr_reader :account, :params
DEFAULT_GROUP_BY = 'day'.freeze DEFAULT_GROUP_BY = 'day'.freeze
AGENT_RESULTS_PER_PAGE = 10 AGENT_RESULTS_PER_PAGE = 25
def initialize(account, params) def initialize(account, params)
@account = account @account = account
@ -46,7 +46,7 @@ class V2::ReportBuilder
if params[:type].equal?(:account) if params[:type].equal?(:account)
conversations conversations
else else
agent_metrics agent_metrics.sort_by { |hash| hash[:metric][:open] }.reverse
end end
end end
@ -95,10 +95,10 @@ class V2::ReportBuilder
end end
def conversations def conversations
@open_conversations = scope.conversations.open @open_conversations = scope.conversations.where(account_id: @account.id).open
first_response_count = scope.reporting_events.where(name: 'first_response', conversation_id: @open_conversations.pluck('id')).count first_response_count = scope.reporting_events.where(name: 'first_response', conversation_id: @open_conversations.pluck('id')).count
metric = { metric = {
total: @open_conversations.count, open: @open_conversations.count,
unattended: @open_conversations.count - first_response_count unattended: @open_conversations.count - first_response_count
} }
metric[:unassigned] = @open_conversations.unassigned.count if params[:type].equal?(:account) metric[:unassigned] = @open_conversations.unassigned.count if params[:type].equal?(:account)

View file

@ -387,18 +387,18 @@
"LIVE": "Live", "LIVE": "Live",
"ACCOUNT_CONVERSATIONS": { "ACCOUNT_CONVERSATIONS": {
"HEADER": "Open Conversations", "HEADER": "Open Conversations",
"LOADING_MESSAGE": "Conversations Loading...", "LOADING_MESSAGE": "Loading conversation metrics...",
"TOTAL" : "Total", "OPEN" : "Open",
"UNATTENDED": "Unattended", "UNATTENDED": "Unattended",
"UNASSIGNED": "Unassigned" "UNASSIGNED": "Unassigned"
}, },
"AGENT_CONVERSATIONS": { "AGENT_CONVERSATIONS": {
"HEADER": "Conversations by agents", "HEADER": "Conversations by agents",
"LOADING_MESSAGE": "Agents Loading...", "LOADING_MESSAGE": "Loading agent metrics...",
"NO_AGENTS": "There are no conversations by agents", "NO_AGENTS": "There are no conversations by agents",
"TABLE_HEADER": { "TABLE_HEADER": {
"AGENT": "Agent", "AGENT": "Agent",
"TOTAL": "Total", "OPEN": "OPEN",
"UNATTENDED": "Unattended", "UNATTENDED": "Unattended",
"STATUS": "Status" "STATUS": "Status"
} }

View file

@ -20,8 +20,8 @@
<ve-pagination <ve-pagination
:total="totalAgents" :total="totalAgents"
:page-index="pageIndex" :page-index="pageIndex"
:page-size="10" :page-size="25"
:page-size-option="[10]" :page-size-option="[25]"
@on-page-number-change="onPageNumberChange" @on-page-number-change="onPageNumberChange"
/> />
</div> </div>
@ -70,7 +70,7 @@ export default {
agent: agent.name, agent: agent.name,
email: agent.email, email: agent.email,
thumbnail: agent.thumbnail, thumbnail: agent.thumbnail,
total: agent.metric.total || 0, open: agent.metric.open || 0,
unattended: agent.metric.unattended || 0, unattended: agent.metric.unattended || 0,
status: agent.availability, status: agent.availability,
}; };
@ -103,10 +103,10 @@ export default {
), ),
}, },
{ {
field: 'total', field: 'open',
key: 'total', key: 'open',
title: this.$t( title: this.$t(
'OVERVIEW_REPORTS.AGENT_CONVERSATIONS.TABLE_HEADER.TOTAL' 'OVERVIEW_REPORTS.AGENT_CONVERSATIONS.TABLE_HEADER.OPEN'
), ),
align: 'left', align: 'left',
width: 10, width: 10,

View file

@ -123,7 +123,7 @@ export const METRIC_CHART = {
}; };
export const OVERVIEW_METRICS = { export const OVERVIEW_METRICS = {
total: 'TOTAL', open: 'OPEN',
unattended: 'UNATTENDED', unattended: 'UNATTENDED',
unassigned: 'UNASSIGNED', unassigned: 'UNASSIGNED',
online: 'ONLINE', online: 'ONLINE',

View file

@ -10,6 +10,7 @@ RSpec.describe 'Reports API', type: :request do
let(:default_timezone) { ActiveSupport::TimeZone[0]&.name } let(:default_timezone) { ActiveSupport::TimeZone[0]&.name }
let(:date_timestamp) { Time.current.in_time_zone(default_timezone).beginning_of_day.to_i } let(:date_timestamp) { Time.current.in_time_zone(default_timezone).beginning_of_day.to_i }
let(:params) { { timezone_offset: Time.zone.utc_offset } } let(:params) { { timezone_offset: Time.zone.utc_offset } }
let(:new_account) { create(:account) }
before do before do
create_list(:conversation, 10, account: account, inbox: inbox, create_list(:conversation, 10, account: account, inbox: inbox,
@ -73,7 +74,7 @@ RSpec.describe 'Reports API', type: :request do
expect(response).to have_http_status(:success) expect(response).to have_http_status(:success)
json_response = JSON.parse(response.body) json_response = JSON.parse(response.body)
expect(json_response['total']).to eq(11) expect(json_response['open']).to eq(11)
expect(json_response['unattended']).to eq(11) expect(json_response['unattended']).to eq(11)
expect(json_response['unassigned']).to eq(1) expect(json_response['unassigned']).to eq(1)
end end
@ -81,6 +82,8 @@ RSpec.describe 'Reports API', type: :request do
it 'return conversation metrics for user in account level' do it 'return conversation metrics for user in account level' do
create_list(:conversation, 2, account: account, inbox: inbox, create_list(:conversation, 2, account: account, inbox: inbox,
assignee: admin, created_at: Time.zone.today) assignee: admin, created_at: Time.zone.today)
create_list(:conversation, 2, account: new_account, inbox: inbox,
assignee: admin, created_at: Time.zone.today)
get "/api/v2/accounts/#{account.id}/reports/conversations", get "/api/v2/accounts/#{account.id}/reports/conversations",
params: { params: {
@ -96,7 +99,7 @@ RSpec.describe 'Reports API', type: :request do
user_metrics = json_response.find { |item| item['name'] == admin[:name] } user_metrics = json_response.find { |item| item['name'] == admin[:name] }
expect(user_metrics.present?).to be true expect(user_metrics.present?).to be true
expect(user_metrics['metric']['total']).to eq(2) expect(user_metrics['metric']['open']).to eq(2)
expect(user_metrics['metric']['unattended']).to eq(2) expect(user_metrics['metric']['unattended']).to eq(2)
end end
@ -116,7 +119,7 @@ RSpec.describe 'Reports API', type: :request do
json_response = JSON.parse(response.body) json_response = JSON.parse(response.body)
expect(json_response.blank?).to be false expect(json_response.blank?).to be false
expect(json_response[0]['metric']['total']).to eq(10) expect(json_response[0]['metric']['open']).to eq(10)
expect(json_response[0]['metric']['unattended']).to eq(10) expect(json_response[0]['metric']['unattended']).to eq(10)
end end
end end