From 960f6932194ed2d0dc19909b302e94d8eb1c7d88 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Fri, 25 Jul 2025 03:21:08 -0400 Subject: [PATCH] Use `field` partial in admin account show view (#35503) --- app/helpers/home_helper.rb | 4 ++-- app/views/admin/accounts/_field.html.haml | 9 +++++++++ app/views/admin/accounts/show.html.haml | 20 ++++++-------------- spec/helpers/home_helper_spec.rb | 20 ++++++++------------ 4 files changed, 25 insertions(+), 28 deletions(-) create mode 100644 app/views/admin/accounts/_field.html.haml diff --git a/app/helpers/home_helper.rb b/app/helpers/home_helper.rb index c5b83326db3..7b9d3f4fc1a 100644 --- a/app/helpers/home_helper.rb +++ b/app/helpers/home_helper.rb @@ -49,8 +49,8 @@ module HomeHelper end end - def custom_field_classes(field) - if field.verified? + def field_verified_class(verified) + if verified 'verified' else 'emojify' diff --git a/app/views/admin/accounts/_field.html.haml b/app/views/admin/accounts/_field.html.haml new file mode 100644 index 00000000000..ce8d80785e6 --- /dev/null +++ b/app/views/admin/accounts/_field.html.haml @@ -0,0 +1,9 @@ +-# locals: (field:, account:) +%dl + %dt.emojify{ title: field.name } + = prerender_custom_emojis(h(field.name), account.emojis) + %dd{ title: field.value, class: field_verified_class(field.verified?) } + - if field.verified? + %span.verified__mark{ title: t('accounts.link_verified_on', date: l(field.verified_at)) } + = material_symbol 'check' + = prerender_custom_emojis(account_field_value_format(field, with_rel_me: false), account.emojis) diff --git a/app/views/admin/accounts/show.html.haml b/app/views/admin/accounts/show.html.haml index f148b9a0822..977967c58fb 100644 --- a/app/views/admin/accounts/show.html.haml +++ b/app/views/admin/accounts/show.html.haml @@ -7,25 +7,17 @@ = render 'application/card', account: @account -- account = @account -- fields = account.fields -- unless fields.empty? && account.note.blank? +- if @account.fields? || @account.note? .admin-account-bio - - unless fields.empty? + - if @account.fields? %div .account__header__fields - - fields.each do |field| - %dl - %dt.emojify{ title: field.name }= prerender_custom_emojis(h(field.name), account.emojis) - %dd{ title: field.value, class: custom_field_classes(field) } - - if field.verified? - %span.verified__mark{ title: t('accounts.link_verified_on', date: l(field.verified_at)) } - = material_symbol 'check' - = prerender_custom_emojis(account_field_value_format(field, with_rel_me: false), account.emojis) + = render partial: 'field', collection: @account.fields, locals: { account: @account } - - if account.note.present? + - if @account.note? %div - .account__header__content.emojify= prerender_custom_emojis(account_bio_format(account), account.emojis) + .account__header__content.emojify + = prerender_custom_emojis(account_bio_format(@account), @account.emojis) = render 'admin/accounts/counters', account: @account diff --git a/spec/helpers/home_helper_spec.rb b/spec/helpers/home_helper_spec.rb index c3fbff4e8bb..a8f6d99f032 100644 --- a/spec/helpers/home_helper_spec.rb +++ b/spec/helpers/home_helper_spec.rb @@ -75,23 +75,19 @@ RSpec.describe HomeHelper do end end - describe 'custom_field_classes' do - context 'with a verified field' do - let(:field) { instance_double(Account::Field, verified?: true) } + describe 'field_verified_class' do + subject { helper.field_verified_class(verified) } - it 'returns verified string' do - result = helper.custom_field_classes(field) - expect(result).to eq 'verified' - end + context 'with a verified field' do + let(:verified) { true } + + it { is_expected.to eq('verified') } end context 'with a non-verified field' do - let(:field) { instance_double(Account::Field, verified?: false) } + let(:verified) { false } - it 'returns verified string' do - result = helper.custom_field_classes(field) - expect(result).to eq 'emojify' - end + it { is_expected.to eq('emojify') } end end