Skip to content

Commit

Permalink
issue-11296 - WIP - AddSortingToSelect
Browse files Browse the repository at this point in the history
Signed-off-by: Helber Belmiro <helber.belmiro@gmail.com>
  • Loading branch information
hbelmiro committed Dec 16, 2024
1 parent bbb83ad commit 332cc47
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions backend/src/apiserver/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,7 @@ func (o *Options) AddSortingToSelect(sqlBuilder sq.SelectBuilder) sq.SelectBuild
// When sorting by a direct field in the listable model (i.e., name in Run or uuid in Pipeline), a sortByFieldPrefix can be specified; when sorting by a field in an array-typed dictionary (i.e., a run metric inside the metrics in Run), a sortByFieldPrefix is not needed.
// If next row's value is specified, set those values in the clause.
if o.SortByFieldValue != nil && o.KeyFieldValue != nil {
order := "ASC"
if o.IsDesc {
order = "DESC"
sqlBuilder = sqlBuilder.
Where(sq.Or{
sq.Lt{o.SortByFieldPrefix + o.SortByFieldName: o.SortByFieldValue},
Expand All @@ -219,11 +217,16 @@ func (o *Options) AddSortingToSelect(sqlBuilder sq.SelectBuilder) sq.SelectBuild
},
})
}
sqlBuilder = sqlBuilder.
OrderBy(fmt.Sprintf("%v %v", o.SortByFieldPrefix+o.SortByFieldName, order)).
OrderBy(fmt.Sprintf("%v %v", o.KeyFieldPrefix+o.KeyFieldName, order))
}

order := "ASC"
if o.IsDesc {
order = "DESC"
}
sqlBuilder = sqlBuilder.
OrderBy(fmt.Sprintf("%v %v", o.SortByFieldPrefix+o.SortByFieldName, order)).
OrderBy(fmt.Sprintf("%v %v", o.KeyFieldPrefix+o.KeyFieldName, order))

return sqlBuilder
}

Expand Down

0 comments on commit 332cc47

Please sign in to comment.