Skip to content

Filter resources - #44

Draft
blocknotes wants to merge 3 commits into
mainfrom
filter_resources
Draft

Filter resources#44
blocknotes wants to merge 3 commits into
mainfrom
filter_resources

Conversation

@blocknotes

@blocknotes blocknotes commented Apr 23, 2025

Copy link
Copy Markdown
Owner

Closes #35

@blocknotes blocknotes self-assigned this Apr 23, 2025
@blocknotes blocknotes changed the title Override filter_resources instead of scoped_resource Filter resources May 4, 2025
@blocknotes
blocknotes force-pushed the filter_resources branch 6 times, most recently from f155adf to b7e91e2 Compare May 12, 2025 06:59

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The updated filters rendering introduces multiple runtime-breaking issues (undefined namespace, missing fallback type handling, incorrect date/datetime value binding, and leftover debug JS output).

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR updates AdministrateRansack to hook into Administrate’s filter_resources flow (rather than scoped_resource) and revises the filtering UI/rendering to be driven by per-dashboard RANSACK_SEARCH configuration, aligning with Administrate v0.18+ behavior.

Changes:

  • Move Ransack integration to filter_resources and add parsing for structured search_term input (key:value) in AdministrateRansack::Searchable.
  • Replace the legacy _filters.html.erb with a new _filters.erb and update filter field component partials to use normalized type/options data.
  • Update system specs and the dummy app views/dashboards to reflect the new filter UI and configuration.
File summaries
File Description
spec/system/string_filter_spec.rb Click the “Search” button via the new .filters-buttons container instead of submitting the first submit input.
spec/system/select_filter_spec.rb Update submission interaction to match the new filter controls markup.
spec/system/scope_filter_spec.rb Update submission interaction to match the new filter controls markup.
spec/system/number_filter_spec.rb Update submission interaction to match the new filter controls markup.
spec/system/has_many_filter_spec.rb Update submission interaction to match the new filter controls markup (two scenarios).
spec/system/date_filter_spec.rb Update submission interaction to match the new filter controls markup.
spec/system/boolean_filter_spec.rb Update submission interaction to match the new filter controls markup.
spec/system/belongs_to_filter_spec.rb Update submission interaction to match the new filter controls markup.
spec/support/capybara.rb Adjust Cuprite driver options (logging, headless toggle, js_errors, etc.).
spec/dummy/app/views/layouts/mailer.text.erb Remove dummy mailer layout.
spec/dummy/app/views/layouts/mailer.html.erb Remove dummy mailer layout.
spec/dummy/app/views/layouts/application.html.erb Remove dummy app layout.
spec/dummy/app/views/administrate/application/_search.html.erb Render AdministrateRansack filters when @ransack_results is present.
spec/dummy/app/views/admin/tags/index.html.erb Remove custom dummy tags index view that embedded filters.
spec/dummy/app/views/admin/posts/index.html.erb Remove custom dummy posts index view that embedded filters and custom CSS.
spec/dummy/app/views/admin/application/_stylesheet.html.erb Remove dummy stylesheet partial customization.
spec/dummy/app/views/admin/application/_javascript.html.erb Remove dummy javascript partial customization.
spec/dummy/app/dashboards/tag_dashboard.rb Add searchable fields via RANSACK_SEARCH and expand collection attributes.
spec/dummy/app/dashboards/post_dashboard.rb Add RANSACK_SEARCH configuration for multiple field types/options.
Makefile Seed during db_reset and remove implicit seeding for console/server.
lib/administrate_ransack/searchable.rb Implement filter_resources integration and build view data (@fields/@model) from dashboard configuration.
lib/administrate_ransack/filters.rb Change FILTERS mapping from component names to normalized filter type symbols.
Gemfile Remove rubocop-rspec_rails.
app/views/administrate_ransack/components/_filter_buttons.html.erb Update submit/clear controls markup and behavior.
app/views/administrate_ransack/components/_field_string.html.erb Switch to normalized options[:label]/options[:param] rendering.
app/views/administrate_ransack/components/_field_select.html.erb Support callable collections and normalized option access.
app/views/administrate_ransack/components/_field_other.html.erb Normalize rendering and add wrapper markup consistent with other fields.
app/views/administrate_ransack/components/_field_number.html.erb Normalize rendering and add wrapper markup consistent with other fields.
app/views/administrate_ransack/components/_field_has_many.html.erb Normalize options handling (select, param, label) and wrapper markup.
app/views/administrate_ransack/components/_field_datetime.html.erb Normalize options handling and support range vs single predicate inputs.
app/views/administrate_ransack/components/_field_date.html.erb Normalize options handling and support range vs single predicate inputs.
app/views/administrate_ransack/components/_field_boolean.html.erb Normalize options handling and wrapper markup.
app/views/administrate_ransack/components/_field_belongs_to.html.erb Normalize options handling and wrapper markup.
app/views/administrate_ransack/_javascript.html.erb Update JS behavior for selectize initialization (and add debug output).
app/views/administrate_ransack/_filters.html.erb Remove legacy filters partial that accepted locals like attribute_types/search_path/namespace.
app/views/administrate_ransack/_filters.erb Add new filters partial driven by instance variables prepared during filter_resources.
Review details
  • Files reviewed: 36/36 changed files
  • Comments generated: 7
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +40 to +42
<div class="ransack-search">
<% form_path = [namespace, @ransack_results] %>
<%= search_form_for(form_path, html: { 'data-administrate-ransack-filters': '1' }) do |f| %>
Comment on lines +6 to +8
<% else %>
<%= form.date_field(options[:param], value: form.object.send(field)) %>
<% end %>
Comment on lines +6 to +8
<% else %>
<%= form.datetime_field(options[:param], value: form.object.send(field)) %>
<% end %>
Comment on lines +44 to +46
<% type = data.delete(:type) %>
<% attrs = { form: f, model: @model, field: field, type: type, options: data[:options] } %>
<%= render "administrate_ransack/components/field_#{type}", attrs %>
Comment on lines 1 to +5
<% content_for :javascript do %>
<!-- [JS] -->
<script>
console.error('JS error!');

Comment on lines +79 to +82
if conf.blank?
field_type = dashboard.attribute_type_for(field).to_s
AdministrateRansack::FILTERS[field_type]
elsif conf.is_a?(Hash)
Comment on lines +72 to +81
RANSACK_SEARCH = {
posts: :has_many,
created_at: {
type: :date
},
updated_at: {
type: :date,
range: false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use filter_resources instead of scoped_resource?

2 participants