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

Nebulab/bulk actions #91

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

DanielePalombo
Copy link
Member

@DanielePalombo DanielePalombo commented Jan 22, 2021

Description
Allow executing an action on more than one product.

How it works:
When the item are selected the available actions will be shown at top right.
Screenshot 2021-01-22 at 18 45 41

Click on the action and a modal preview will be open:
Screenshot 2021-01-22 at 18 45 54

Confirm the modal and the BatchAction will be processed
Screenshot 2021-01-22 at 18 46 04

How to make your own action 3b1a45f
Create your callable object under app/models/spree/batch_action/ and let it to inheredit from Spree::BatchAction::Base and return the affected collection.
Create the _preview.html.erb and result.html.erb partials under app/views/spree/admin/batch_actions/destroy_record_action/

How to use an action on resource controller
df0d786

Add the following code to the Controller:

include Spree::Backend::Batch
set_batch_actions [
  { action: 'Spree::BatchAction::DestroyRecordAction', icon: :trash, label: :delete }
]

the actionable_routes concern on the related resources route.

Make the resource table a selectable table and add the actionable class to it.
Provide also the right data to it:

data: {
        actions: batch_action_buttons(batch_actions),
        search_form_selector: 'form.spree\\/product_search',
        preview_batch_url: preview_batch_admin_products_path,
        process_batch_url: process_batch_admin_products_path
      }

Checklist:

  • I have followed Pull Request guidelines
  • I have added a detailed description into each commit message
  • I have updated Guides and README accordingly to this change (if needed)
  • I have added tests to cover this change (if needed)
  • I have attached screenshots to this PR for visual changes (if needed)

This commit is going to add a standard way to load the modals in solidus.
They can be load and store as global object Spree.Views.Modals.
This is the base object to create the batch actions.
Any batch action object should inherit from it and overriding the `call` method.
Include this concern into controller to manage a batch action list.

e.g.

```
include Spree::Backend::Batch
      set_batch_actions [
        { action: 'Spree::BatchAction::DestroyRecordAction', icon: :trash, label: :delete }
      ]
```

In this way the controller will be able to run the specified batch
actions
This modal will show when a batch action is clicked.
When the modal is shown it will be possible to show to the user an
action preview, in this way we can ask to the user other configuration
or just show what the action will do
This commit adds to the Spree::Backend::Batch concern the
`preview_batch` action.
It will render the related partial under
`spree/admin/batch_actions/*BATCH_ACTION_NAME*/preview` template.
In this way, any BatchAction would have been its template and ask to the
user other fields required to process the collection.
This modal will render the batch action result.
process_batch action is used to execute the BatchAction and return the
result as js.
Execute the batch action and return the result in a modal.
This is the first batch action.
It will handle the delete of multiple records.

The partials _preview.html.erb and _result.html.erb are required to
support admin user during usage.
@cesartalves
Copy link

This is a great addition! A few notes:

I changed the Batch Action interface on https://github.com/arfabrands/acs-core/pull/213 slightly to allow parameters to be passed to the batch_action.

image

Basically, the concern collects all parameters under :batch_actions and passes to the action as a hash. I believe this gives greater flexibility to the interface.
Maybe include this on this revision or next one?

--
Also, kinda unrelated but sometimes I get a 500 on the preview_batch action, which seems to be related to the frozen_string_literal magic comment. Perhaps we should understand this problem before merging.

image

@DanielePalombo
Copy link
Member Author

Thank you for this addition @cesartalves 💪

if (msg.responseJSON["error"]) {
show_flash('error', msg.responseJSON["error"]);
} else {
show_flash('error', "There was a problem adding this coupon code.");
Copy link

@cesartalves cesartalves Apr 6, 2021

Choose a reason for hiding this comment

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

I believe we can change this to a more generic error message right?
We could also use i18n here so that users can easily customize this message.

if (msg.responseJSON["error"]) {
show_flash('error', msg.responseJSON["error"]);
} else {
show_flash('error', "There was a problem adding this coupon code.");
Copy link

@cesartalves cesartalves Apr 6, 2021

Choose a reason for hiding this comment

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

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.

2 participants