Skip to content

Commit 8c88111

Browse files
fix test
1 parent 8d7ae77 commit 8c88111

File tree

5 files changed

+46
-19
lines changed

5 files changed

+46
-19
lines changed

app/components/avo/view_types/grid_component.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<% @resources.each_with_index do |resource, index| %>
1111
<% cache_if Avo.configuration.cache_resources_on_index_view, resource.cache_hash(@parent_record) do %>
1212
<% card = grid_card_for(resource) %>
13-
<%= render Avo::UI::GridItemComponent.new(
13+
<%= render resource.resolve_component(Avo::UI::GridItemComponent).new(
1414
image: card[:cover_url],
1515
title: card[:title],
1616
description: card[:body],
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<div class="flex flex-col">
2+
Custom grid item component here!
3+
<%= render(Avo::UI::GridItemComponent.new(**@args)) %>
4+
</div>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# frozen_string_literal: true
2+
3+
class Avo::ForTest::UiGridItemComponent < Avo::BaseComponent
4+
def initialize(**args)
5+
@args = args
6+
end
7+
end

spec/dummy/test/components/previews/u_i/grid_item_component_preview/mixed_cases.html.erb

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,23 @@
2424
variant = ipod_product.image.variant(resize_to_fill: [300, 300])
2525
main_app.url_for(variant)
2626
end
27-
%>
27+
28+
simulated_actions = capture do %>
29+
<div>
30+
<%= link_to "#", class: "flex items-center gap-2" do %>
31+
<%= svg("tabler/outline/pencil", class: "h-6") %>
32+
Edit
33+
<% end %>
34+
<%= link_to "#", class: "flex items-center gap-2" do %>
35+
<%= svg("tabler/outline/eye", class: "h-6") %>
36+
View
37+
<% end %>
38+
<%= link_to "#", class: "flex items-center gap-2" do %>
39+
<%= svg("tabler/outline/trash", class: "h-6") %>
40+
Delete
41+
<% end %>
42+
</div>
43+
<% end %>
2844
<div class="p-8 bg-white">
2945
<h3 class="text-lg font-semibold text-gray-900 mb-6">Mixed Cases - 8 Items</h3>
3046
<div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4">
@@ -34,63 +50,62 @@
3450
badge_label: "New",
3551
badge_color: :success,
3652
image: nil,
37-
checkbox_checked: false
53+
checkbox_checked: false,
54+
actions: simulated_actions,
3855
) %>
3956
<%= render Avo::UI::GridItemComponent.new(
4057
title: "iPhone",
4158
description: "A magical new way to interact",
4259
badge_label: "Updated",
4360
badge_color: :warning,
4461
image: iphone_image,
45-
checkbox_checked: false
62+
checkbox_checked: false,
63+
actions: simulated_actions,
4664
) %>
4765
<%= render Avo::UI::GridItemComponent.new(
4866
title: "Apple watch",
4967
description: "A healthy leap ahead",
50-
badge_label: nil,
51-
badge_color: :blue,
5268
image: watch_image,
53-
checkbox_checked: false
69+
checkbox_checked: false,
70+
actions: simulated_actions,
5471
) %>
5572
<%= render Avo::UI::GridItemComponent.new(
5673
title: "iPod",
57-
description: nil,
5874
badge_label: "Sale",
5975
badge_color: :danger,
6076
image: ipod_image,
61-
checkbox_checked: false
77+
checkbox_checked: false,
78+
actions: simulated_actions,
6279
) %>
6380
<%= render Avo::UI::GridItemComponent.new(
6481
title: nil,
6582
description: "Item without title",
6683
badge_label: "Featured",
6784
badge_color: :purple,
6885
image: macbook_image,
69-
checkbox_checked: false
86+
checkbox_checked: false,
87+
actions: simulated_actions,
7088
) %>
7189
<%= render Avo::UI::GridItemComponent.new(
7290
title: "No Description",
73-
description: nil,
7491
badge_label: "Info",
7592
badge_color: :info,
7693
image: iphone_image,
77-
checkbox_checked: false
94+
checkbox_checked: false,
95+
actions: simulated_actions,
7896
) %>
7997
<%= render Avo::UI::GridItemComponent.new(
8098
title: "No Badge Item",
8199
description: "This item has no badge",
82-
badge_label: nil,
83-
badge_color: :blue,
84100
image: watch_image,
85-
checkbox_checked: false
101+
checkbox_checked: false,
102+
actions: simulated_actions,
86103
) %>
87104
<%= render Avo::UI::GridItemComponent.new(
88105
title: "Minimal Item",
89-
description: nil,
90-
badge_label: nil,
91-
badge_color: :blue,
92106
image: ipod_image,
93-
checkbox_checked: false
107+
checkbox_checked: false,
108+
actions: simulated_actions,
94109
) %>
95110
</div>
96111
</div>

spec/features/avo/resource_custom_components_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"Avo::Views::ResourceShowComponent": "Avo::ForTest::ResourceShowComponent",
4646
"Avo::Views::ResourceEditComponent": "Avo::ForTest::ResourceEditComponent",
4747
"Avo::Index::GridItemComponent": "Avo::ForTest::GridItemComponent",
48+
"Avo::UI::GridItemComponent": Avo::ForTest::UiGridItemComponent,
4849
"Avo::ViewTypes::TableComponent": "Avo::ForTest::ResourceTableComponent",
4950
"Avo::Index::TableRowComponent": "Avo::ForTest::TableRowComponent"
5051
}

0 commit comments

Comments
 (0)