avo-hq / avo

Build Ruby on Rails apps 10x faster
https://avohq.io
Other
1.44k stars 225 forks source link

Repeater field #2867

Open adrianthedev opened 4 weeks ago

adrianthedev commented 4 weeks ago

Feature

# for a resource called product
# variants can be an association on the model product
  # We should figure it out fom the reflections
  # and do what we need to do to make it work
# variants can be a json field on the product table
  # We should figure it out fom the db schema
  # and "just pass it"
# variants can be some plain object/method that creates something else through a gem (like acts_as_taggalble_on (an assocition))
  # Maybe 
# variants can be a json field on the product table
field :variants,
  as: :repeater,
  limit: 10,
  can_add: true, # callable too
  can_update: -> { curren_user.admin? ? true : false },
  can_order: true, # maybe
  update_using: -> {
    record # is the actual product
    item # is the variant; which is a hash?
    _id # maybe
    _position # is the position of the item in the list. something we expose "privately"
    # do something with the item

    item.position = _position
  }
  can_delete: true do
    field :id, as: :id # this should not show up as it's an "edit view"
    field :color, as: :select
    field :description, as: :textarea
    field :price, as: :money
  end

# pseudo code being run
product.variants = [
  { id: 1, color: "red", description: "A red variant", price: 10 }, # this will be updated
  { id: 2, color: "blue", description: "A blue variant", price: 20 }, # this will be updated
  { color: "green", description: "A blue variant", price: 20 }, # this will be created
]
### Next iteration
- [ ] drag and drop reorder
- [ ] collapse items (accordion-like)
- [ ] maybe a "title" on the header bar
- [ ] add items at position (between other items)
### Related PRs/Issues
- [ ] https://github.com/avo-hq/avo/issues/2854#issuecomment-2173344168
- [ ] https://github.com/avo-hq/avo/issues/1583
github-actions[bot] commented 1 week ago

This issue has been marked as stale because there was no activity for the past 15 days.