Search: Fix empty folder details for nested folder items (#76504)

* Introduce dashboard.folder_uid column

* Add data migration

* Search: Fix empty folder details for nested folders

* Set `dashboard.folder_uid` and update tests

* Add unique index

* lint

Ignore cyclomatic complexity of func
`(*DashboardServiceImpl).BuildSaveDashboardCommand

* Fix search by folder UID
This commit is contained in:
Sofia Papagiannaki
2023-10-24 10:04:45 +03:00
committed by GitHub
parent 442e533803
commit 03a626f1d6
28 changed files with 706 additions and 236 deletions
@@ -2,6 +2,7 @@ package dashverimpl
import (
"context"
"strconv"
"testing"
"time"
@@ -24,7 +25,7 @@ func testIntegrationGetDashboardVersion(t *testing.T, fn getStore) {
dashVerStore := fn(ss)
t.Run("Get a Dashboard ID and version ID", func(t *testing.T) {
savedDash := insertTestDashboard(t, ss, "test dash 26", 1, 0, false, "diff")
savedDash := insertTestDashboard(t, ss, "test dash 26", 1, 0, "", false, "diff")
query := dashver.GetDashboardVersionQuery{
DashboardID: savedDash.ID,
@@ -66,7 +67,7 @@ func testIntegrationGetDashboardVersion(t *testing.T, fn getStore) {
t.Run("Clean up old dashboard versions", func(t *testing.T) {
versionsToWrite := 10
for i := 0; i < versionsToWrite-1; i++ {
insertTestDashboard(t, ss, "test dash 53", 1, int64(i), false, "diff-all")
insertTestDashboard(t, ss, "test dash 53", 1, int64(i), strconv.Itoa(i), false, "diff-all")
}
versionIDsToDelete := []any{1, 2, 3, 4}
res, err := dashVerStore.DeleteBatch(
@@ -78,7 +79,7 @@ func testIntegrationGetDashboardVersion(t *testing.T, fn getStore) {
assert.EqualValues(t, 4, res)
})
savedDash := insertTestDashboard(t, ss, "test dash 43", 1, 0, false, "diff-all")
savedDash := insertTestDashboard(t, ss, "test dash 43", 1, 0, "", false, "diff-all")
t.Run("Get all versions for a given Dashboard ID", func(t *testing.T) {
query := dashver.ListDashboardVersionsQuery{
DashboardID: savedDash.ID,
@@ -134,12 +135,13 @@ var (
)
func insertTestDashboard(t *testing.T, sqlStore db.DB, title string, orgId int64,
folderId int64, isFolder bool, tags ...any) *dashboards.Dashboard {
folderId int64, folderUID string, isFolder bool, tags ...any) *dashboards.Dashboard {
t.Helper()
cmd := dashboards.SaveDashboardCommand{
OrgID: orgId,
FolderID: folderId,
IsFolder: isFolder,
OrgID: orgId,
FolderID: folderId,
FolderUID: folderUID,
IsFolder: isFolder,
Dashboard: simplejson.NewFromAny(map[string]any{
"id": nil,
"title": title,