Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: chore: Migrate AdminIndexComponent to use ViewComponent #2666

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
10 changes: 0 additions & 10 deletions app/components/admin_index/admin_index_component.rb

This file was deleted.

13 changes: 13 additions & 0 deletions app/components/admin_index_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

class AdminIndexComponent < ViewComponent::Base
def initialize(additional_links:, default: [])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in answer to your q i think all you need to do is pass in all the params here :)

Copy link
Member

@kimadactyl kimadactyl Jan 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OH sorry i read your comment again

this is making additional_links mandatory i think? i am a bit rusty but i think additional_links: [], default: [] should fix it? think you jsut need a default value. from a search it doesn't look like this is actually in use anywhere so it might be cuttable along with the comments referring to it? i think we can purge it!

super
@additional_links = additional_links
@default = default
end

def model_name
properties[:model].to_s.chop.humanize
Copy link
Member

@kimadactyl kimadactyl Jan 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this properties business is mountain_view code and needs replacing - this is how it implicitly imported everything before

Copy link
Member

@kimadactyl kimadactyl Jan 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ugh also surely theres a way to do this referring directly to the type itself and not with this method chain 😓 embarrased for old me lol

end
end
3 changes: 2 additions & 1 deletion app/views/admin/collections/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<%# TODO: Only show Edit link for root users %>

<%= render_component "admin_index",
<%= render_component AdminIndexComponent.new(
title: "Collections",
model: :collections,
column_titles: ['ID', 'Name', 'Description'],
columns: %i[id name description],
data: @collections,
new_link: new_admin_collection_path
)
%>
3 changes: 2 additions & 1 deletion app/views/admin/supporters/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<%= render_component "admin_index",
<%= render_component AdminIndexComponent.new(
title: "Supporters",
model: :supporters,
column_titles: ['ID', 'Name', 'Logo', 'Global?'],
columns: %i[id name logo is_global],
data: @supporters,
new_link: new_admin_supporter_path
)
%>
12 changes: 12 additions & 0 deletions test/components/admin_index_component_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

require 'test_helper'

class AdminIndexComponentTest < ViewComponent::TestCase
def test_component_renders_something_useful
# assert_equal(
# %(<span>Hello, components!</span>),
# render_inline(AdminIndexComponent.new(message: "Hello, components!")).css("span").to_html
# )
end
end
Loading