-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[Moved] Improve variant and product autocomplete functions flexibility with Ransack #4733
[Moved] Improve variant and product autocomplete functions flexibility with Ransack #4733
Conversation
@RyanofWoods nice, can you please show us the way to use this custom query as well? |
9a96c36
to
dbd35b2
Compare
I added an example to the description @kennyadsl 👍 I also changed the option variable name to use lower camelcase |
Thanks, @RyanofWoods!! ❤️ A couple of questions/suggestions:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Loving that! Thanks. I have some doubts about the name and it would be nice to fix the variantAutocomplete
as well :)
Thanks for your feedback @waiting-for-dev ❤️ I will happily add tests and docs for it after discussing some more 👍 Here's the endpoint it touches:
Security of this is a great point, this change would make it highly dependant on how well |
On further inspection, if there would be any security issues with allowing full control of parameters to solidus/api/app/controllers/spree/api/variants_controller.rb Lines 37 to 42 in d582f54
|
Ok, it all boils down to the regular usage of Ransack, so we should be fine. |
Codecov Report
@@ Coverage Diff @@
## master #4733 +/- ##
=======================================
Coverage 86.14% 86.14%
=======================================
Files 578 578
Lines 14654 14654
=======================================
Hits 12623 12623
Misses 2031 2031 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
dbd35b2
to
222767d
Compare
222767d
to
8c319fe
Compare
Specs are not getting actioned here @waiting-for-dev 🤔 |
Can you |
8c319fe
to
38c0a8f
Compare
Done this twice now, but same thing @waiting-for-dev 🤷 |
38c0a8f
to
b02bc2c
Compare
For some reason, you are unauthorized to run the build. Let's investigate that further. For now, I re-run CI and we can see the results. BUT, same that master, it's failing because the image suddenly can't find the libvips package 🤷 |
d5cb2fd
to
b02bc2c
Compare
Great, @RyanofWoods, you're no longer unauthorized! 🥳 Just rebase from master to fix the CI errors. |
From this change, when initializing a productAutocomplete, a function can be given to the searchCallback option argument. This callback should return an object (hash), and accepts a parameter which is the currently typed string in the autocomplete select2. The "q" key on the returned hash will be given to Ransack.
From this change, when initializing a variantAutocomplete, a function can be given to the searchCallback option argument. Before, variantAutocomplete accepted a object (hash) searchOptions argument, now, instead, searchCallback should be used and given a function that returns an object (hash). It accepts a parameter which is the currently typed string in the autocomplete select2. The "q" key on the returned hash will be given to Ransack if the variant_search_term key is overridden with a falsy value. For compatibility, if searchOptions was being used, searchCallback can just return the same hash.
b02bc2c
to
e021613
Compare
Nope, happened again @waiting-for-dev, wondering it's something to do with force pushing or that I am pushing to my own fork 🤔 |
e021613
to
b969610
Compare
For this endpoint use the q parameter with Ransack variant_search_term has to be a falsy value/not exist. By default, variantAutocomplete has variant_search_term defined and needs to be overriden if ransack wants to be used.
b969610
to
c89a605
Compare
I couldn't get the CircleCI tests to trigger 🤷 So I made a new PR via the Nebulab fork which did the trick. |
Summary
From this change, when initializing a productAutocomplete, a callback can be given to the searchCallback option. This callback should return a hash object that will be used to merge onto the existing parameters in the select2 ajax function. The callback also allows for one argument, which is the string typed in the select2 (term). Custom Ransack can be achieved by defining this option with the Ransack query on the
q
key.Similar behavior was already existing on the
variantAutocomplete
, however accepted a simplehash
object instead of a function, and so one didn't have access to the select2 search term, so this was improved.Checklist
Check out our PR guidelines for more details.
The following are mandatory for all PRs:
The following are not always needed (
cross them outif they are not):- [ ] I have attached screenshots to demo visual changes.- [ ] I have opened a PR to update the guides.- [ ] I have updated the README to account for my changes.Autocompletes are still working:
Variant
Orders#index
Orders#edit
Product
Promotion Rules - Product
Promotion Rules - Option Values