Merge branch 'develop' into feat/new-auth-screens

This commit is contained in:
Sivin Varghese 2022-04-27 08:31:36 +05:30 committed by GitHub
commit d24a5c98a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 74 additions and 22 deletions

View file

@ -4,7 +4,7 @@ class V2::ReportBuilder
attr_reader :account, :params
DEFAULT_GROUP_BY = 'day'.freeze
AGENT_RESULTS_PER_PAGE = 10
AGENT_RESULTS_PER_PAGE = 25
def initialize(account, params)
@account = account
@ -46,7 +46,7 @@ class V2::ReportBuilder
if params[:type].equal?(:account)
conversations
else
agent_metrics
agent_metrics.sort_by { |hash| hash[:metric][:open] }.reverse
end
end
@ -95,10 +95,10 @@ class V2::ReportBuilder
end
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
metric = {
total: @open_conversations.count,
open: @open_conversations.count,
unattended: @open_conversations.count - first_response_count
}
metric[:unassigned] = @open_conversations.unassigned.count if params[:type].equal?(:account)

View file

@ -1,6 +1,8 @@
<template>
<div class="message-text--metadata">
<span class="time">{{ readableTime }}</span>
<span class="time" :class="{ delivered: messageRead }">{{
readableTime
}}</span>
<span v-if="showSentIndicator" class="time">
<fluent-icon
v-tooltip.top-start="$t('CHAT_LIST.SENT')"
@ -252,6 +254,15 @@ export default {
position: absolute;
right: var(--space-small);
white-space: nowrap;
&.delivered {
right: var(--space-medium);
line-height: 2;
}
}
.read-tick {
position: absolute;
bottom: var(--space-small);
right: var(--space-small);
}
}
}

View file

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

View file

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

View file

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

View file

@ -145,13 +145,13 @@ class Contact < ApplicationRecord
def phone_number_format
return if phone_number.blank?
self.phone_number = changes['phone_number'].first unless phone_number.match?(/\+[1-9]\d{1,14}\z/)
self.phone_number = phone_number_was unless phone_number.match?(/\+[1-9]\d{1,14}\z/)
end
def email_format
return if email.blank?
self.email = changes['email'].first unless email.match(Devise.email_regexp)
self.email = email_was unless email.match(Devise.email_regexp)
end
def prepare_contact_attributes

View file

@ -10,6 +10,7 @@ RSpec.describe 'Reports API', type: :request do
let(:default_timezone) { ActiveSupport::TimeZone[0]&.name }
let(:date_timestamp) { Time.current.in_time_zone(default_timezone).beginning_of_day.to_i }
let(:params) { { timezone_offset: Time.zone.utc_offset } }
let(:new_account) { create(:account) }
before do
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)
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['unassigned']).to eq(1)
end
@ -81,6 +82,8 @@ RSpec.describe 'Reports API', type: :request do
it 'return conversation metrics for user in account level' do
create_list(:conversation, 2, account: account, inbox: inbox,
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",
params: {
@ -96,7 +99,7 @@ RSpec.describe 'Reports API', type: :request do
user_metrics = json_response.find { |item| item['name'] == admin[:name] }
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)
end
@ -116,7 +119,7 @@ RSpec.describe 'Reports API', type: :request do
json_response = JSON.parse(response.body)
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)
end
end

View file

@ -12,7 +12,7 @@ RSpec.describe Contact do
it { is_expected.to have_many(:conversations).dependent(:destroy_async) }
end
context 'pepare contact attributes before validation' do
context 'prepare contact attributes before validation' do
it 'sets email to lowercase' do
contact = create(:contact, email: 'Test@test.com')
expect(contact.email).to eq('test@test.com')
@ -43,4 +43,42 @@ RSpec.describe Contact do
expect(contact.additional_attributes).to eq({})
end
end
# rubocop:disable Rails/SkipsModelValidations
context 'when phone number format' do
it 'will not throw error for existing invalid phone number' do
contact = create(:contact)
contact.update_column(:phone_number, '344234')
contact.reload
expect(contact.update!(name: 'test')).to eq true
expect(contact.phone_number).to eq '344234'
end
it 'updates phone number when adding valid phone number' do
contact = create(:contact)
contact.update_column(:phone_number, '344234')
contact.reload
expect(contact.update!(phone_number: '+12312312321')).to eq true
expect(contact.phone_number).to eq '+12312312321'
end
end
context 'when email format' do
it 'will not throw error for existing invalid email' do
contact = create(:contact)
contact.update_column(:email, 'ssfdasdf <test@test')
contact.reload
expect(contact.update!(name: 'test')).to eq true
expect(contact.email).to eq 'ssfdasdf <test@test'
end
it 'updates email when adding valid email' do
contact = create(:contact)
contact.update_column(:email, 'ssfdasdf <test@test')
contact.reload
expect(contact.update!(email: 'test@test.com')).to eq true
expect(contact.email).to eq 'test@test.com'
end
end
# rubocop:enable Rails/SkipsModelValidations
end