mirror of
https://github.com/grafana/grafana.git
synced 2025-02-11 16:15:42 -06:00
Previews: return an empty array, rather than a null, if a dashboard has no datasources (#52961)
This commit is contained in:
parent
d0aa688e36
commit
273c37c27d
@ -60,7 +60,7 @@ func getDatasourceUIDs(resp *backend.DataResponse, uid string) ([]string, error)
|
||||
}
|
||||
|
||||
func filterOutGrafanaDs(uids []string) []string {
|
||||
var filtered []string
|
||||
filtered := make([]string, 0)
|
||||
for _, uid := range uids {
|
||||
if uid != grafanads.DatasourceUID {
|
||||
filtered = append(filtered, uid)
|
||||
|
@ -18,6 +18,11 @@ var (
|
||||
exampleListFrameJSON string
|
||||
exampleListFrame = &data.Frame{}
|
||||
_ = exampleListFrame.UnmarshalJSON([]byte(exampleListFrameJSON))
|
||||
|
||||
//go:embed testdata/empty_search_response_frame.json
|
||||
listFrameJSONWithNoDatasources string
|
||||
listFrameWithNoDatasources = &data.Frame{}
|
||||
_ = listFrameWithNoDatasources.UnmarshalJSON([]byte(listFrameJSONWithNoDatasources))
|
||||
)
|
||||
|
||||
func TestShouldParseUidFromSearchResponseFrame(t *testing.T) {
|
||||
@ -41,6 +46,28 @@ func TestShouldParseUidFromSearchResponseFrame(t *testing.T) {
|
||||
require.Equal(t, []string{"datasource-2", "datasource-3", "datasource-4"}, uids)
|
||||
}
|
||||
|
||||
func TestShouldReturnEmptyArrayIfThereAreNoDatasources(t *testing.T) {
|
||||
searchService := &searchV2.MockSearchService{}
|
||||
dsLookup := &dsUidsLookup{
|
||||
searchService: searchService,
|
||||
crawlerAuth: &crawlerAuth{},
|
||||
features: featuremgmt.WithFeatures(featuremgmt.FlagPanelTitleSearch),
|
||||
}
|
||||
|
||||
dashboardUid := "abc"
|
||||
searchService.On("IsDisabled").Return(false)
|
||||
searchService.On("DoDashboardQuery", mock.Anything, mock.Anything, mock.Anything, searchV2.DashboardQuery{
|
||||
UIDs: []string{dashboardUid},
|
||||
}).Return(&backend.DataResponse{
|
||||
Frames: []*data.Frame{listFrameWithNoDatasources},
|
||||
})
|
||||
|
||||
uids, err := dsLookup.getDatasourceUidsForDashboard(context.Background(), dashboardUid, 1)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, []string{}, uids)
|
||||
require.NotNil(t, uids)
|
||||
}
|
||||
|
||||
func TestShouldReturnNullIfSearchServiceIsDisabled(t *testing.T) {
|
||||
searchService := &searchV2.MockSearchService{}
|
||||
dsLookup := &dsUidsLookup{
|
||||
|
120
pkg/services/thumbs/testdata/empty_search_response_frame.json
vendored
Normal file
120
pkg/services/thumbs/testdata/empty_search_response_frame.json
vendored
Normal file
@ -0,0 +1,120 @@
|
||||
{
|
||||
"schema": {
|
||||
"name": "Query results",
|
||||
"refId": "Search",
|
||||
"meta": {
|
||||
"type": "search-results",
|
||||
"custom": {
|
||||
"count": 106,
|
||||
"locationInfo": {
|
||||
"yboVMzb7z": {
|
||||
"name": "gdev dashboards",
|
||||
"kind": "folder",
|
||||
"url": "/dashboards/f/yboVMzb7z/gdev-dashboards"
|
||||
}
|
||||
},
|
||||
"sortBy": "name_sort"
|
||||
}
|
||||
},
|
||||
"fields": [
|
||||
{
|
||||
"name": "kind",
|
||||
"type": "string",
|
||||
"typeInfo": {
|
||||
"frame": "string"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "uid",
|
||||
"type": "string",
|
||||
"typeInfo": {
|
||||
"frame": "string"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "name",
|
||||
"type": "string",
|
||||
"typeInfo": {
|
||||
"frame": "string"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "panel_type",
|
||||
"type": "string",
|
||||
"typeInfo": {
|
||||
"frame": "string"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "url",
|
||||
"type": "string",
|
||||
"typeInfo": {
|
||||
"frame": "string"
|
||||
},
|
||||
"config": {
|
||||
"links": [
|
||||
{
|
||||
"title": "link",
|
||||
"url": "${__value.text}"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "tags",
|
||||
"type": "other",
|
||||
"typeInfo": {
|
||||
"frame": "json.RawMessage",
|
||||
"nullable": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "ds_uid",
|
||||
"type": "other",
|
||||
"typeInfo": {
|
||||
"frame": "json.RawMessage",
|
||||
"nullable": false
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "location",
|
||||
"type": "string",
|
||||
"typeInfo": {
|
||||
"frame": "string"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"data": {
|
||||
"values": [
|
||||
[
|
||||
"dashboard"
|
||||
],
|
||||
[
|
||||
"ujaM1h6nz"
|
||||
],
|
||||
[
|
||||
"abc2"
|
||||
],
|
||||
[
|
||||
""
|
||||
],
|
||||
[
|
||||
"/dashboards/f/ujaM1h6nz/abc2"
|
||||
],
|
||||
[
|
||||
[
|
||||
"gdev"
|
||||
]
|
||||
],
|
||||
[
|
||||
[
|
||||
"grafana"
|
||||
]
|
||||
],
|
||||
[
|
||||
""
|
||||
]
|
||||
]
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user