diff --git a/app/components/avo/panel_component.html.erb b/app/components/avo/panel_component.html.erb index cb97b26a4d..63da39b304 100644 --- a/app/components/avo/panel_component.html.erb +++ b/app/components/avo/panel_component.html.erb @@ -1,34 +1,21 @@ <%= content_tag :div, class: classes, data: data_attributes do %> <%= render Avo::CoverPhotoComponent.new cover_photo: @cover_photo %> - - <% if render_header? %> -
-
- <%= render Avo::ProfilePhotoComponent.new profile_photo: @profile_photo %> -
- <%= render partial: "avo/partials/panel_breadcrumbs" if display_breadcrumbs? %> -
-
- <% if name_slot? %> - <%= name_slot %> - <% else %> - <%= render Avo::PanelNameComponent.new name: @name %> - <% end %> - <% if description.present? %> -
- <%== description %> -
- <% end %> -
- <% if tools.present? %> -
- <%= tools %> -
- <% end %> -
-
-
-
+ <%= render Avo::PanelHeaderComponent.new( + name: @name, + description: @description, + display_breadcrumbs: @display_breadcrumbs, + profile_photo: @profile_photo + ) do |header| %> + <% if name_slot.present? %> + <% header.with_name_slot do %> + <%= name_slot %> + <% end %> + <% end %> + <% if tools.present? %> + <% header.with_tools do %> + <%= tools %> + <% end %> + <% end %> <% end %> <% if body? %>
diff --git a/app/components/avo/panel_component.rb b/app/components/avo/panel_component.rb index ca5a7631fe..e36ea5a09a 100644 --- a/app/components/avo/panel_component.rb +++ b/app/components/avo/panel_component.rb @@ -37,18 +37,4 @@ def classes def data_attributes @data.merge({"panel-index": @index}) end - - def display_breadcrumbs? - @display_breadcrumbs == true && Avo.configuration.display_breadcrumbs == true - end - - def description - return @description if @description.present? - - "" - end - - def render_header? - @name.present? || description.present? || tools.present? || display_breadcrumbs? - end end diff --git a/app/components/avo/panel_header_component.html.erb b/app/components/avo/panel_header_component.html.erb new file mode 100644 index 0000000000..4f1b08fd02 --- /dev/null +++ b/app/components/avo/panel_header_component.html.erb @@ -0,0 +1,31 @@ +
+
+ <%= render Avo::ProfilePhotoComponent.new profile_photo: @profile_photo %> +
+ <% if display_breadcrumbs? %> + + <% end %> +
+
+ <% if name_slot? %> + <%= name_slot %> + <% else %> + <%= render Avo::PanelNameComponent.new name: @name %> + <% end %> + <% if @description.present? %> +
+ <%== @description %> +
+ <% end %> +
+ <% if tools.present? %> +
+ <%= tools %> +
+ <% end %> +
+
+
+
diff --git a/app/components/avo/panel_header_component.rb b/app/components/avo/panel_header_component.rb new file mode 100644 index 0000000000..5155c86a9a --- /dev/null +++ b/app/components/avo/panel_header_component.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +class Avo::PanelHeaderComponent < Avo::BaseComponent + include Avo::ApplicationHelper + + renders_one :name_slot + renders_one :tools + + prop :name + prop :description + prop :display_breadcrumbs, default: false + prop :profile_photo + + private + + def display_breadcrumbs? + @display_breadcrumbs && Avo.configuration.display_breadcrumbs + end + + def description + return @description if @description.present? + + "" + end + + def render? + @name.present? || description.present? || tools.present? || display_breadcrumbs? + end +end diff --git a/app/components/avo/tab_group_component.html.erb b/app/components/avo/tab_group_component.html.erb index b2c354f97e..f14a7bd888 100644 --- a/app/components/avo/tab_group_component.html.erb +++ b/app/components/avo/tab_group_component.html.erb @@ -10,7 +10,8 @@ } do %> <% visible_tabs.each_with_index do |tab, index| %> <%= content_tag :div, **args(tab) do %> -
+ <%= render Avo::PanelHeaderComponent.new name: group.title, description: group.description %> +
<%= render Avo::TabSwitcherComponent.new resource: resource, current_tab: visible_tabs.first, group: group, active_tab_name: tab.name, view: view %> <% if !tab.is_empty? %>
diff --git a/lib/avo/resources/items/holder.rb b/lib/avo/resources/items/holder.rb index 0d5a7daec0..4262e9b19c 100644 --- a/lib/avo/resources/items/holder.rb +++ b/lib/avo/resources/items/holder.rb @@ -37,11 +37,19 @@ def field(field_name, **args, &block) add_item field_parser.instance end - def tabs(tab = nil, id: nil, name: nil, **kwargs, &block) + def tabs(tab = nil, id: nil, name: nil, title: nil, description: nil, **args, &block) if tab.present? add_item tab else - add_item Avo::Resources::Items::TabGroup::Builder.parse_block(parent: @parent, id: id, name: name, **kwargs, &block) + add_item Avo::Resources::Items::TabGroup::Builder.parse_block( + parent: @parent, + id: id, + name: name, + title: title, + description: description, + **args, + &block + ) end end diff --git a/lib/avo/resources/items/tab_group.rb b/lib/avo/resources/items/tab_group.rb index 1db7f7adc4..7b7567fc6e 100644 --- a/lib/avo/resources/items/tab_group.rb +++ b/lib/avo/resources/items/tab_group.rb @@ -6,15 +6,15 @@ class Avo::Resources::Items::TabGroup include Avo::Concerns::IsVisible include Avo::Concerns::VisibleInDifferentViews - attr_accessor :index - attr_accessor :style - attr_accessor :name + attr_accessor :index, :style, :name, :title, :description - def initialize(index: 0, view: nil, style: nil, id: nil, name: nil, **args) + def initialize(index: 0, view: nil, style: nil, title: nil, description: nil, id: nil, name: nil, **args) @index = index @items_holder = Avo::Resources::Items::Holder.new @view = Avo::ViewInquirer.new view @style = style + @title = title + @description = description @id = id @name = name @args = args @@ -67,8 +67,15 @@ def field(field_name, **args, &block) @items_holder.tabs tab end - def initialize(name:, id:, parent:, style: nil, **args) - @group = Avo::Resources::Items::TabGroup.new(name: name, id: id, style: style, **args) + def initialize(name:, id:, parent:, title: nil, description: nil, style: nil, **args) + @group = Avo::Resources::Items::TabGroup.new( + name: name, + id: id, + style: style, + title: title, + description: description, + **args + ) @items_holder = Avo::Resources::Items::Holder.new(parent: parent, from: self) end diff --git a/spec/dummy/app/avo/resources/user.rb b/spec/dummy/app/avo/resources/user.rb index cfb603cc69..81636ac29c 100644 --- a/spec/dummy/app/avo/resources/user.rb +++ b/spec/dummy/app/avo/resources/user.rb @@ -227,7 +227,7 @@ def stacked_name end def first_tabs_group - tabs do + tabs title: "First tabs group", description: "First tabs group description" do birthday_tab test_tab test_field("Inside tabs") @@ -241,7 +241,7 @@ def first_tabs_group end def second_tabs_group - tabs id: :second_tabs_group do + tabs title: "Second tabs group", description: "Second tabs group description", id: :second_tabs_group do field :post, as: :has_one, name: "Main post", diff --git a/spec/system/avo/tabs_spec.rb b/spec/system/avo/tabs_spec.rb index 6a2572cba5..49bb2b61cc 100644 --- a/spec/system/avo/tabs_spec.rb +++ b/spec/system/avo/tabs_spec.rb @@ -32,6 +32,12 @@ expect(find('turbo-frame[id="has_many_field_show_posts"]')).to have_link "Attach post" expect(find('turbo-frame[id="has_many_field_show_posts"]')).to have_link "Create new post", href: "/admin/resources/posts/new?via_record_id=#{user.slug}&via_relation=user&via_relation_class=User&via_resource_class=Avo%3A%3AResources%3A%3AUser" + expect(page).to have_text "First tabs group" + expect(page).to have_text "First tabs group description" + + expect(page).to have_text "Second tabs group" + expect(page).to have_text "Second tabs group description" + click_on "Attach post" expect(page).to have_text "Choose post"