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

Feature/backoffice smart filters #426

Merged
merged 26 commits into from
Apr 4, 2023
Merged

Conversation

tsubik
Copy link
Collaborator

@tsubik tsubik commented Mar 14, 2023

Adding more dependent filters by using filter trees. (https://www.pivotaltracker.com/story/show/181286870)

@tsubik tsubik force-pushed the feature/backoffice-smart-filters branch from 9118dfa to e5a3200 Compare March 21, 2023 10:47
@tsubik tsubik force-pushed the feature/backoffice-smart-filters branch from 85eed81 to 9b608f6 Compare March 21, 2023 11:52
@tsubik tsubik force-pushed the feature/backoffice-smart-filters branch from 073c5c1 to 1a366c5 Compare March 21, 2023 18:00
@tsubik tsubik force-pushed the feature/backoffice-smart-filters branch from 1a366c5 to 30997c2 Compare March 21, 2023 18:01
@tsubik tsubik force-pushed the feature/backoffice-smart-filters branch from df15f40 to ce5be5f Compare March 24, 2023 11:09
@tsubik tsubik force-pushed the feature/backoffice-smart-filters branch 2 times, most recently from f9bf158 to 8c495d4 Compare March 27, 2023 11:59
@tsubik tsubik force-pushed the feature/backoffice-smart-filters branch from 8c495d4 to d02b627 Compare March 27, 2023 12:02
@tsubik tsubik marked this pull request as ready for review March 27, 2023 14:08
@santostiago santostiago self-requested a review April 1, 2023 14:02
Copy link
Contributor

@santostiago santostiago left a comment

Choose a reason for hiding this comment

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

Looks great!
But we will lose some dependencies on the observation page. Is that ok?

app/admin/law.rb Outdated
as: :select,
collection: -> { Subcategory.joins(:laws).with_translations(I18n.locale).order('subcategory_translations.name') }
filter :written_infraction_cont, label: I18n.t('active_admin.laws_page.written_infraction')
filter :infraction_cont, label: I18n.t('active_admin.laws_page.infraction')
Copy link
Contributor

Choose a reason for hiding this comment

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

what's cont? So that the field is not prepopulated? Wasn't it enough not to make the fields text fields?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it's ransack contains so checking if text contains a string. It's a simple text field without any autocompletion now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I will ask Sophie again what is more desired, as we can change as you said to look by law id for selected infraction text which will help, but I think they wanted simple text field here.

{
country_id: {
operator_id: Operator.pluck(:country_id, :id),
fmu_id: Fmu.pluck(:country_id, :id),
Copy link
Contributor

Choose a reason for hiding this comment

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

mmm.. but this way the fmu does not depend on the operator.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In this case, that was strictly requested.

collection: -> { Country.with_translations(I18n.locale).order('country_translations.name') }
filter :observers, label: I18n.t('activerecord.attributes.observation.observers'), as: :select,
collection: -> { Observer.with_translations(I18n.locale).order('observer_translations.name') }
label: I18n.t('activerecord.models.country.one'),
Copy link
Contributor

Choose a reason for hiding this comment

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

We no longer want the user? I thought this was a useful field

Copy link
Collaborator Author

@tsubik tsubik Apr 1, 2023

Choose a reason for hiding this comment

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

Yes, I removed all filters Sophie doesn't want there anymore.

collection: -> { Operator.order(:name) }
filter :fmu, label: I18n.t('activerecord.models.fmu.other'), as: :select,
collection: -> { Fmu.with_translations(I18n.locale).order('fmu_translations.name') }
collection: -> { RequiredOperatorDocument.with_generic.map { |r| [r.name_with_country, r.id] } }
Copy link
Contributor

Choose a reason for hiding this comment

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

❤️

end
end
result
array.group_by(&:first).transform_values { |v| v.map(&:last) }.delete_if { |k, _v| k.nil? }
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

# Configure Capybara to use :cuprite driver by default
Capybara.default_driver = Capybara.javascript_driver = :cuprite

RSpec.configure do |config|
Copy link
Contributor

Choose a reason for hiding this comment

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

mmm.. what does this change in the rspec execution?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We did not have any system spec before, so we do now. System specs are run along the rest when executing rspec spec.

@santostiago
Copy link
Contributor

@tsubik maybe before merging it would be a good idea to squash most of the commits :)

@tsubik
Copy link
Collaborator Author

tsubik commented Apr 1, 2023 via email

filter_tree = block.call
filter_tree.each_value { |v| v.transform_values! { |collection| HashHelper.aggregate(collection) } }

# div class: 'dependent-filters', data: { filters: filter_tree }
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

upps I see I forgot to remove this comment here.

@tsubik tsubik merged commit 406641c into develop Apr 4, 2023
@tsubik tsubik deleted the feature/backoffice-smart-filters branch April 4, 2023 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants