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

fix: extract fields from sidebar and add them to permitted params #2053

Merged
merged 8 commits into from
Nov 23, 2023
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions lib/avo/concerns/has_items.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,19 @@ def only_fields(only_root: false)
unless only_root
# Dive into panels to fetch their fields
if item.is_panel?
fields << extract_fields_from_items(item)
fields << extract_fields(item)
end

# Dive into tabs to fetch their fields
if item.is_tab_group?
item.items.map do |tab|
fields << extract_fields_from_items(tab)
fields << extract_fields(tab)
end
end

# Dive into sidebar to fetch their fields
if item.is_sidebar?
fields << extract_fields_from_items(item)
fields << extract_fields(item)
end
end

Expand All @@ -108,11 +108,11 @@ def only_fields(only_root: false)
end

if item.is_row?
fields << extract_fields_from_items(tab)
fields << extract_fields(tab)
end

if item.is_main_panel?
fields << extract_fields_from_items(item)
fields << extract_fields(item)
end
end

Expand Down Expand Up @@ -309,18 +309,20 @@ def set_target_to_top(fields)
end
end

def extract_fields_from_items(thing)
fields = []
# Extracts fields from a structure
# Structures can be panels, rows and sidebars
def extract_fields(structure)
Paul-Bob marked this conversation as resolved.
Show resolved Hide resolved
Paul-Bob marked this conversation as resolved.
Show resolved Hide resolved
structure.items.map do |item|
next item if item.is_field?

thing.items.each do |item|
if item.is_field?
fields << item
elsif item.is_panel? || item.is_row?
fields << extract_fields_from_items(item)
end
end
extract_fields(item) if extractable_structure?(item)
end.compact
end

fields
# Extractable structures are panels, rows and sidebars
# Sidebars are only extractable if they are not on the index view
def extractable_structure?(structure)
structure.is_panel? || structure.is_row? || (structure.is_sidebar? && !view.index?)
end

# Standalone items are fields that don't have their own panel
Expand Down
Loading