Use field partial in admin account show view (#35503)

This commit is contained in:
Matt Jankowski 2025-07-25 03:21:08 -04:00 committed by GitHub
parent e5e977c24f
commit 960f693219
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 25 additions and 28 deletions

View File

@ -49,8 +49,8 @@ module HomeHelper
end end
end end
def custom_field_classes(field) def field_verified_class(verified)
if field.verified? if verified
'verified' 'verified'
else else
'emojify' 'emojify'

View File

@ -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)

View File

@ -7,25 +7,17 @@
= render 'application/card', account: @account = render 'application/card', account: @account
- account = @account - if @account.fields? || @account.note?
- fields = account.fields
- unless fields.empty? && account.note.blank?
.admin-account-bio .admin-account-bio
- unless fields.empty? - if @account.fields?
%div %div
.account__header__fields .account__header__fields
- fields.each do |field| = render partial: 'field', collection: @account.fields, locals: { account: @account }
%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)
- if account.note.present? - if @account.note?
%div %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 = render 'admin/accounts/counters', account: @account

View File

@ -75,23 +75,19 @@ RSpec.describe HomeHelper do
end end
end end
describe 'custom_field_classes' do describe 'field_verified_class' do
context 'with a verified field' do subject { helper.field_verified_class(verified) }
let(:field) { instance_double(Account::Field, verified?: true) }
it 'returns verified string' do context 'with a verified field' do
result = helper.custom_field_classes(field) let(:verified) { true }
expect(result).to eq 'verified'
end it { is_expected.to eq('verified') }
end end
context 'with a non-verified field' do context 'with a non-verified field' do
let(:field) { instance_double(Account::Field, verified?: false) } let(:verified) { false }
it 'returns verified string' do it { is_expected.to eq('emojify') }
result = helper.custom_field_classes(field)
expect(result).to eq 'emojify'
end
end end
end end