Skip to content

Commit 64d5780

Browse files
committed
Address BE review changes
1 parent 55d99f3 commit 64d5780

7 files changed

Lines changed: 124 additions & 120 deletions

File tree

server/compose/envoy/store_decode.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,28 +163,28 @@ func decodePageRefs(p *types.Page) (refs map[string]envoyx.Ref) {
163163
for index, b := range p.Blocks {
164164
switch b.Kind {
165165
case "RecordList":
166-
refs = envoyx.MergeRefs(refs, getPageBlockRecordListRefs(b, index))
166+
refs = envoyx.MergeRefs(refs, getPageBlockRecordListRefs(b.Options, index))
167167

168168
case "Automation":
169-
refs = envoyx.MergeRefs(refs, getPageBlockAutomationRefs(b, index))
169+
refs = envoyx.MergeRefs(refs, getPageBlockAutomationRefs(b.Options, index))
170170

171171
case "RecordOrganizer":
172-
refs = envoyx.MergeRefs(refs, getPageBlockRecordOrganizerRefs(b, index))
172+
refs = envoyx.MergeRefs(refs, getPageBlockRecordOrganizerRefs(b.Options, index))
173173

174174
case "Chart":
175-
refs = envoyx.MergeRefs(refs, getPageBlockChartRefs(b, index))
175+
refs = envoyx.MergeRefs(refs, getPageBlockChartRefs(b.Options, index))
176176

177177
case "Calendar":
178-
refs = envoyx.MergeRefs(refs, getPageBlockCalendarRefs(b, index))
178+
refs = envoyx.MergeRefs(refs, getPageBlockCalendarRefs(b.Options, index))
179179

180180
case "Metric":
181-
refs = envoyx.MergeRefs(refs, getPageBlockMetricRefs(b, index))
181+
refs = envoyx.MergeRefs(refs, getPageBlockMetricRefs(b.Options, index))
182182

183183
case "Comment":
184-
refs = envoyx.MergeRefs(refs, getPageBlockCommentRefs(b, index))
184+
refs = envoyx.MergeRefs(refs, getPageBlockCommentRefs(b.Options, index))
185185

186186
case "Progress":
187-
refs = envoyx.MergeRefs(refs, getPageBlockProgressRefs(b, index))
187+
refs = envoyx.MergeRefs(refs, getPageBlockProgressRefs(b.Options, index))
188188
}
189189
}
190190

server/compose/envoy/yaml_decode.go

Lines changed: 44 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -73,74 +73,55 @@ func (d *auxYamlDoc) unmarshalPageBlocksNode(r *types.Page, n *yaml.Node) (refs
7373
refs = map[string]envoyx.Ref{}
7474

7575
for index, b := range r.Blocks {
76-
switch b.Kind {
77-
case "RecordList":
78-
refs = envoyx.MergeRefs(refs, getPageBlockRecordListRefs(b, index))
79-
80-
case "Automation":
81-
refs = envoyx.MergeRefs(refs, getPageBlockAutomationRefs(b, index))
82-
83-
case "RecordOrganizer":
84-
refs = envoyx.MergeRefs(refs, getPageBlockRecordOrganizerRefs(b, index))
85-
86-
case "Chart":
87-
refs = envoyx.MergeRefs(refs, getPageBlockChartRefs(b, index))
88-
89-
case "Calendar":
90-
refs = envoyx.MergeRefs(refs, getPageBlockCalendarRefs(b, index))
91-
92-
case "Metric":
93-
refs = envoyx.MergeRefs(refs, getPageBlockMetricRefs(b, index))
94-
95-
case "Comment":
96-
refs = envoyx.MergeRefs(refs, getPageBlockCommentRefs(b, index))
97-
98-
case "Progress":
99-
refs = envoyx.MergeRefs(refs, getPageBlockProgressRefs(b, index))
100-
}
76+
idents, err = unmarshalResourceBlocksNode(b.Kind, b.Options, index, refs)
10177
}
102-
10378
return
10479
}
10580

10681
func (d *auxYamlDoc) unmarshalNamespaceBlocksNode(r *types.Namespace, n *yaml.Node) (refs map[string]envoyx.Ref, idents envoyx.Identifiers, err error) {
10782
refs = map[string]envoyx.Ref{}
10883

109-
for index, b := range r.Blocks {
110-
switch b.Kind {
111-
case "RecordList":
112-
refs = envoyx.MergeRefs(refs, getPageBlockRecordListRefs(b, index))
84+
for index, gBlock := range r.Blocks {
85+
idents, err = unmarshalResourceBlocksNode(gBlock.Kind, gBlock.Options, index, refs)
86+
}
87+
88+
return
89+
}
11390

114-
case "Automation":
115-
refs = envoyx.MergeRefs(refs, getPageBlockAutomationRefs(b, index))
91+
func unmarshalResourceBlocksNode(kind string, options map[string]interface{}, index int, refs map[string]envoyx.Ref) (idents envoyx.Identifiers, err error) {
92+
switch kind {
93+
case "RecordList":
94+
refs = envoyx.MergeRefs(refs, getPageBlockRecordListRefs(options, index))
11695

117-
case "RecordOrganizer":
118-
refs = envoyx.MergeRefs(refs, getPageBlockRecordOrganizerRefs(b, index))
96+
case "Automation":
97+
refs = envoyx.MergeRefs(refs, getPageBlockAutomationRefs(options, index))
11998

120-
case "Chart":
121-
refs = envoyx.MergeRefs(refs, getPageBlockChartRefs(b, index))
99+
case "RecordOrganizer":
100+
refs = envoyx.MergeRefs(refs, getPageBlockRecordOrganizerRefs(options, index))
122101

123-
case "Calendar":
124-
refs = envoyx.MergeRefs(refs, getPageBlockCalendarRefs(b, index))
102+
case "Chart":
103+
refs = envoyx.MergeRefs(refs, getPageBlockChartRefs(options, index))
125104

126-
case "Metric":
127-
refs = envoyx.MergeRefs(refs, getPageBlockMetricRefs(b, index))
105+
case "Calendar":
106+
refs = envoyx.MergeRefs(refs, getPageBlockCalendarRefs(options, index))
128107

129-
case "Comment":
130-
refs = envoyx.MergeRefs(refs, getPageBlockCommentRefs(b, index))
108+
case "Metric":
109+
refs = envoyx.MergeRefs(refs, getPageBlockMetricRefs(options, index))
131110

132-
case "Progress":
133-
refs = envoyx.MergeRefs(refs, getPageBlockProgressRefs(b, index))
134-
}
111+
case "Comment":
112+
refs = envoyx.MergeRefs(refs, getPageBlockCommentRefs(options, index))
113+
114+
case "Progress":
115+
refs = envoyx.MergeRefs(refs, getPageBlockProgressRefs(options, index))
135116
}
136117

137118
return
138119
}
139120

140-
func getPageBlockRecordListRefs(b types.PageBlock, index int) (refs map[string]envoyx.Ref) {
121+
func getPageBlockRecordListRefs(options map[string]interface{}, index int) (refs map[string]envoyx.Ref) {
141122
refs = make(map[string]envoyx.Ref)
142123

143-
id := optString(b.Options, "module", "moduleID")
124+
id := optString(options, "module", "moduleID")
144125
if id == "" || id == "0" {
145126
return
146127
}
@@ -153,10 +134,10 @@ func getPageBlockRecordListRefs(b types.PageBlock, index int) (refs map[string]e
153134
return
154135
}
155136

156-
func getPageBlockChartRefs(b types.PageBlock, index int) (refs map[string]envoyx.Ref) {
137+
func getPageBlockChartRefs(options map[string]interface{}, index int) (refs map[string]envoyx.Ref) {
157138
refs = make(map[string]envoyx.Ref)
158139

159-
id := optString(b.Options, "chart", "chartID")
140+
id := optString(options, "chart", "chartID")
160141
if id == "" || id == "0" {
161142
return
162143
}
@@ -169,10 +150,10 @@ func getPageBlockChartRefs(b types.PageBlock, index int) (refs map[string]envoyx
169150
return
170151
}
171152

172-
func getPageBlockCalendarRefs(b types.PageBlock, index int) (refs map[string]envoyx.Ref) {
153+
func getPageBlockCalendarRefs(options map[string]interface{}, index int) (refs map[string]envoyx.Ref) {
173154
refs = make(map[string]envoyx.Ref)
174155

175-
ff, _ := b.Options["feeds"].([]interface{})
156+
ff, _ := options["feeds"].([]interface{})
176157
for j, f := range ff {
177158
feed, _ := f.(map[string]interface{})
178159
opt, _ := (feed["options"]).(map[string]interface{})
@@ -191,10 +172,10 @@ func getPageBlockCalendarRefs(b types.PageBlock, index int) (refs map[string]env
191172
return
192173
}
193174

194-
func getPageBlockMetricRefs(b types.PageBlock, index int) (refs map[string]envoyx.Ref) {
175+
func getPageBlockMetricRefs(options map[string]interface{}, index int) (refs map[string]envoyx.Ref) {
195176
refs = make(map[string]envoyx.Ref)
196177

197-
mm, _ := b.Options["metrics"].([]interface{})
178+
mm, _ := options["metrics"].([]interface{})
198179
for j, m := range mm {
199180
mops, _ := m.(map[string]interface{})
200181

@@ -212,26 +193,26 @@ func getPageBlockMetricRefs(b types.PageBlock, index int) (refs map[string]envoy
212193
return
213194
}
214195

215-
func getPageBlockCommentRefs(b types.PageBlock, index int) (refs map[string]envoyx.Ref) {
196+
func getPageBlockCommentRefs(options map[string]interface{}, index int) (refs map[string]envoyx.Ref) {
216197
// Same difference
217-
return getPageBlockRecordListRefs(b, index)
198+
return getPageBlockRecordListRefs(options, index)
218199
}
219200

220-
func getPageBlockProgressRefs(b types.PageBlock, index int) (refs map[string]envoyx.Ref) {
201+
func getPageBlockProgressRefs(options map[string]interface{}, index int) (refs map[string]envoyx.Ref) {
221202
refs = make(map[string]envoyx.Ref)
222203
var aux *envoyx.Ref
223204

224-
aux = getPageBlockProgressValueRefs(b.Options["minValue"])
205+
aux = getPageBlockProgressValueRefs(options["minValue"])
225206
if aux != nil {
226207
refs[fmt.Sprintf("Blocks.%d.Options.minValue.ModuleID", index)] = *aux
227208
}
228209

229-
aux = getPageBlockProgressValueRefs(b.Options["maxValue"])
210+
aux = getPageBlockProgressValueRefs(options["maxValue"])
230211
if aux != nil {
231212
refs[fmt.Sprintf("Blocks.%d.Options.maxValue.ModuleID", index)] = *aux
232213
}
233214

234-
aux = getPageBlockProgressValueRefs(b.Options["value"])
215+
aux = getPageBlockProgressValueRefs(options["value"])
235216
if aux != nil {
236217
refs[fmt.Sprintf("Blocks.%d.Options.value.ModuleID", index)] = *aux
237218
}
@@ -260,15 +241,15 @@ func getPageBlockProgressValueRefs(val any) (ref *envoyx.Ref) {
260241
}
261242
}
262243

263-
func getPageBlockRecordOrganizerRefs(b types.PageBlock, index int) (refs map[string]envoyx.Ref) {
244+
func getPageBlockRecordOrganizerRefs(options map[string]interface{}, index int) (refs map[string]envoyx.Ref) {
264245
// Same difference
265-
return getPageBlockRecordListRefs(b, index)
246+
return getPageBlockRecordListRefs(options, index)
266247
}
267248

268-
func getPageBlockAutomationRefs(b types.PageBlock, index int) (refs map[string]envoyx.Ref) {
249+
func getPageBlockAutomationRefs(options map[string]interface{}, index int) (refs map[string]envoyx.Ref) {
269250
refs = make(map[string]envoyx.Ref)
270251

271-
bb, _ := b.Options["buttons"].([]interface{})
252+
bb, _ := options["buttons"].([]interface{})
272253
for buttonIx, b := range bb {
273254
button, _ := b.(map[string]interface{})
274255
id := optString(button, "workflow", "workflowID")

0 commit comments

Comments
 (0)