Skip to content

Commit aa1a945

Browse files
feature: Sorts response frames by name
1 parent 6017c40 commit aa1a945

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

pkg/plugin/datasource.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"encoding/json"
66
"fmt"
7+
"sort"
78
"strconv"
89
"strings"
910
"sync"
@@ -238,19 +239,25 @@ func (datasource *Datasource) query(ctx context.Context, pCtx backend.PluginCont
238239
}
239240
}
240241

242+
// Creates a response from the input grids. The frames in the result are sorted by display name.
241243
func responseFromGrids(grids []haystack.Grid) backend.DataResponse {
242-
var response backend.DataResponse
244+
frames := data.Frames{}
243245
for _, grid := range grids {
244246
frame, frameErr := dataFrameFromGrid(grid)
245247
if frameErr != nil {
246248
log.DefaultLogger.Error(frameErr.Error())
247249
return backend.ErrDataResponse(backend.StatusBadRequest, fmt.Sprintf("Frame conversion failure: %v", frameErr.Error()))
248250
}
249-
250-
// add the frames to the response.
251-
response.Frames = append(response.Frames, frame)
252-
response.Status = backend.StatusOK
251+
frames = append(frames, frame)
253252
}
253+
254+
sort.Slice(frames, func(i, j int) bool {
255+
return frames[i].Name < frames[j].Name
256+
})
257+
258+
var response backend.DataResponse
259+
response.Frames = frames
260+
response.Status = backend.StatusOK
254261
return response
255262
}
256263

0 commit comments

Comments
 (0)