Commit dac4c27 1 parent 40747e8 commit dac4c27 Copy full SHA for dac4c27
File tree 6 files changed +27
-10
lines changed
6 files changed +27
-10
lines changed Original file line number Diff line number Diff line change 700
700
701
701
PLATFORMS
702
702
arm64-darwin-23
703
+ arm64-darwin-24
703
704
x86_64-linux
704
705
705
706
DEPENDENCIES
Original file line number Diff line number Diff line change @@ -119,11 +119,7 @@ def singular_resource_name
119
119
120
120
def description
121
121
# If this is a has many association, the user can pass a description to be shown just for this association.
122
- if @reflection . present?
123
- return field . description if field . present? && field . description
124
-
125
- return
126
- end
122
+ return field &.description ( query : @query ) if @reflection . present?
127
123
128
124
@resource . description
129
125
end
Original file line number Diff line number Diff line change @@ -8,8 +8,12 @@ module HasDescription
8
8
attr_accessor :description
9
9
end
10
10
11
- def description
12
- Avo ::ExecutionContext . new ( target : @description || self . class . description , **description_attributes ) . handle
11
+ def description ( additional_attributes = { } )
12
+ Avo ::ExecutionContext . new (
13
+ target : @description || self . class . description ,
14
+ **description_attributes ,
15
+ **additional_attributes
16
+ ) . handle
13
17
end
14
18
15
19
private
Original file line number Diff line number Diff line change @@ -116,9 +116,9 @@ def translated_plural_name(default:)
116
116
# Secondly we'll try to find a translation key
117
117
# We'll fallback to humanizing the id
118
118
def name
119
- return @name if custom_name?
120
-
121
- if translation_key
119
+ if custom_name?
120
+ Avo :: ExecutionContext . new ( target : @name ) . handle
121
+ elsif translation_key
122
122
translated_name default : default_name
123
123
else
124
124
default_name
Original file line number Diff line number Diff line change @@ -258,6 +258,8 @@ def second_tabs_group
258
258
translation_key : "avo.field_translations.people"
259
259
field :posts ,
260
260
as : :has_many ,
261
+ name : -> { "Posts" } ,
262
+ description : -> { "This user has #{ query . count } posts." } ,
261
263
show_on : :edit ,
262
264
attach_scope : -> { query . where . not ( user_id : parent . id ) . or ( query . where ( user_id : nil ) ) }
263
265
field :comments ,
Original file line number Diff line number Diff line change 156
156
expect { find ( "tr[data-resource-id='#{ team . id } '] [data-control='detach']" ) . click } . to raise_error ( "Callback Called" )
157
157
end
158
158
end
159
+
160
+ describe "dynamic description" do
161
+ let ( :url ) { "/admin/resources/users/#{ user . slug } /posts?turbo_frame=has_many_field_posts&view_type=table" }
162
+ let! ( :post_1 ) { create :post , user : user }
163
+ let! ( :post_2 ) { create :post , user : user }
164
+
165
+ it { is_expected . to have_text "This user has 2 posts" }
166
+ end
167
+
168
+ describe "dynamic name" do
169
+ let ( :url ) { "/admin/resources/users/#{ user . slug } /posts?turbo_frame=has_many_field_posts&view_type=table" }
170
+
171
+ it { is_expected . to have_text "Posts" }
172
+ end
159
173
end
You can’t perform that action at this time.
0 commit comments