Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

[#48266] Replace Webhooks cells by ViewComponent

Dombi Attila5c413df12521
diff --git a/modules/webhooks/app/cells/webhooks/outgoing/deliveries/response/show.erb b/modules/webhooks/app/components/webhooks/outgoing/deliveries/response_component.html.erb
similarity index 100%
rename from modules/webhooks/app/cells/webhooks/outgoing/deliveries/response/show.erb
rename to modules/webhooks/app/components/webhooks/outgoing/deliveries/response_component.html.erb
diff --git a/modules/webhooks/app/cells/webhooks/outgoing/deliveries/response_cell.rb b/modules/webhooks/app/components/webhooks/outgoing/deliveries/response_component.rb
similarity index 69%
rename from modules/webhooks/app/cells/webhooks/outgoing/deliveries/response_cell.rb
rename to modules/webhooks/app/components/webhooks/outgoing/deliveries/response_component.rb
index 97546358696..ed12c33b4f4 100644
--- a/modules/webhooks/app/cells/webhooks/outgoing/deliveries/response_cell.rb
+++ b/modules/webhooks/app/components/webhooks/outgoing/deliveries/response_component.rb
@@ -1,9 +1,7 @@
module ::Webhooks
module Outgoing
module Deliveries
- class ResponseCell < RailsCell
- view_paths << ::OpenProject::Webhooks::Engine.root.join("app/cells")
-
+ class ResponseComponent < RailsComponent
property :id
property :response_headers
property :response_body
diff --git a/modules/webhooks/app/cells/webhooks/outgoing/deliveries/row_cell.rb b/modules/webhooks/app/components/webhooks/outgoing/deliveries/row_component.rb
similarity index 64%
rename from modules/webhooks/app/cells/webhooks/outgoing/deliveries/row_cell.rb
rename to modules/webhooks/app/components/webhooks/outgoing/deliveries/row_component.rb
index 3652e8c687b..d3d9074f7cf 100644
--- a/modules/webhooks/app/cells/webhooks/outgoing/deliveries/row_cell.rb
+++ b/modules/webhooks/app/components/webhooks/outgoing/deliveries/row_component.rb
@@ -1,9 +1,11 @@
module ::Webhooks
module Outgoing
module Deliveries
- class RowCell < ::RowCell
+ class RowComponent < ::RowComponent
include ::IconsHelper
+ property :id, :description, :event_name, :response_code
+
def log
model
end
@@ -13,7 +15,7 @@ module ::Webhooks
end
def response_body
- cell(ResponseCell, log).()
+ render ResponseComponent.new(log)
end
end
end
diff --git a/modules/webhooks/app/cells/webhooks/outgoing/deliveries/table_cell.rb b/modules/webhooks/app/components/webhooks/outgoing/deliveries/table_component.rb
similarity index 94%
rename from modules/webhooks/app/cells/webhooks/outgoing/deliveries/table_cell.rb
rename to modules/webhooks/app/components/webhooks/outgoing/deliveries/table_component.rb
index 2aa53211487..26a01092973 100644
--- a/modules/webhooks/app/cells/webhooks/outgoing/deliveries/table_cell.rb
+++ b/modules/webhooks/app/components/webhooks/outgoing/deliveries/table_component.rb
@@ -1,7 +1,7 @@
module ::Webhooks
module Outgoing
module Deliveries
- class TableCell < ::TableCell
+ class TableComponent < ::TableComponent
columns :id, :event_name, :time, :response_code, :response_body
def sortable?
diff --git a/modules/webhooks/app/cells/webhooks/outgoing/webhooks/row_cell.rb b/modules/webhooks/app/components/webhooks/outgoing/webhooks/row_component.rb
similarity index 96%
rename from modules/webhooks/app/cells/webhooks/outgoing/webhooks/row_cell.rb
rename to modules/webhooks/app/components/webhooks/outgoing/webhooks/row_component.rb
index 393ed763870..aef519745ce 100644
--- a/modules/webhooks/app/cells/webhooks/outgoing/webhooks/row_cell.rb
+++ b/modules/webhooks/app/components/webhooks/outgoing/webhooks/row_component.rb
@@ -1,9 +1,11 @@
module ::Webhooks
module Outgoing
module Webhooks
- class RowCell < ::RowCell
+ class RowComponent < ::RowComponent
include ::IconsHelper
+ property :description
+
def webhook
model
end
diff --git a/modules/webhooks/app/cells/webhooks/outgoing/webhooks/table_cell.rb b/modules/webhooks/app/components/webhooks/outgoing/webhooks/table_component.rb
similarity index 96%
rename from modules/webhooks/app/cells/webhooks/outgoing/webhooks/table_cell.rb
rename to modules/webhooks/app/components/webhooks/outgoing/webhooks/table_component.rb
index fc99ada650b..79269a23081 100644
--- a/modules/webhooks/app/cells/webhooks/outgoing/webhooks/table_cell.rb
+++ b/modules/webhooks/app/components/webhooks/outgoing/webhooks/table_component.rb
@@ -1,7 +1,7 @@
module ::Webhooks
module Outgoing
module Webhooks
- class TableCell < ::TableCell
+ class TableComponent < ::TableComponent
columns :name, :enabled, :selected_projects, :events, :description
def initial_sort
diff --git a/modules/webhooks/app/views/webhooks/outgoing/admin/index.html.erb b/modules/webhooks/app/views/webhooks/outgoing/admin/index.html.erb
index fbf8564f500..7d3c2e4763f 100644
--- a/modules/webhooks/app/views/webhooks/outgoing/admin/index.html.erb
+++ b/modules/webhooks/app/views/webhooks/outgoing/admin/index.html.erb
@@ -18,5 +18,5 @@
link: link_to(t(:'webhooks.outgoing.explanation.link'), admin_settings_aggregation_path, target: '_blank')).html_safe %>
</p>
-<%= rails_cell ::Webhooks::Outgoing::Webhooks::TableCell, @webhooks %>
+<%= render ::Webhooks::Outgoing::Webhooks::TableComponent.new(rows: @webhooks) %>
diff --git a/modules/webhooks/app/views/webhooks/outgoing/admin/show.html.erb b/modules/webhooks/app/views/webhooks/outgoing/admin/show.html.erb
index 035f63bdc8c..58b1e800278 100644
--- a/modules/webhooks/app/views/webhooks/outgoing/admin/show.html.erb
+++ b/modules/webhooks/app/views/webhooks/outgoing/admin/show.html.erb
@@ -69,5 +69,5 @@
<div class="account--section">
<h2><%= t 'webhooks.outgoing.deliveries.title' %></h2>
- <%= rails_cell ::Webhooks::Outgoing::Deliveries::TableCell, @webhook.deliveries.newest %>
+ <%= render ::Webhooks::Outgoing::Deliveries::TableComponent.new(rows: @webhook.deliveries.newest) %>
</div>
\ No newline at end of file
diff --git a/modules/webhooks/spec/cells/webhooks/outgoing/deliveries/table_cell_spec.rb b/modules/webhooks/spec/components/webhooks/outgoing/deliveries/table_component_spec.rb
similarity index 76%
rename from modules/webhooks/spec/cells/webhooks/outgoing/deliveries/table_cell_spec.rb
rename to modules/webhooks/spec/components/webhooks/outgoing/deliveries/table_component_spec.rb
index f52f994c8c7..3d61377f275 100644
--- a/modules/webhooks/spec/cells/webhooks/outgoing/deliveries/table_cell_spec.rb
+++ b/modules/webhooks/spec/components/webhooks/outgoing/deliveries/table_component_spec.rb
@@ -27,27 +27,21 @@
#++
require 'spec_helper'
-describe Webhooks::Outgoing::Deliveries::TableCell do
- include Cell::Testing
-
- # used internally by Cell::Testing when calling #cell helper
- let(:controller) { instance_double(ApplicationController, request: :dummy_request) }
-
+describe Webhooks::Outgoing::Deliveries::TableComponent, type: :component do
it 'escapes response body html' do
delivery = create(:webhook_log, response_body: 'Hello <b>world<b/>!')
- html = cell(described_class, [delivery]).()
+ render_inline described_class.new(rows: [delivery])
- response_body_node = Capybara.string(html).find('pre.webhooks--response-body')
- expect(response_body_node.text).to eq(delivery.response_body)
+ expect(page).to have_css("pre.webhooks--response-body", text: delivery.response_body)
end
it 'escapes response headers html' do
header_name = "x_header_<b>evil</b>_name"
header_value = "header <b>evil</b> value"
delivery = create(:webhook_log, response_headers: { header_name => header_value })
- html = cell(described_class, [delivery]).()
+ render_inline described_class.new(rows: [delivery])
- response_headers_node = Capybara.string(html).find('pre.webhooks--response-headers')
+ response_headers_node = page.find('pre.webhooks--response-headers')
aggregate_failures do
expect(response_headers_node).not_to have_selector('b', text: 'evil')
expect(response_headers_node.text).to include(header_name)