From 69e61fff38b426109bd074ccf93f5d2874d430c2 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 6 Feb 2024 08:18:37 -0500 Subject: [PATCH] Move direct serializer usage out of admin view partial (#29028) --- app/helpers/react_component_helper.rb | 11 +++++++++++ app/views/admin/reports/_media_attachments.html.haml | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/helpers/react_component_helper.rb b/app/helpers/react_component_helper.rb index ce616e8306..821a6f1e2d 100644 --- a/app/helpers/react_component_helper.rb +++ b/app/helpers/react_component_helper.rb @@ -15,9 +15,20 @@ module ReactComponentHelper div_tag_with_data(data) end + def serialized_media_attachments(media_attachments) + media_attachments.map { |attachment| serialized_attachment(attachment) } + end + private def div_tag_with_data(data) content_tag(:div, nil, data: data) end + + def serialized_attachment(attachment) + ActiveModelSerializers::SerializableResource.new( + attachment, + serializer: REST::MediaAttachmentSerializer + ).as_json + end end diff --git a/app/views/admin/reports/_media_attachments.html.haml b/app/views/admin/reports/_media_attachments.html.haml index 3c52d69178..45cc4c5aa3 100644 --- a/app/views/admin/reports/_media_attachments.html.haml +++ b/app/views/admin/reports/_media_attachments.html.haml @@ -12,6 +12,6 @@ = react_component :media_gallery, height: 343, lang: status.language, - media: status.ordered_media_attachments.map { |a| ActiveModelSerializers::SerializableResource.new(a, serializer: REST::MediaAttachmentSerializer).as_json }, + media: serialized_media_attachments(status.ordered_media_attachments), sensitive: status.sensitive?, visible: false