Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add header_action method for panels #2723

Merged
merged 2 commits into from

3 participants

@shekibobo

Rough implementation that seems to work. No tests yet, but wanted to open #2552 for discussion over actual code.

@coveralls

Coverage Status

Coverage decreased (-0.07%) when pulling 59ec491 on shekibobo:2552-panel-header-actions into e9b7c47 on gregbell:master.

@seanlinsley
Owner

Closing this as stale

@seanlinsley seanlinsley closed this
@shekibobo

I just updated this branch and added tests for this over on shekibobo:2552-panel-header-actions, but it doesn't show up here (probably because it's closed). I would like to revisit this, as far as the DSL or advanced implementation goes. Any thoughts?

@seanlinsley seanlinsley reopened this
@shekibobo

I've reworked this a bit and added better tests to make sure it all works right. Any thoughts on what it might take to get this (or some version of it) pulled into master?

@seanlinsley
Owner

I'm still not happy with the user-facing DSL, but there's no point in letting that block an undeniably useful feature. Thanks! :cat:

@seanlinsley seanlinsley merged commit 4bca96f into from
@shekibobo

Awesome! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
8 app/assets/stylesheets/active_admin/mixins/_sections.css.scss
@@ -25,7 +25,13 @@
@include section-background;
margin-bottom: 20px;
- > h3 { @include section-header; }
+ > h3 {
+ @include section-header;
+
+ .header_action {
+ float: right;
+ }
+ }
> div { padding: 3px $section-padding $section-padding $section-padding; }
View
8 lib/active_admin/views/components/panel.rb
@@ -28,7 +28,13 @@ def children?
@contents.children?
end
- end
+ def header_action(*args)
+ action = args[0]
+ @title << div(class: 'header_action') do
+ action
+ end
+ end
+ end
end
end
View
49 spec/unit/views/components/panel_spec.rb
@@ -1,51 +1,60 @@
require 'spec_helper'
describe ActiveAdmin::Views::Panel do
-
- let(:the_panel) do
+ let(:arbre_panel) do
render_arbre_component do
- panel "My Title" do
+ panel "My Title", icon: :arrow_down do
+ header_action link_to("My Link", "https://www.github.com/gregbell/active_admin")
span("Hello World")
end
end
end
+ let(:panel_html) { Capybara.string(arbre_panel.to_s) }
+
it "should have a title h3" do
- expect(the_panel.find_by_tag("h3").first.content).to eq "My Title"
+ expect(panel_html).to have_css 'h3', content: "My Title"
+ end
+
+ it "should add panel actions to the panel header" do
+ expect(panel_html).to have_css 'h3 > div.header_action a', content: 'My Link', href: "https://www.github.com/gregbell/active_admin"
end
it "should have a contents div" do
- expect(the_panel.find_by_tag("div").first.class_list).to include("panel_contents")
+ expect(panel_html).to have_css 'div.panel_contents'
end
it "should add children to the contents div" do
- expect(the_panel.find_by_tag("span").first.parent).to eq the_panel.find_by_tag("div").first
+ expect(panel_html).to have_css 'div.panel_contents > span', content: "Hello World"
end
it "should set the icon" do
- the_panel = render_arbre_component do
- panel("Title", icon: :arrow_down)
- end
- expect(the_panel.find_by_tag("h3").first.content).to include("span class=\"icon")
+ expect(panel_html).to have_css "h3 > span.icon"
end
- it "should allow a html_safe title (without icon)" do
- title_with_html = %q[Title with <abbr>HTML</abbr>].html_safe
- the_panel = render_arbre_component do
- panel(title_with_html)
+ context "with html-safe title" do
+ let(:arbre_panel) do
+ title_with_html = %q[Title with <abbr>HTML</abbr>].html_safe
+ render_arbre_component do
+ panel(title_with_html)
+ end
+ end
+
+ it "should allow a html_safe title" do
+ expect(panel_html).to have_css "h3", content: "Title with HTML"
+ expect(panel_html).to have_css "h3 > abbr", content: "HTML"
end
- expect(the_panel.find_by_tag("h3").first.content).to eq(title_with_html)
end
describe "#children?" do
-
- it "returns false if no children have been added to the panel" do
- the_panel = render_arbre_component do
+ let(:arbre_panel) do
+ render_arbre_component do
panel("A Panel")
end
- expect(the_panel.children?).to eq false
end
+ it "returns false if no children have been added to the panel" do
+ expect(arbre_panel.children?).to eq false
+ end
end
-
end
Something went wrong with that request. Please try again.