forest_admin_datasource_customizer 1.0.0.pre.beta.82 → 1.0.0.pre.beta.85

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: 299499a2210846eb377245a543896dcec7714ae5dc55f8958e0434275f0b23f0
4
- data.tar.gz: f26199d80505c75939bf4d08c075e87be41d8e63be6073b17a3b96c764190c8b
3
+ metadata.gz: c72efdb33fb2fc538bbf3bd8082ddbf5620fb082ad6254d89f0c3822d68358ef
4
+ data.tar.gz: bcd0f24e6d8abd66cbd7fedf4516f23971c0784f86bafdba289ebb39a2451703
5
5
  SHA512:
6
- metadata.gz: 37e9e714ac9926534566252e6fc5cf0e7237e7772e99ceb43cf1474b3a546a3d313d4d984b311ca853bf5933bdaed7ec463f0c19bde7ed52de466f9a9586872e
7
- data.tar.gz: fe78f7fedb32dc6376479c5c9bf4f67f4b7641ffbc7be4033ee3e3cefc105aa04af520e94f572a74084a545168f824e7f550cd7a4cafedbbb61dc136ddb08aaf
6
+ metadata.gz: 1e0f37284e0df57b62fe6b81fa6bb5df4541218d0a345eaab5ffe39ae2f3d87cfd622be13fbadbbcb7d9819b76264a87bec1b695140df6d451a027ee7650e664
7
+ data.tar.gz: 8a53ba29e8b032bdb7c644c427292ae86827ef81d97ef0d419fc2b57d42eadd8e8ffe76eb76887b4f4ae8b54a80e206f820b0319acc2ca647ce50bffefd225fe
@@ -1,10 +1,11 @@
1
1
  module ForestAdminDatasourceCustomizer
2
2
  class DatasourceCustomizer
3
- attr_reader :stack
3
+ attr_reader :stack, :datasources
4
4
 
5
5
  def initialize(_db_config = {})
6
6
  @composite_datasource = ForestAdminDatasourceToolkit::Datasource.new
7
7
  @stack = Decorators::DecoratorsStack.new(@composite_datasource)
8
+ @datasources = []
8
9
  end
9
10
 
10
11
  def schema
@@ -46,6 +47,8 @@ module ForestAdminDatasourceCustomizer
46
47
  end
47
48
  })
48
49
 
50
+ @datasources << datasource
51
+
49
52
  self
50
53
  end
51
54
 
@@ -72,6 +75,19 @@ module ForestAdminDatasourceCustomizer
72
75
  self
73
76
  end
74
77
 
78
+ def get_root_datasource_by_connection(name)
79
+ root_datasource = @datasources.find do |datasource|
80
+ datasource.live_query_connections.any? { |connection_name, _connection| connection_name == name }
81
+ end
82
+
83
+ unless root_datasource
84
+ raise ForestAdminAgent::Http::Exceptions::NotFoundError,
85
+ "Native query connection '#{name}' is unknown."
86
+ end
87
+
88
+ root_datasource
89
+ end
90
+
75
91
  private
76
92
 
77
93
  def push_customization(&customization)
@@ -25,34 +25,37 @@ module ForestAdminDatasourceCustomizer
25
25
  sub_schema
26
26
  end
27
27
 
28
- def refine_filter(caller, filter = nil)
28
+ def refine_filter(_caller, filter = nil)
29
29
  return nil unless filter
30
30
 
31
31
  condition_tree = filter.condition_tree
32
32
  segment = filter.segment
33
-
34
33
  if segment && @segments.key?(segment)
35
- definition = @segments[segment]
34
+ condition_tree = compute_segment(segment, filter)
35
+ segment = nil
36
+ end
36
37
 
37
- result = if definition.respond_to? :call
38
- definition.call(Context::CollectionCustomizationContext.new(self, caller))
39
- else
40
- definition
41
- end
38
+ filter.override(condition_tree: condition_tree, segment: segment)
39
+ end
42
40
 
43
- condition_tree_segment = if result.is_a? Nodes::ConditionTree
44
- result
45
- else
46
- ConditionTreeFactory.from_plain_object(result)
47
- end
41
+ def compute_segment(segment_name, filter)
42
+ definition = @segments[segment_name]
48
43
 
49
- ConditionTreeValidator.validate(condition_tree_segment, self)
44
+ result = if definition.respond_to? :call
45
+ definition.call(Context::CollectionCustomizationContext.new(self, caller))
46
+ else
47
+ definition
48
+ end
50
49
 
51
- condition_tree = ConditionTreeFactory.intersect([condition_tree_segment, filter.condition_tree])
52
- segment = nil
53
- end
50
+ condition_tree_segment = if result.is_a? Nodes::ConditionTree
51
+ result
52
+ else
53
+ ConditionTreeFactory.from_plain_object(result)
54
+ end
54
55
 
55
- filter.override(condition_tree: condition_tree, segment: segment)
56
+ ConditionTreeValidator.validate(condition_tree_segment, self)
57
+
58
+ ConditionTreeFactory.intersect([condition_tree_segment, filter.condition_tree])
56
59
  end
57
60
  end
58
61
  end
@@ -42,10 +42,10 @@ module ForestAdminDatasourceCustomizer
42
42
  reference_records = child_filter.page.apply(reference_records) if child_filter.page
43
43
 
44
44
  # We now have the information we need to sort by the field
45
- new_filter = Filter.new(condition_tree: ConditionTree::ConditionTreeFactory.match_records(schema,
45
+ new_filter = Filter.new(condition_tree: ConditionTree::ConditionTreeFactory.match_records(self,
46
46
  reference_records))
47
47
 
48
- records = child_collection.list(caller, new_filter, projection.with_pks(self))
48
+ records = child_collection.list(caller, new_filter, projection.clone.with_pks(self))
49
49
  records = sort_records(reference_records, records)
50
50
 
51
51
  projection.apply(records)
@@ -89,7 +89,7 @@ module ForestAdminDatasourceCustomizer
89
89
 
90
90
  def emulated?(path)
91
91
  index = path.index(':')
92
- return @sorts[path] if index.nil?
92
+ return @sorts.key?(path) if index.nil?
93
93
 
94
94
  foreign_collection = schema[:fields][path[0, index]].foreign_collection
95
95
  association = datasource.get_collection(foreign_collection)
@@ -101,7 +101,7 @@ module ForestAdminDatasourceCustomizer
101
101
 
102
102
  def replace_or_emulate_field_sorting(name, equivalent_sort)
103
103
  FieldValidator.validate(self, name)
104
- @sorts[name] =
104
+ @sorts[name.to_s] =
105
105
  equivalent_sort ? ForestAdminDatasourceToolkit::Components::Query::Sort.new(equivalent_sort) : nil
106
106
  mark_schema_as_dirty
107
107
  end
@@ -111,11 +111,11 @@ module ForestAdminDatasourceCustomizer
111
111
  sorted = Array.new(records.length)
112
112
 
113
113
  reference_records.each_with_index do |record, index|
114
- position_by_id[Record.primary_keys(schema, record).join('|')] = index
114
+ position_by_id[Record.primary_keys(self, record).join('|')] = index
115
115
  end
116
116
 
117
117
  records.each do |record|
118
- id = Record.primary_keys(schema, record).join('|')
118
+ id = Record.primary_keys(self, record).join('|')
119
119
  sorted[position_by_id[id]] = record
120
120
  end
121
121
 
@@ -1,3 +1,3 @@
1
1
  module ForestAdminDatasourceCustomizer
2
- VERSION = "1.0.0-beta.82"
2
+ VERSION = "1.0.0-beta.85"
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.0.0.pre.beta.82
4
+ version: 1.0.0.pre.beta.85
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-12-04 00:00:00.000000000 Z
12
+ date: 2024-12-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport