forest_admin_datasource_customizer 1.0.0.pre.beta.59 → 1.0.0.pre.beta.61
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/forest_admin_datasource_customizer/decorators/computed/utils/computed_field.rb +13 -5
- data/lib/forest_admin_datasource_customizer/decorators/computed/utils/flattener.rb +49 -3
- data/lib/forest_admin_datasource_customizer/decorators/search/search_collection_decorator.rb +1 -1
- data/lib/forest_admin_datasource_customizer/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 01a3e9d078567da75ac00fbce2df8722f362800ac0e67108691755f8ea3908ea
|
4
|
+
data.tar.gz: b7fb6555dcefb5e78f6fceba1afaca3459d73f52692be6492d6992a9875c3de8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: abfb2618846aebd32cacb55c85a074786e59e72596baefded111a7e1a801622ee9d5b7bc1ab19c3c74018a19e692fb600c9fa47043b146efb1c4fc438cff3b82
|
7
|
+
data.tar.gz: ee3c04a82b7b8cc35ee009a935b26f06e014bfb95b6d34b8e82263c3433ba665619d59ad9795020c9399cd83d538758cef97aad01725f7a5701cffb1b0def061
|
@@ -19,28 +19,36 @@ module ForestAdminDatasourceCustomizer
|
|
19
19
|
return if paths.include?(new_path)
|
20
20
|
|
21
21
|
computed = collection.get_computed(new_path)
|
22
|
-
|
23
|
-
|
22
|
+
computed_dependencies = Flattener.with_null_marker(computed.dependencies)
|
23
|
+
nested_dependencies = Projection.new(computed_dependencies)
|
24
|
+
.nest(
|
25
|
+
prefix: if new_path.include?(':')
|
26
|
+
new_path.slice(0, new_path.rindex(':'))
|
27
|
+
end
|
28
|
+
)
|
24
29
|
|
25
30
|
nested_dependencies.each do |path|
|
26
31
|
queue_field(ctx, collection, path, paths, flatten)
|
27
32
|
end
|
28
33
|
|
29
34
|
dependency_values = nested_dependencies.map { |path| flatten[paths.index(path)] }
|
35
|
+
|
30
36
|
paths.push(new_path)
|
31
37
|
|
32
|
-
flatten << compute_field(ctx, computed,
|
38
|
+
flatten << compute_field(ctx, computed, computed_dependencies, dependency_values)
|
33
39
|
end
|
34
40
|
|
35
41
|
def self.compute_from_records(ctx, collection, records_projection, desired_projection, records)
|
36
|
-
paths = records_projection
|
42
|
+
paths = Flattener.with_null_marker(records_projection)
|
37
43
|
flatten = Flattener.flatten(records, paths)
|
38
44
|
|
39
45
|
desired_projection.each do |path|
|
40
46
|
queue_field(ctx, collection, path, paths, flatten)
|
41
47
|
end
|
42
48
|
|
43
|
-
|
49
|
+
final_projection = Flattener.with_null_marker(desired_projection)
|
50
|
+
|
51
|
+
Flattener.un_flatten(final_projection.map { |path| flatten[paths.index(path)] }, final_projection)
|
44
52
|
end
|
45
53
|
|
46
54
|
def self.transform_unique_values(inputs, callback)
|
@@ -3,9 +3,55 @@ module ForestAdminDatasourceCustomizer
|
|
3
3
|
module Computed
|
4
4
|
module Utils
|
5
5
|
class Flattener
|
6
|
+
include ForestAdminDatasourceToolkit::Components::Query
|
7
|
+
|
8
|
+
class Undefined
|
9
|
+
def key?(_key)
|
10
|
+
false
|
11
|
+
end
|
12
|
+
|
13
|
+
def dig(*_keys)
|
14
|
+
self
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
MARKER_NAME = '__null_marker'.freeze
|
19
|
+
def self.with_null_marker(projection)
|
20
|
+
new_projection = Projection.new(projection)
|
21
|
+
projection.each do |path|
|
22
|
+
parts = path.split(':')
|
23
|
+
|
24
|
+
parts.slice(1, parts.size).each_with_index do |_item, index|
|
25
|
+
new_projection << "#{parts.slice(0, index + 1).join(":")}:#{MARKER_NAME}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
new_projection.uniq
|
30
|
+
end
|
31
|
+
|
6
32
|
def self.flatten(records, projection)
|
7
33
|
projection.map do |field|
|
8
|
-
|
34
|
+
parts = field.split(':')
|
35
|
+
records.map do |record|
|
36
|
+
value = record
|
37
|
+
|
38
|
+
parts.slice(0, parts.size - 1).each_with_index do |_item, index|
|
39
|
+
value = if value&.key?(parts[index])
|
40
|
+
value[parts[index]]
|
41
|
+
else
|
42
|
+
Undefined.new
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# for markers, the value tells us which fields are null so that we can set them.
|
47
|
+
if parts[parts.length - 1] == MARKER_NAME
|
48
|
+
value.nil? ? nil : Undefined.new
|
49
|
+
elsif value&.key?(parts[parts.length - 1])
|
50
|
+
value[parts[parts.length - 1]]
|
51
|
+
else
|
52
|
+
Undefined.new
|
53
|
+
end
|
54
|
+
end
|
9
55
|
end
|
10
56
|
end
|
11
57
|
|
@@ -17,11 +63,11 @@ module ForestAdminDatasourceCustomizer
|
|
17
63
|
records[record_index] = {}
|
18
64
|
|
19
65
|
projection.each_with_index do |path, path_index|
|
20
|
-
parts = path.split(':').reject { |part| part
|
66
|
+
parts = path.split(':').reject { |part| part == MARKER_NAME }
|
21
67
|
value = flatten[path_index][record_index]
|
22
68
|
|
23
69
|
# Ignore undefined values.
|
24
|
-
next if value.
|
70
|
+
next if value.is_a? Undefined
|
25
71
|
|
26
72
|
# Set all others (including null)
|
27
73
|
record = records[record_index]
|
data/lib/forest_admin_datasource_customizer/decorators/search/search_collection_decorator.rb
CHANGED
@@ -20,7 +20,7 @@ module ForestAdminDatasourceCustomizer
|
|
20
20
|
|
21
21
|
def refine_filter(caller, filter)
|
22
22
|
# Search string is not significant
|
23
|
-
return filter.override({ search: nil }) if !filter || !filter.search || filter.search.strip&.
|
23
|
+
return filter.override({ search: nil }) if !filter || !filter.search || filter.search.strip&.empty?
|
24
24
|
|
25
25
|
# Implement search ourselves
|
26
26
|
if @replacer || !@child_collection.schema[:searchable]
|
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.0.0.pre.beta.
|
4
|
+
version: 1.0.0.pre.beta.61
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthieu
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2024-07-
|
12
|
+
date: 2024-07-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|