bullet-train-pro / bullet_train-action_models

Other
5 stars 1 forks source link

Refine use of bulk action select #98

Open gazayas opened 8 months ago

gazayas commented 8 months ago

As I was working on https://github.com/bullet-train-co/bullet_train-core/pull/776, I figured it would make sense to super scaffold bulk_action_select when we create a new action, as opposed to just having it show for all models whenever bullet_train-action_models is enabled.

The reason being that the we only use the bulk select when performing an action. Right now we just apply the partial to all models, even when there are no actions to perform on it (Refer to the hide_actions conditional in the files in https://github.com/bullet-train-co/bullet_train-core/pull/776).

We could go with one of two options

  1. Extend the bulk select to delete records, or to do any other processing that would make sense to include in standard Bullet Train applications. Then we could remove the hide_actions conditional altogether.
  2. Only scaffold the bulk select partial when super scaffolding a new action.

If we go with option two, I think we could add a method in the base scaffolder, lib/scaffolding/action_model_transformer.rb, and then call it for each Action which requires it (i.e. - TargetsMany).

def scaffold_bulk_action_select(file_name)
  transformed_file_name = transform(file_name)
  file_content = File.read(transformed_file_name)
  block_manipulator = Scaffolding::BlockManipulator.new(transformed_file_name)
  # Then insert `<%= render 'shared/bulk_action_select' %>` above the proper Action Models scaffolding hook
end