From 1e1d7996bb45b7dbfae6fb284c2efb396bd72926 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 12 Oct 2023 21:21:42 +0200 Subject: [PATCH] Simplify rendering document/image fields We were adding
tags with the `images` or `documents` HTML class prettly much every time we rendered a NestedComponent. We're now including the HTML class inside the component, as we usually do. We're also rendering the nested components directly, since it's been a while since the partials were changed to simply render the components. --- .../admin/budget_phases/form_component.html.erb | 4 ++-- app/components/admin/budgets/form_component.html.erb | 4 ++-- .../questions/answers/documents/index_component.html.erb | 4 +--- .../budgets/investments/form_component.html.erb | 8 ++------ app/components/documents/nested_component.html.erb | 2 +- app/components/images/nested_component.html.erb | 2 +- app/components/proposals/form_component.html.erb | 8 ++------ app/views/admin/dashboard/actions/_form.html.erb | 4 ++-- app/views/admin/legislation/processes/_form.html.erb | 8 ++++---- app/views/admin/milestones/_form.html.erb | 7 ++----- app/views/admin/poll/polls/_form.html.erb | 4 ++-- .../admin/poll/questions/answers/images/new.html.erb | 4 +--- app/views/admin/widget/cards/_form.html.erb | 2 +- app/views/documents/_nested_documents.html.erb | 1 - app/views/images/_nested_image.html.erb | 1 - app/views/legislation/proposals/_form.html.erb | 8 ++++---- 16 files changed, 27 insertions(+), 44 deletions(-) delete mode 100644 app/views/documents/_nested_documents.html.erb delete mode 100644 app/views/images/_nested_image.html.erb diff --git a/app/components/admin/budget_phases/form_component.html.erb b/app/components/admin/budget_phases/form_component.html.erb index 369373454..d9b494220 100644 --- a/app/components/admin/budget_phases/form_component.html.erb +++ b/app/components/admin/budget_phases/form_component.html.erb @@ -56,8 +56,8 @@ <% end %> <% if feature?(:allow_images) %> -
- <%= render "images/nested_image", f: f %> +
+ <%= render Images::NestedComponent.new(f) %>

<%= t("admin.budget_phases.edit.image_description") %>

<% end %> diff --git a/app/components/admin/budgets/form_component.html.erb b/app/components/admin/budgets/form_component.html.erb index 38cc4e6f6..0f958d4d9 100644 --- a/app/components/admin/budgets/form_component.html.erb +++ b/app/components/admin/budgets/form_component.html.erb @@ -54,8 +54,8 @@ <% end %> <% if feature?(:allow_images) %> -
- <%= render "/images/nested_image", f: f %> +
+ <%= render Images::NestedComponent.new(f) %>

<%= t("admin.budgets.edit.image_description") %>

<% end %> diff --git a/app/components/admin/poll/questions/answers/documents/index_component.html.erb b/app/components/admin/poll/questions/answers/documents/index_component.html.erb index b23f46ef2..627159982 100644 --- a/app/components/admin/poll/questions/answers/documents/index_component.html.erb +++ b/app/components/admin/poll/questions/answers/documents/index_component.html.erb @@ -12,9 +12,7 @@ <%= form_for(Poll::Question::Answer.new, url: admin_answer_documents_path(answer)) do |f| %> <%= render "shared/errors", resource: answer %> -
- <%= render "documents/nested_documents", f: f %> -
+ <%= render Documents::NestedComponent.new(f) %>
<%= f.submit(class: "button expanded", value: t("shared.save")) %> diff --git a/app/components/budgets/investments/form_component.html.erb b/app/components/budgets/investments/form_component.html.erb index daa0aec4a..228aec322 100644 --- a/app/components/budgets/investments/form_component.html.erb +++ b/app/components/budgets/investments/form_component.html.erb @@ -37,15 +37,11 @@ <%= t("shared.optional") %> <% if feature?(:allow_images) %> -
- <%= render "images/nested_image", f: f %> -
+ <%= render Images::NestedComponent.new(f) %> <% end %> <% if feature?(:allow_attached_documents) %> -
- <%= render "documents/nested_documents", f: f %> -
+ <%= render Documents::NestedComponent.new(f) %> <% end %> <% if feature?(:map) %> diff --git a/app/components/documents/nested_component.html.erb b/app/components/documents/nested_component.html.erb index 743cd7be3..d47185ae8 100644 --- a/app/components/documents/nested_component.html.erb +++ b/app/components/documents/nested_component.html.erb @@ -1,4 +1,4 @@ -
+
<%= t("documents.form.title") %>

<%= note %>

diff --git a/app/components/images/nested_component.html.erb b/app/components/images/nested_component.html.erb index 0505ea4de..578cb53fe 100644 --- a/app/components/images/nested_component.html.erb +++ b/app/components/images/nested_component.html.erb @@ -1,4 +1,4 @@ -
+
<%= t("images.form.title") %>

<%= note %>

diff --git a/app/components/proposals/form_component.html.erb b/app/components/proposals/form_component.html.erb index f6084f3b8..fddca56bb 100644 --- a/app/components/proposals/form_component.html.erb +++ b/app/components/proposals/form_component.html.erb @@ -38,15 +38,11 @@
<% if feature?(:allow_images) %> -
- <%= render "images/nested_image", f: f %> -
+ <%= render Images::NestedComponent.new(f) %> <% end %> <% if feature?(:allow_attached_documents) %> -
- <%= render "documents/nested_documents", f: f %> -
+ <%= render Documents::NestedComponent.new(f) %> <% end %> <% if Geozone.any? %> diff --git a/app/views/admin/dashboard/actions/_form.html.erb b/app/views/admin/dashboard/actions/_form.html.erb index f479f6ad7..3dd147172 100644 --- a/app/views/admin/dashboard/actions/_form.html.erb +++ b/app/views/admin/dashboard/actions/_form.html.erb @@ -64,8 +64,8 @@
<% if feature?(:allow_attached_documents) %> -
- <%= render "documents/nested_documents", f: f %> +
+ <%= render Documents::NestedComponent.new(f) %>
<% end %> diff --git a/app/views/admin/legislation/processes/_form.html.erb b/app/views/admin/legislation/processes/_form.html.erb index 0fe41f941..0f461bfd7 100644 --- a/app/views/admin/legislation/processes/_form.html.erb +++ b/app/views/admin/legislation/processes/_form.html.erb @@ -109,12 +109,12 @@
-
- <%= render "documents/nested_documents", f: f %> +
+ <%= render Documents::NestedComponent.new(f) %>
-
- <%= render "images/nested_image", f: f %> +
+ <%= render Images::NestedComponent.new(f) %>
diff --git a/app/views/admin/milestones/_form.html.erb b/app/views/admin/milestones/_form.html.erb index 7198f1c93..2d7d6b2a1 100644 --- a/app/views/admin/milestones/_form.html.erb +++ b/app/views/admin/milestones/_form.html.erb @@ -27,11 +27,8 @@
<%= f.date_field :publication_date %> - <%= render "images/nested_image", f: f %> - -
- <%= render "documents/nested_documents", f: f %> -
+ <%= render Images::NestedComponent.new(f) %> + <%= render Documents::NestedComponent.new(f) %> <%= f.submit nil, class: "button success" %>
diff --git a/app/views/admin/poll/polls/_form.html.erb b/app/views/admin/poll/polls/_form.html.erb index dd0b59292..332011a20 100644 --- a/app/views/admin/poll/polls/_form.html.erb +++ b/app/views/admin/poll/polls/_form.html.erb @@ -32,8 +32,8 @@
-
- <%= render "images/nested_image", f: f %> +
+ <%= render Images::NestedComponent.new(f) %>
diff --git a/app/views/admin/poll/questions/answers/images/new.html.erb b/app/views/admin/poll/questions/answers/images/new.html.erb index e4ddaa769..3c85c0b57 100644 --- a/app/views/admin/poll/questions/answers/images/new.html.erb +++ b/app/views/admin/poll/questions/answers/images/new.html.erb @@ -2,9 +2,7 @@ <%= form_for(@answer, url: admin_answer_images_path(@answer), method: :post) do |f| %> <%= render "shared/errors", resource: @answer %> -
- <%= render Images::NestedComponent.new(f, image_fields: :images) %> -
+ <%= render Images::NestedComponent.new(f, image_fields: :images) %> <%= f.submit t("admin.questions.answers.images.save_image"), class: "button success" %> <% end %> diff --git a/app/views/admin/widget/cards/_form.html.erb b/app/views/admin/widget/cards/_form.html.erb index 606697f4d..d01dc0cc1 100644 --- a/app/views/admin/widget/cards/_form.html.erb +++ b/app/views/admin/widget/cards/_form.html.erb @@ -45,7 +45,7 @@
- <%= render "images/nested_image", f: f %> + <%= render Images::NestedComponent.new(f) %>
diff --git a/app/views/documents/_nested_documents.html.erb b/app/views/documents/_nested_documents.html.erb deleted file mode 100644 index 229840e83..000000000 --- a/app/views/documents/_nested_documents.html.erb +++ /dev/null @@ -1 +0,0 @@ -<%= render Documents::NestedComponent.new(f) %> diff --git a/app/views/images/_nested_image.html.erb b/app/views/images/_nested_image.html.erb deleted file mode 100644 index c55ccaa56..000000000 --- a/app/views/images/_nested_image.html.erb +++ /dev/null @@ -1 +0,0 @@ -<%= render Images::NestedComponent.new(f) %> diff --git a/app/views/legislation/proposals/_form.html.erb b/app/views/legislation/proposals/_form.html.erb index 69a699bf5..b1cf5d8b4 100644 --- a/app/views/legislation/proposals/_form.html.erb +++ b/app/views/legislation/proposals/_form.html.erb @@ -27,13 +27,13 @@
<% if feature?(:allow_images) %> -
- <%= render "images/nested_image", f: f %> +
+ <%= render Images::NestedComponent.new(f) %>
<% end %> -
- <%= render "documents/nested_documents", f: f %> +
+ <%= render Documents::NestedComponent.new(f) %>
<% if Geozone.any? %>