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

Refactor DeveloperQuery #821

Closed

Conversation

soumyashree25
Copy link

@soumyashree25 soumyashree25 commented Mar 19, 2023

closes #805

Pull request checklist

  • My code contains tests covering the code I modified
  • I linted and tested the project with bin/check
  • I added significant changes and product updates to the changelog

@soumyashree25
Copy link
Author

Hi @joemasilotti , I have extracted sort and countries filter from DeveloperQuery as of now in this PR.
Can you review once, I want to make sure this PR is aligned with your expectation.

def initialize(options = {})
attr_reader :query_item_builder, :query_items

def initialize(options = {}, query_item_builder = Developers::QueryItemBuilder.new)
Copy link
Author

Choose a reason for hiding this comment

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

Currently options are being provided to support other existing query items.
Once I extract all other query items, we will only pass query_item_builder object.

Comment on lines 13 to 14
add_sorting_query
add_countries_filter_query
Copy link
Owner

Choose a reason for hiding this comment

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

I think that these two should be passed in as parameters to initialize. That way we can pass in any combination we want - and future queries only require changes to the new query item and not this class.

Comment on lines 30 to 15
QUERY_ITEM_OPTIONS.each do |method_initial, _|
define_method "#{method_initial}_query_item" do
query_items.detect { |query_item| query_item.type.has_key? method_initial }
end
end
Copy link
Owner

Choose a reason for hiding this comment

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

This feels like it is breaking the point of the refactor. If the public interface exposes the different filters by name then anyone using the query needs to know about reach filter.

Copy link
Author

Choose a reason for hiding this comment

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

@joemasilotti since methods like sort, countries etc are called on developer query object in many places (example: https://github.com/joemasilotti/railsdevs.com/pull/821/files#diff-9b36d228956c34411c77b9a8f1fc0f9831f453e3c4fb52b050673af85a6ee584R14) , somehow we have to expose those either in developer query or query builder.

Any thoughts on how to achieve that if we don't get access to sort_query_item or countries_query_item ?

Copy link
Owner

Choose a reason for hiding this comment

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

One approach is for the query to expose an array of query items publicly. Then, the view can iterate over those to generate the necessary form elements.

The query item can indicate what type of field it requires (text box, select, checkbox, etc.) along with the copy and notes needed for the UI. It can also expose a method that decides if a collapse should be expanded or not.

Does that make sense?

Copy link
Author

Choose a reason for hiding this comment

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

One approach is for the query to expose an array of query items publicly. Then, the view can iterate over those to generate the necessary form elements.

@joemasilotti made adjustments to countries filter and sort query items, let me know if this is fine.

The query item can indicate what type of field it requires (text box, select, checkbox, etc.) along with the copy and notes needed for the UI. It can also expose a method that decides if a collapse should be expanded or not.

@joemasilotti can you please explain a bit more what do you mean by indicating tags like checkbox, select, etc ?
Should we let the query item return its own html and then embed it to app/components/developers/query_component.html.erb ?

Copy link
Owner

Choose a reason for hiding this comment

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

Thanks for the update!

In an ideal world we could pass in a bunch of QueryItem duck types and a single SortItem into DeveloperQuery and that would be that. The HTML could be generated based entirely by iterating over these items and inferring the type.

But the more I think about it the more I'm wondering if a) I'm overcomplicating it and b) we are rebuilding ransack.

I appreciate the work you put into this PR. But I think I'd like to explore ransack next. I'd still love to award a bounty - send me an email and we can figure it out.

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.

Refactor DeveloperQuery to be closed for modification
2 participants