feat: SLA reports view (#9189)
* feat: SLA report table * feat: Add SLA popover card * feat: Update popover position * feat: Add loader * Update SLACardLabel.vue * feat: Update column order * chore: fix conditions * Update SLATable.vue * chore: enable reports in ui * chore: Revamp report SLA apis * chore: revert download method * chore: improve the code * Update enterprise/app/views/api/v1/accounts/applied_slas/download.csv.erb Co-authored-by: Vishnu Narayanan <iamwishnu@gmail.com> * chore: style fixes * chore: fix specs * feat: Add number of conversations * chore: review comments * fix: translation * Update app/javascript/dashboard/i18n/locale/en/report.json Co-authored-by: Vishnu Narayanan <iamwishnu@gmail.com> * Update app/javascript/dashboard/i18n/locale/en/report.json Co-authored-by: Vishnu Narayanan <iamwishnu@gmail.com> * Update app/javascript/dashboard/i18n/locale/en/report.json Co-authored-by: Vishnu Narayanan <iamwishnu@gmail.com> * Update SLAReportItem.vue * Update report.json * Update package.json * chore: review comments * chore: remove unused translation * feat: Add TableHeaderCell component * chore: more review fixes * Update app/javascript/dashboard/components/widgets/TableHeaderCell.vue Co-authored-by: Shivam Mishra <scm.mymail@gmail.com> * Update TableHeaderCell.vue --------- Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com> Co-authored-by: Vishnu Narayanan <iamwishnu@gmail.com> Co-authored-by: Shivam Mishra <scm.mymail@gmail.com>
This commit is contained in:
@@ -6,22 +6,23 @@ class Api::V1::Accounts::AppliedSlasController < Api::V1::Accounts::EnterpriseAc
|
||||
|
||||
before_action :set_applied_slas, only: [:index, :metrics, :download]
|
||||
before_action :set_current_page, only: [:index]
|
||||
before_action :paginate_slas, only: [:index]
|
||||
before_action :check_admin_authorization?
|
||||
|
||||
sort_on :created_at, type: :datetime
|
||||
|
||||
def index; end
|
||||
def index
|
||||
@count = number_of_sla_misses
|
||||
@applied_slas = @missed_applied_slas.page(@current_page).per(RESULTS_PER_PAGE)
|
||||
end
|
||||
|
||||
def metrics
|
||||
@total_applied_slas = total_applied_slas
|
||||
@number_of_sla_breaches = number_of_sla_breaches
|
||||
@number_of_sla_misses = number_of_sla_misses
|
||||
@hit_rate = hit_rate
|
||||
end
|
||||
|
||||
def download
|
||||
@breached_slas = breached_slas
|
||||
|
||||
@missed_applied_slas = missed_applied_slas
|
||||
response.headers['Content-Type'] = 'text/csv'
|
||||
response.headers['Content-Disposition'] = 'attachment; filename=breached_conversation.csv'
|
||||
render layout: false, formats: [:csv]
|
||||
@@ -29,41 +30,38 @@ class Api::V1::Accounts::AppliedSlasController < Api::V1::Accounts::EnterpriseAc
|
||||
|
||||
private
|
||||
|
||||
def breached_slas
|
||||
@applied_slas.includes(:sla_policy).joins(:conversation)
|
||||
.where.not(conversations: { status: :resolved })
|
||||
.where(applied_slas: { sla_status: :missed })
|
||||
end
|
||||
|
||||
def total_applied_slas
|
||||
@total_applied_slas ||= @applied_slas.count
|
||||
end
|
||||
|
||||
def number_of_sla_breaches
|
||||
@number_of_sla_breaches ||= @applied_slas.missed.count
|
||||
def number_of_sla_misses
|
||||
@number_of_sla_misses ||= missed_applied_slas.count
|
||||
end
|
||||
|
||||
def hit_rate
|
||||
number_of_sla_breaches.zero? ? '100%' : "#{hit_rate_percentage}%"
|
||||
number_of_sla_misses.zero? ? '100%' : "#{hit_rate_percentage}%"
|
||||
end
|
||||
|
||||
def hit_rate_percentage
|
||||
((total_applied_slas - number_of_sla_breaches) / total_applied_slas.to_f * 100).round(2)
|
||||
((total_applied_slas - number_of_sla_misses) / total_applied_slas.to_f * 100).round(2)
|
||||
end
|
||||
|
||||
def set_applied_slas
|
||||
initial_query = Current.account.applied_slas.includes(:conversation)
|
||||
@applied_slas = initial_query
|
||||
.filter_by_date_range(range)
|
||||
.filter_by_inbox_id(params[:inbox_id])
|
||||
.filter_by_team_id(params[:team_id])
|
||||
.filter_by_sla_policy_id(params[:sla_policy_id])
|
||||
.filter_by_label_list(params[:label_list])
|
||||
.filter_by_assigned_agent_id(params[:assigned_agent_id])
|
||||
@applied_slas = apply_filters(initial_query)
|
||||
end
|
||||
|
||||
def paginate_slas
|
||||
@applied_slas = @applied_slas.page(@current_page).per(RESULTS_PER_PAGE)
|
||||
def apply_filters(query)
|
||||
query.filter_by_date_range(range)
|
||||
.filter_by_inbox_id(params[:inbox_id])
|
||||
.filter_by_team_id(params[:team_id])
|
||||
.filter_by_sla_policy_id(params[:sla_policy_id])
|
||||
.filter_by_label_list(params[:label_list])
|
||||
.filter_by_assigned_agent_id(params[:assigned_agent_id])
|
||||
end
|
||||
|
||||
def missed_applied_slas
|
||||
@missed_applied_slas ||= @applied_slas.missed
|
||||
end
|
||||
|
||||
def set_current_page
|
||||
|
||||
@@ -39,7 +39,7 @@ class AppliedSla < ApplicationRecord
|
||||
joins(:conversation).where(conversations: { assigned_agent_id: assigned_agent_id })
|
||||
end
|
||||
}
|
||||
scope :missed, -> { where(sla_status: :missed) }
|
||||
scope :missed, -> { where(sla_status: %i[missed active_with_misses]) }
|
||||
|
||||
after_update_commit :push_conversation_event
|
||||
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
] %>
|
||||
<%= CSV.generate_line headers %>
|
||||
|
||||
<% @breached_slas.each do |sla| %>
|
||||
<% breached_events = sla.sla_events.map(&:event_type).join(', ') %>
|
||||
<% @missed_applied_slas.each do |sla| %>
|
||||
<% missed_events = sla.sla_events.map(&:event_type).join(', ') %>
|
||||
<% conversation = sla.conversation %>
|
||||
<%= CSV.generate_line([
|
||||
conversation.display_id,
|
||||
@@ -21,6 +21,6 @@
|
||||
conversation.inbox&.name,
|
||||
conversation.cached_label_list,
|
||||
app_account_conversation_url(account_id: conversation.account_id, id: conversation.display_id),
|
||||
breached_events
|
||||
missed_events
|
||||
]) %>
|
||||
<% end %>
|
||||
|
||||
@@ -1,14 +1,22 @@
|
||||
json.array! @applied_slas do |applied_sla|
|
||||
json.id applied_sla.id
|
||||
json.sla_policy_id applied_sla.sla_policy_id
|
||||
json.conversation_id applied_sla.conversation_id
|
||||
json.sla_status applied_sla.sla_status
|
||||
json.created_at applied_sla.created_at
|
||||
json.updated_at applied_sla.updated_at
|
||||
json.conversation do
|
||||
json.partial! 'api/v1/models/conversation', conversation: applied_sla.conversation
|
||||
end
|
||||
json.sla_events applied_sla.sla_events do |sla_event|
|
||||
json.partial! 'api/v1/models/sla_event', formats: [:json], sla_event: sla_event
|
||||
json.payload do
|
||||
json.array! @applied_slas do |applied_sla|
|
||||
json.applied_sla applied_sla.push_event_data
|
||||
json.conversation do
|
||||
conversation = applied_sla.conversation
|
||||
json.id conversation.id
|
||||
json.contact do
|
||||
json.name conversation.contact.name if conversation.contact
|
||||
end
|
||||
json.labels conversation.cached_label_list
|
||||
json.assignee conversation.assignee.push_event_data if conversation.assignee
|
||||
end
|
||||
json.sla_events applied_sla.sla_events do |sla_event|
|
||||
json.partial! 'api/v1/models/sla_event', formats: [:json], sla_event: sla_event
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
json.meta do
|
||||
json.count @count
|
||||
json.current_page @current_page
|
||||
end
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
json.total_applied_slas @total_applied_slas
|
||||
json.number_of_sla_breaches @number_of_sla_breaches
|
||||
json.number_of_sla_misses @number_of_sla_misses
|
||||
json.hit_rate @hit_rate
|
||||
|
||||
Reference in New Issue
Block a user