forest_admin_agent 1.0.0.pre.beta.66 → 1.0.0.pre.beta.67

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5fc85827537907fb926fbcda872d569326d43924765e01226c7dd7fd039e5295
4
- data.tar.gz: c8d8a5ac377333ae6ae550938c5c59b47c1a03a5d61e2e6ae95ff638f9920560
3
+ metadata.gz: 102bc16ac3f1558f735da11578c64f728e46a8d4fce2e5226e39446cbd3b83fd
4
+ data.tar.gz: 9e6cf5a41c4cfdd84733bb2bba8ed63e2b176375e32be57f5c1372fdb1e703e2
5
5
  SHA512:
6
- metadata.gz: 764cc18307625f10dc4278c76ee89c7ad786c0b5136a4942781a1a57e0976d4e8f26e953a7c0d18cc60c10503721328b779971707f5a14bb6f3fd1f0206c10f8
7
- data.tar.gz: 2886be1ee6068aba91aeb447a5fc5d55e9edcf51ac84998ce8c8b50e5418ff8a8d3c4edbc21e10fe6422d7625fd3e0eaa9fe933a5885375e6e7d824a7bb9342a
6
+ metadata.gz: 8be3201acf63fbc863320e1f663f15b18b556e0be542484081f4b0494abfa8f8d62180d6f481efb9db03ee3299da4e00d20b2d17e82b3b12da416b255e8f5996
7
+ data.tar.gz: f0ff4f00e19244e8440791d9bae621b2616e33003a3467107c1a81bdd5a62900c9dd12c5f53eaacbe46394f17202c110c3dfdec625a4307c74fa04fba79760d6
@@ -69,7 +69,11 @@ module ForestAdminAgent
69
69
  )
70
70
 
71
71
  # Now that we have the field list, we can parse the data again.
72
- data = Schema::ForestValueConverter.make_form_data(@datasource, raw_data, fields)
72
+ data = Schema::ForestValueConverter.make_form_data(
73
+ @datasource,
74
+ raw_data,
75
+ fields.reject { |field| field.type == 'Layout' }
76
+ )
73
77
 
74
78
  { content: @collection.execute(@caller, @action_name, data, filter_for_caller) }
75
79
  end
@@ -82,7 +86,7 @@ module ForestAdminAgent
82
86
  search_values = {}
83
87
  forest_fields&.each { |field| search_values[field['field']] = field['searchValue'] }
84
88
 
85
- fields = @collection.get_form(
89
+ form = @collection.get_form(
86
90
  @caller,
87
91
  @action_name,
88
92
  data,
@@ -94,10 +98,12 @@ module ForestAdminAgent
94
98
  includeHiddenFields: false
95
99
  }
96
100
  )
101
+ form_elements = Schema::GeneratorAction.extract_fields_and_layout(form)
97
102
 
98
103
  {
99
104
  content: {
100
- fields: fields&.map { |field| Schema::GeneratorAction.build_field_schema(@datasource, field) } || {}
105
+ fields: Schema::GeneratorAction.build_fields(@collection, form_elements[:fields]),
106
+ layout: Schema::GeneratorAction.build_layout(form_elements[:layout])
101
107
  }
102
108
  }
103
109
  end
@@ -2,6 +2,8 @@ module ForestAdminAgent
2
2
  module Utils
3
3
  module Schema
4
4
  class GeneratorAction
5
+ include ForestAdminDatasourceToolkit::Components
6
+
5
7
  DEFAULT_FIELDS = [
6
8
  {
7
9
  field: 'Loading...',
@@ -23,27 +25,46 @@ module ForestAdminAgent
23
25
  end
24
26
 
25
27
  def self.build_schema(collection, name)
26
- schema = collection.schema[:actions][name]
28
+ action = collection.schema[:actions][name]
27
29
  action_index = collection.schema[:actions].keys.index(name)
28
30
  slug = get_action_slug(name)
29
- fields = build_fields(collection, name, schema)
30
31
 
31
- {
32
+ form_elements = extract_fields_and_layout(collection.get_form(nil, name))
33
+ if action.static_form? && form_elements[:layout].empty?
34
+ # if action.static_form?
35
+ fields = build_fields(collection, form_elements[:fields])
36
+ layout = form_elements[:layout]
37
+ else
38
+ fields = DEFAULT_FIELDS
39
+ layout = nil
40
+ end
41
+
42
+ schema = {
32
43
  id: "#{collection.name}-#{action_index}-#{slug}",
33
44
  name: name,
34
- type: schema.scope.downcase,
45
+ type: action.scope.downcase,
35
46
  baseUrl: nil,
36
47
  endpoint: "/forest/_actions/#{collection.name}/#{action_index}/#{slug}",
37
48
  httpMethod: 'POST',
38
49
  redirect: nil, # frontend ignores this attribute
39
- download: schema.is_generate_file,
50
+ download: action.is_generate_file,
40
51
  fields: fields,
41
52
  hooks: {
42
- load: !schema.static_form?,
53
+ load: !action.static_form?,
43
54
  # Always registering the change hook has no consequences, even if we don't use it.
44
55
  change: ['changeHook']
45
56
  }
46
57
  }
58
+
59
+ return schema unless layout && !layout.empty?
60
+
61
+ schema[:layout] = build_layout(layout)
62
+
63
+ schema
64
+ end
65
+
66
+ def self.build_layout_schema(field)
67
+ { **field.to_h, component: field.component.downcase }
47
68
  end
48
69
 
49
70
  def self.build_field_schema(datasource, field)
@@ -76,26 +97,49 @@ module ForestAdminAgent
76
97
  output
77
98
  end
78
99
 
79
- class << self
80
- private
81
-
82
- def build_fields(collection, name, action)
83
- return DEFAULT_FIELDS unless action.static_form?
100
+ def self.build_fields(collection, fields)
101
+ if fields
102
+ return fields.map do |field|
103
+ new_field = build_field_schema(collection.datasource, field)
104
+ new_field[:default_value] = new_field[:value]
105
+ new_field.delete(:value)
84
106
 
85
- fields = collection.get_form(nil, name)
107
+ new_field
108
+ end
109
+ end
86
110
 
87
- if fields
88
- return fields.map do |field|
89
- new_field = build_field_schema(collection.datasource, field)
90
- new_field[:default_value] = new_field[:value]
91
- new_field.delete(:value)
111
+ []
112
+ end
92
113
 
93
- new_field
94
- end
114
+ def self.build_layout(elements)
115
+ if elements
116
+ return elements.map do |element|
117
+ build_layout_schema(element)
95
118
  end
119
+ end
120
+
121
+ []
122
+ end
123
+
124
+ def self.extract_fields_and_layout(form)
125
+ fields = []
126
+ layout = []
127
+ has_real_layout = false
96
128
 
97
- []
129
+ form&.each do |element|
130
+ if element.type == Actions::FieldType::LAYOUT
131
+ layout << element
132
+ has_real_layout = true
133
+ else
134
+ fields << element
135
+ # frontend rule
136
+ layout << Actions::ActionLayoutElement::InputElement.new(component: 'Input', field_id: element.label)
137
+ end
98
138
  end
139
+
140
+ layout = [] unless has_real_layout
141
+
142
+ { fields: fields, layout: layout }
99
143
  end
100
144
  end
101
145
  end
@@ -7,7 +7,7 @@ module ForestAdminAgent
7
7
  class SchemaEmitter
8
8
  LIANA_NAME = "agent-ruby"
9
9
 
10
- LIANA_VERSION = "1.0.0-beta.66"
10
+ LIANA_VERSION = "1.0.0-beta.67"
11
11
 
12
12
  def self.get_serialized_schema(datasource)
13
13
  schema_path = Facades::Container.cache(:schema_path)
@@ -66,6 +66,7 @@ module ForestAdminAgent
66
66
  schema[:collections].each do |collection|
67
67
  collection_actions = collection[:actions]
68
68
  collection_segments = collection[:segments]
69
+
69
70
  collection.delete(:actions)
70
71
  collection.delete(:segments)
71
72
 
@@ -94,6 +95,7 @@ module ForestAdminAgent
94
95
 
95
96
  def get_smart_features_by_collection(type, data, with_attributes: false)
96
97
  smart_features = []
98
+
97
99
  data.each do |value|
98
100
  smart_feature = { id: value[:id], type: type }
99
101
  smart_feature[:attributes] = value if with_attributes
@@ -1,3 +1,3 @@
1
1
  module ForestAdminAgent
2
- VERSION = "1.0.0-beta.66"
2
+ VERSION = "1.0.0-beta.67"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forest_admin_agent
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre.beta.66
4
+ version: 1.0.0.pre.beta.67
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-09-05 00:00:00.000000000 Z
12
+ date: 2024-09-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport