Skip to content

Commit

Permalink
Merge pull request #3835 from 3scale/THREESCALE-9807_analytics_errors…
Browse files Browse the repository at this point in the history
…_toolbar

🦋 Update Product Integration Errors
  • Loading branch information
josemigallas authored Jun 25, 2024
2 parents ab8ce0c + 30d433e commit 532acac
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 76 deletions.
6 changes: 0 additions & 6 deletions app/assets/stylesheets/provider/stats/_base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,3 @@ $stats-chart-tooltip-color: $label-color;
.ui-datepicker {
z-index: 9999 !important;
}

// TODO: Remove when integration errors empty state implemented (https://issues.redhat.com/browse/THREESCALE-9808)
div[id^="transaction_errors_container_"] {
@include white-box-shadow;
padding: line-height-times(1);
}
5 changes: 4 additions & 1 deletion app/controllers/api/errors_controller.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
# frozen_string_literal: true

class Api::ErrorsController < Api::BaseController
helper_method :presenter
attr_reader :presenter

before_action :find_service

activate_menu :serviceadmin, :monitoring, :errors

def index
@errors = errors_service.list(@service.id, pagination_params)
errors = errors_service.list(@service.id, pagination_params)
@presenter = Api::ErrorsIndexPresenter.new(errors: errors, service: @service)
end

def purge
Expand Down
30 changes: 30 additions & 0 deletions app/presenters/api/errors_index_presenter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# frozen_string_literal: true

class Api::ErrorsIndexPresenter
include ::Draper::ViewHelpers

def initialize(errors:, service:)
@errors = errors
@service = service
end

attr_reader :errors, :service

def empty_state?
errors.empty?
end

def toolbar_props
{
totalEntries: errors.total_entries,
pageEntries: errors.length,
actions: [{
variant: :danger,
label: I18n.t('api.errors.index.toolbar.purge.title'),
href: h.admin_service_errors_path(service),
'data-confirm': I18n.t('api.errors.index.toolbar.purge.confirm'),
'data-method': :delete,
}],
}
end
end
2 changes: 1 addition & 1 deletion app/services/integration_errors_service.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class IntegrationErrorsService
def list(service_id, page: 1, per_page: 100)
def list(service_id, page: 1, per_page: 20)
pagination = { page: page, per_page: per_page }
errors = ThreeScale::Core::ServiceError.load_all(service_id, pagination)

Expand Down
37 changes: 0 additions & 37 deletions app/views/api/errors/index.html.erb

This file was deleted.

24 changes: 24 additions & 0 deletions app/views/api/errors/index.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
- content_for :page_header_title, t('.title', service: @service.name)
- content_for :page_header_body, t('.body_html', href: provider_admin_api_docs_path(anchor: '/service_management_api'))

- if presenter.empty_state?
= render partial: 'shared/empty_state', locals: { icon: 'check-circle',
title: t('.empty_state.title'),
body: t('.empty_state.body') }
- else
- content_for :javascripts do
= javascript_packs_with_chunks_tag 'table_toolbar'

table class="pf-c-table pf-m-grid-lg" role="grid" aria-label="Integration errors table" data-toolbar-props=presenter.toolbar_props.to_json
thead
tr role="row"
th role="columnheader" scope="col" Time (UTC)
th role="columnheader" scope="col" Error
td

tbody role="rowgroup"
- presenter.errors.each do |error|
tr role="row"
td role="cell" data-label="Time (UTC)" = error.timestamp
td role="cell" data-label="Error" = h error.message
td
14 changes: 14 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,20 @@ en:
success: The Backend was removed from the Product
error: The Backend cannot be removed from the Product
errors:
index:
title: Integration Errors for %{service}
body_html:
Here you can see errors related to your API's integration with 3scale, in particular in
calls made to methods of 3scale's Service Management API.
Please refer to the <a href=%{href} target="_blank">API ActiveDocs</a> documentation
section on using 3scale's Service Management API.
empty_state:
title: Hooray!
body: No integration errors reported for this service.
toolbar:
purge:
title: Purge
confirm: All errors will be permanently deleted.
purge:
success: All errors were purged.
services:
Expand Down
7 changes: 4 additions & 3 deletions features/api/services/errors.feature
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Feature: Integration errors of a product

Scenario: No errors
Given they go to the integration errors page of product "Pepe API"
Then they should see "Hooray! No integration errors reported for this service."
Then they should see "No integration errors reported for this service."

Rule: There are errors
Background:
Expand All @@ -39,6 +39,7 @@ Feature: Integration errors of a product
| Time (UTC) | Error |
| 2024-03-03 12:00:00 UTC | Error 1 |
| 2024-01-01 13:00:00 UTC | Error 2 |
When press "Purge"
When they select toolbar action "Purge"
And confirm the dialog
Then they should see the flash message "All errors were purged."
And they should see "Hooray! No integration errors reported for this service."
And they should see "No integration errors reported for this service."
28 changes: 28 additions & 0 deletions features/step_definitions/api/services/errors_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

Given "{product} has the following integration errors:" do |product, table|
transform_integration_errors_table(table)
errors = table.hashes.map { |error| ThreeScale::Core::ServiceError.new(error) }
@purge = states('purge').starts_as('pending')

ThreeScale::Core::ServiceError.stubs(:load_all)
.with(product.id, any_parameters)
.when(@purge.is('pending'))
.returns(ThreeScale::Core::APIClient::Collection.new(errors))
end

Given "they want to empty the integration errors table" do
product_id = @product.id

ThreeScale::Core::ServiceError.stubs(:delete_all)
.with(product_id)
.then(@purge.is('done'))
.returns(true)
.once

ThreeScale::Core::ServiceError.stubs(:load_all)
.with(product_id, any_parameters)
.when(@purge.is('done'))
.returns(ThreeScale::Core::APIClient::Collection.new([]))
.once
end
27 changes: 0 additions & 27 deletions features/step_definitions/service_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,33 +86,6 @@
product.update!(buyers_manage_keys: false)
end

Given "{product} has the following integration errors:" do |product, table|
transform_integration_errors_table(table)
errors = table.hashes.map { |error| ThreeScale::Core::ServiceError.new(error) }
@purge = states('purge').starts_as('pending')

ThreeScale::Core::ServiceError.stubs(:load_all)
.with(product.id, any_parameters)
.when(@purge.is('pending'))
.returns(ThreeScale::Core::APIClient::Collection.new(errors))
end

Given "they want to empty the integration errors table" do
product_id = @product.id

ThreeScale::Core::ServiceError.stubs(:delete_all)
.with(product_id)
.then(@purge.is('done'))
.returns(true)
.once

ThreeScale::Core::ServiceError.stubs(:load_all)
.with(product_id, any_parameters)
.when(@purge.is('done'))
.returns(ThreeScale::Core::APIClient::Collection.new([]))
.once
end

Then /^I should see the following backends being used:$/ do |table|
within backends_used_table do
table.raw.each do |row|
Expand Down
2 changes: 1 addition & 1 deletion test/integration/api/errors_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Api::ErrorsControllerTest < ActionDispatch::IntegrationTest

test 'index with pagination' do
get admin_service_errors_path(@service), params: { per_page: 1, page: 2 }
assigned_errors = assigns(:errors)
assigned_errors = assigns(:presenter).errors
assert_equal 2, assigned_errors.size
assigned_errors.each { |error| assert_instance_of(ThreeScale::Core::ServiceError, error) }
assert_same_elements @service_errors, assigned_errors.map { |error| {timestamp: error.timestamp.to_time.iso8601, message: error.message} }
Expand Down

0 comments on commit 532acac

Please sign in to comment.