forest_admin_datasource_customizer 1.16.6 → 1.16.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 88a8eec88408a61cfe18b06d9b6a00d7f9752e1f0f7a0634d707d306ff417e51
4
- data.tar.gz: 9a7367fbb6e052077120295e53d36b0ff74d2647f3ad466a3a96fa12c229c48f
3
+ metadata.gz: 82e278319e01d29d59e70dc15f727d82ccc9d3d48bbafa6592c33ccb11573734
4
+ data.tar.gz: cfaa2bfb96607e8760b136e53a05846375e3114ffe18f1fe5023ca0691911be2
5
5
  SHA512:
6
- metadata.gz: cdb4c1439e10a28ad2788837b63ed37eaf88bbb27ff216aeb03a76b62b2741f66c8790d1eb7ea58223fb27fdabb235b7fd0181882037054fbe488d3ea33e9183
7
- data.tar.gz: cc92ee88c407852a979233016e970bae6e7419592c19bfc25f71233ebd172d0a47d80b4269bca3a48f99454d8e720f02e5717173b670d1ae411066b08a045daa
6
+ metadata.gz: c1973f833993be5e828ff73df8171a32b1ac1cfc4a18c55e335b88f6955f3791482adf03c1e0ebbab457f7c7c28ba5249aeb49abd14bc7422bb2744dd487acff
7
+ data.tar.gz: 8b8febafd935cacff3bc44f06f555d17e23f9986d98b48998b42d2947db4805df3d64e8b93cbcd63681f7e170a62eed6af3247b8fb6aceec4148a06601313d7b
@@ -68,7 +68,7 @@ module ForestAdminDatasourceCustomizer
68
68
 
69
69
  def list(caller, filter, projection)
70
70
  records = super
71
- records.map! { |record| convert_record(false, record) }
71
+ records.map! { |record| convert_record(false, record, projection) }
72
72
 
73
73
  records
74
74
  end
@@ -126,17 +126,43 @@ module ForestAdminDatasourceCustomizer
126
126
  Utils::Schema.primary_key?(@child_collection, name) || Utils::Schema.foreign_key?(@child_collection, name)
127
127
  end
128
128
 
129
- def convert_record(to_backend, record)
130
- if record
131
- record = record.to_h do |path, value|
132
- [path, convert_value(to_backend, path, value)]
129
+ def convert_record(to_backend, record, projection = nil)
130
+ return record unless record
131
+
132
+ result = {}
133
+ record.each do |path, value|
134
+ # Skip fields that don't exist in the schema (e.g., virtual attributes)
135
+ prefix = path.split(':').first
136
+ next unless @child_collection.schema[:fields][prefix]
137
+
138
+ if projection.nil?
139
+ result[path] = convert_value(to_backend, path, value, nil)
140
+ else
141
+ sub_projection = extract_sub_projection(projection, path)
142
+ result[path] = if sub_projection
143
+ convert_value(to_backend, path, value, sub_projection)
144
+ else
145
+ value
146
+ end
133
147
  end
134
148
  end
135
149
 
136
- record
150
+ result
151
+ end
152
+
153
+ def extract_sub_projection(projection, path)
154
+ # Check if the field is directly in the projection
155
+ return Projection.new([path]) if projection.include?(path)
156
+
157
+ # Check if any field in the projection starts with "path:"
158
+ sub_fields = projection.select { |p| p.start_with?("#{path}:") }
159
+ return nil if sub_fields.empty?
160
+
161
+ # Extract the sub-projection by removing the prefix
162
+ Projection.new(sub_fields.map { |p| p[(path.length + 1)..] })
137
163
  end
138
164
 
139
- def convert_value(to_backend, path, value)
165
+ def convert_value(to_backend, path, value, projection = nil)
140
166
  prefix, suffix = path.split(':')
141
167
  field = @child_collection.schema[:fields][prefix]
142
168
 
@@ -151,9 +177,13 @@ module ForestAdminDatasourceCustomizer
151
177
  if field.type != 'Column'
152
178
  foreign_collection = @datasource.get_collection(field.foreign_collection)
153
179
 
154
- return suffix ? foreign_collection.convert_value(to_backend, suffix,
155
- value) : foreign_collection.convert_record(to_backend,
156
- value)
180
+ result = if suffix
181
+ foreign_collection.convert_value(to_backend, suffix, value, projection)
182
+ else
183
+ foreign_collection.convert_record(to_backend, value, projection)
184
+ end
185
+
186
+ return result
157
187
  end
158
188
 
159
189
  binary_mode = should_use_hex(path)
@@ -201,6 +201,9 @@ module ForestAdminDatasourceCustomizer
201
201
  field = from_child_collection[child_field] || child_field
202
202
  field_schema = schema[:fields][field]
203
203
 
204
+ # Skip fields that don't exist in the schema (e.g., virtual attributes)
205
+ next unless field_schema
206
+
204
207
  # Perform the mapping, recurse for relation
205
208
  if field_schema.type == 'Column' || value.nil? || field_schema.type == 'PolymorphicManyToOne' ||
206
209
  field_schema.type == 'PolymorphicOneToOne'
@@ -1,3 +1,3 @@
1
1
  module ForestAdminDatasourceCustomizer
2
- VERSION = "1.16.6"
2
+ VERSION = "1.16.7"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forest_admin_datasource_customizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.16.6
4
+ version: 1.16.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthieu