Skip to content

Commit

Permalink
feature: add visible option to tab (#3017)
Browse files Browse the repository at this point in the history
  • Loading branch information
icaroryan authored Jul 19, 2024
1 parent 34c48c7 commit 4b4c367
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/avo/resources/items/tab.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class Avo::Resources::Items::Tab
include Avo::Concerns::HasItems
include Avo::Concerns::HasItemType
include Avo::Concerns::VisibleItems
include Avo::Concerns::IsVisible
include Avo::Concerns::VisibleInDifferentViews

delegate :items, :add_item, to: :items_holder
Expand All @@ -16,6 +17,7 @@ def initialize(name: nil, description: nil, view: nil, **args)
@items_holder = Avo::Resources::Items::Holder.new
@view = Avo::ViewInquirer.new view
@args = args
@visible = args[:visible]

post_initialize if respond_to?(:post_initialize)
end
Expand Down
10 changes: 10 additions & 0 deletions spec/features/avo/tabs_panels_and_sidebar_visibility_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
}
end
end

tab "Conditional hidden tab inside tabs", visible: -> { resource.record.name == "RSpec TabsPanelAndSidebarVisibility" } do
field :hidden_field_inside_tabs_inside_conditional_tab, as: :text
end
end

panel "Hidden panel", visible: -> { resource.record.name == "RSpec PanelVisibility" } do
Expand Down Expand Up @@ -64,6 +68,9 @@
expect(page).to have_text "Hidden field inside tabs inside tab"
expect(page).to have_text "Hidden field inside tabs inside tab inside panel"
expect(page).to have_text "Hidden field inside sidebar"

expect(page).to have_text "Conditional hidden tab inside tabs"
expect(page).to have_text "Hidden field inside tabs inside conditional tab"
end
end

Expand All @@ -75,6 +82,9 @@
expect(page).not_to have_text "Hidden field inside tabs inside tab"
expect(page).not_to have_text "Hidden field inside tabs inside tab inside panel"
expect(page).not_to have_text "Hidden field inside sidebar"

expect(page).not_to have_text "Conditional hidden tab inside tabs"
expect(page).not_to have_text "Hidden field inside tabs inside conditional tab"
end
end
end
Expand Down

0 comments on commit 4b4c367

Please sign in to comment.