-
-
Notifications
You must be signed in to change notification settings - Fork 269
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: resource custom components (#3176)
* step 1: use string as identifier for actual components * step 2: grid view * step3: tests * separate tests * resource table component * map component * add TableRowComponent * lint * lint * rename name * end rename
- Loading branch information
Showing
29 changed files
with
216 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
spec/components/avo/index/resource_table_component_spec.rb
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
4 changes: 4 additions & 0 deletions
4
spec/dummy/app/components/avo/for_test/grid_item_component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<div class="flex flex-col"> | ||
Custom grid item component here! | ||
<%= render(Avo::Index::GridItemComponent.new(**@args)) %> | ||
</div> |
7 changes: 7 additions & 0 deletions
7
spec/dummy/app/components/avo/for_test/grid_item_component.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
class Avo::ForTest::GridItemComponent < Avo::BaseComponent | ||
def initialize(**args) | ||
@args = args | ||
end | ||
end |
4 changes: 4 additions & 0 deletions
4
spec/dummy/app/components/avo/for_test/resource_edit_component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<div class="flex flex-col"> | ||
Custom edit component here! | ||
<%= render(Avo::Views::ResourceEditComponent.new(**@args)) %> | ||
</div> |
7 changes: 7 additions & 0 deletions
7
spec/dummy/app/components/avo/for_test/resource_edit_component.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
class Avo::ForTest::ResourceEditComponent < Avo::ResourceComponent | ||
def initialize(**args) | ||
@args = args | ||
end | ||
end |
4 changes: 4 additions & 0 deletions
4
spec/dummy/app/components/avo/for_test/resource_index_component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<div class="flex flex-col"> | ||
Custom index component here! | ||
<%= render(Avo::Views::ResourceIndexComponent.new(**@args)) %> | ||
</div> |
7 changes: 7 additions & 0 deletions
7
spec/dummy/app/components/avo/for_test/resource_index_component.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
class Avo::ForTest::ResourceIndexComponent < Avo::ResourceComponent | ||
def initialize(**args) | ||
@args = args | ||
end | ||
end |
4 changes: 4 additions & 0 deletions
4
spec/dummy/app/components/avo/for_test/resource_map_component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<div class="flex flex-col"> | ||
Custom map component here! | ||
<%= render(Avo::Index::ResourceMapComponent.new(**@args)) %> | ||
</div> |
7 changes: 7 additions & 0 deletions
7
spec/dummy/app/components/avo/for_test/resource_map_component.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
class Avo::ForTest::ResourceMapComponent < Avo::BaseComponent | ||
def initialize(**args) | ||
@args = args | ||
end | ||
end |
4 changes: 4 additions & 0 deletions
4
spec/dummy/app/components/avo/for_test/resource_new_component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<div class="flex flex-col"> | ||
Custom new component here! | ||
<%= render(Avo::Views::ResourceEditComponent.new(**@args)) %> | ||
</div> |
7 changes: 7 additions & 0 deletions
7
spec/dummy/app/components/avo/for_test/resource_new_component.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
class Avo::ForTest::ResourceNewComponent < Avo::ResourceComponent | ||
def initialize(**args) | ||
@args = args | ||
end | ||
end |
4 changes: 4 additions & 0 deletions
4
spec/dummy/app/components/avo/for_test/resource_show_component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<div class="flex flex-col"> | ||
Custom show component here! | ||
<%= render(Avo::Views::ResourceShowComponent.new(**@args)) %> | ||
</div> |
7 changes: 7 additions & 0 deletions
7
spec/dummy/app/components/avo/for_test/resource_show_component.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
class Avo::ForTest::ResourceShowComponent < Avo::ResourceComponent | ||
def initialize(**args) | ||
@args = args | ||
end | ||
end |
4 changes: 4 additions & 0 deletions
4
spec/dummy/app/components/avo/for_test/resource_table_component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<div class="flex flex-col"> | ||
Resource table component here! | ||
<%= render(Avo::Index::ResourceTableComponent.new(**@args)) %> | ||
</div> |
7 changes: 7 additions & 0 deletions
7
spec/dummy/app/components/avo/for_test/resource_table_component.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
class Avo::ForTest::ResourceTableComponent < Avo::BaseComponent | ||
def initialize(**args) | ||
@args = args | ||
end | ||
end |
4 changes: 4 additions & 0 deletions
4
spec/dummy/app/components/avo/for_test/table_row_component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<div class="flex flex-col"> | ||
Table row component here! | ||
<%= render(Avo::Index::TableRowComponent.new(**args)) %> | ||
</div> |
12 changes: 12 additions & 0 deletions
12
spec/dummy/app/components/avo/for_test/table_row_component.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# frozen_string_literal: true | ||
|
||
class Avo::ForTest::TableRowComponent < Avo::Index::TableRowComponent | ||
def initialize(**args) | ||
@args = args | ||
end | ||
|
||
def args | ||
@args.merge(header_fields: @header_fields) | ||
end | ||
end | ||
# TODO: document that need to inherit from < Avo::Index::TableRowComponent and need to pass @header_files... and explain why |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
RSpec.describe "Custom components", type: :feature do | ||
describe "symbol" do | ||
before do | ||
Avo::Resources::User.components = { | ||
resource_index_component: Avo::ForTest::ResourceIndexComponent, | ||
resource_show_component: "Avo::ForTest::ResourceShowComponent", | ||
resource_edit_component: "Avo::ForTest::ResourceEditComponent", | ||
resource_new_component: Avo::ForTest::ResourceNewComponent | ||
} | ||
end | ||
|
||
it "index" do | ||
visit avo.resources_users_path | ||
|
||
expect(page).to have_text("Custom index component here!") | ||
end | ||
|
||
it "show" do | ||
visit avo.resources_user_path(admin) | ||
|
||
expect(page).to have_text("Custom show component here!") | ||
end | ||
|
||
it "new" do | ||
visit avo.new_resources_user_path | ||
|
||
expect(page).to have_text("Custom new component here!") | ||
end | ||
|
||
it "edit" do | ||
visit avo.edit_resources_user_path(admin) | ||
|
||
expect(page).to have_text("Custom edit component here!") | ||
end | ||
end | ||
|
||
describe "class" do | ||
before do | ||
Avo::Resources::User.components = { | ||
"Avo::Views::ResourceIndexComponent": Avo::ForTest::ResourceIndexComponent, | ||
"Avo::Views::ResourceShowComponent": "Avo::ForTest::ResourceShowComponent", | ||
"Avo::Views::ResourceEditComponent": "Avo::ForTest::ResourceEditComponent", | ||
"Avo::Index::GridItemComponent": "Avo::ForTest::GridItemComponent", | ||
"Avo::Index::ResourceTableComponent": "Avo::ForTest::ResourceTableComponent", | ||
"Avo::Index::TableRowComponent": "Avo::ForTest::TableRowComponent" | ||
} | ||
end | ||
|
||
it "index and table" do | ||
visit avo.resources_users_path | ||
|
||
expect(page).to have_text("Custom index component here!") | ||
expect(page).to have_text("Resource table component here!") | ||
expect(page).to have_text("Table row component here!") | ||
end | ||
|
||
it "grid item component" do | ||
visit avo.resources_users_path(view_type: :grid) | ||
|
||
expect(page).to have_text("Custom grid item component here!") | ||
end | ||
|
||
it "show" do | ||
visit avo.resources_user_path(admin) | ||
|
||
expect(page).to have_text("Custom show component here!") | ||
end | ||
|
||
# Impossible to specify for new, only for edit. | ||
it "new" do | ||
visit avo.new_resources_user_path | ||
|
||
expect(page).to have_text("Custom edit component here!") | ||
end | ||
|
||
it "edit" do | ||
visit avo.edit_resources_user_path(admin) | ||
|
||
expect(page).to have_text("Custom edit component here!") | ||
end | ||
|
||
it "map" do | ||
Avo::Resources::City.components = { | ||
"Avo::Index::ResourceMapComponent": "Avo::ForTest::ResourceMapComponent" | ||
} | ||
|
||
City.create! | ||
|
||
visit avo.resources_cities_path(view_type: :map) | ||
|
||
expect(page).to have_text("Custom map component here!") | ||
end | ||
end | ||
end |