fix(09): WR-07 keep relation column order from the YAML itself, not a fixed indentation

This commit is contained in:
Jakub Zych
2026-10-01 21:10:09 +02:00
parent 889250c8fb
commit b026aec162
3 changed files with 80 additions and 22 deletions

View File

@@ -7,7 +7,6 @@ import (
"fmt"
"io/fs"
"reflect"
"sort"
"strings"
"git.golem15.com/golem15/summercms/modules/lagoon"
@@ -212,7 +211,7 @@ func compileRelations(pluginID string, ctl pact.AdminController, fsys fs.FS, for
return nil, bootErr(pluginID, ctl.ID(), file, err)
}
var root yaml.MapSlice
if err := decodeStrict(raw, &root); err != nil {
if err := decodeStrictOrdered(raw, &root); err != nil {
return nil, bootErr(pluginID, ctl.ID(), file, err)
}
out := map[string]*CompiledRelation{}
@@ -247,8 +246,6 @@ func compileRelations(pluginID string, ctl pact.AdminController, fsys fs.FS, for
if err != nil {
return nil, bootErr(pluginID, ctl.ID(), file, fmt.Errorf("relation %s manage: %w", name, err))
}
orderRelationColumns(raw, &view)
orderRelationColumns(raw, &manage)
schema := &RelationSchema{Name: name, Label: doc.Label, View: view, Manage: manage}
if doc.Messages != nil {
schema.messageKeys = *doc.Messages
@@ -274,24 +271,6 @@ func compileRelations(pluginID string, ctl pact.AdminController, fsys fs.FS, for
return out, nil
}
func orderRelationColumns(raw []byte, panel *RelationPanel) {
if panel == nil || len(panel.List.Columns) < 2 {
return
}
source := string(raw)
sort.SliceStable(panel.List.Columns, func(i, j int) bool {
left := strings.Index(source, "\n "+panel.List.Columns[i].Key+":")
right := strings.Index(source, "\n "+panel.List.Columns[j].Key+":")
if left < 0 {
left = len(source)
}
if right < 0 {
right = len(source)
}
return left < right
})
}
func compileRelationPanel(doc relationPanelDocument, contract RelationContract, view bool) (RelationPanel, error) {
cols := make([]RelationColumn, 0, len(doc.List.Columns))
seen := map[string]struct{}{}