Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
078d08d0
Unverified
Commit
078d08d0
authored
May 06, 2020
by
Emil Tullstedt
Committed by
GitHub
May 06, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Search: Support multiple order filters (#24230)
parent
9b7bbc3d
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
52 additions
and
14 deletions
+52
-14
pkg/services/search/service.go
+4
-3
pkg/services/search/sorting.go
+11
-3
pkg/services/sqlstore/dashboard.go
+2
-5
pkg/services/sqlstore/dashboard_test.go
+31
-0
pkg/services/sqlstore/searchstore/builder.go
+4
-3
No files found.
pkg/services/search/service.go
View file @
078d08d0
...
@@ -3,7 +3,6 @@ package search
...
@@ -3,7 +3,6 @@ package search
import
(
import
(
"sort"
"sort"
"github.com/grafana/grafana/pkg/services/sqlstore/searchstore"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/bus"
...
@@ -49,7 +48,7 @@ type FindPersistedDashboardsQuery struct {
...
@@ -49,7 +48,7 @@ type FindPersistedDashboardsQuery struct {
Page
int64
Page
int64
Permission
models
.
PermissionType
Permission
models
.
PermissionType
SortBy
searchstore
.
FilterOrderBy
Filters
[]
interface
{}
Result
HitList
Result
HitList
}
}
...
@@ -86,7 +85,9 @@ func (s *SearchService) searchHandler(query *Query) error {
...
@@ -86,7 +85,9 @@ func (s *SearchService) searchHandler(query *Query) error {
}
}
if
sortOpt
,
exists
:=
s
.
sortOptions
[
query
.
Sort
];
exists
{
if
sortOpt
,
exists
:=
s
.
sortOptions
[
query
.
Sort
];
exists
{
dashboardQuery
.
SortBy
=
sortOpt
.
Filter
for
_
,
filter
:=
range
sortOpt
.
Filter
{
dashboardQuery
.
Filters
=
append
(
dashboardQuery
.
Filters
,
filter
)
}
}
}
if
err
:=
bus
.
Dispatch
(
&
dashboardQuery
);
err
!=
nil
{
if
err
:=
bus
.
Dispatch
(
&
dashboardQuery
);
err
!=
nil
{
...
...
pkg/services/search/sorting.go
View file @
078d08d0
...
@@ -11,13 +11,17 @@ var (
...
@@ -11,13 +11,17 @@ var (
Name
:
"alpha-asc"
,
Name
:
"alpha-asc"
,
DisplayName
:
"Alphabetically (A-Z)"
,
DisplayName
:
"Alphabetically (A-Z)"
,
Description
:
"Sort results in an alphabetically ascending order"
,
Description
:
"Sort results in an alphabetically ascending order"
,
Filter
:
searchstore
.
TitleSorter
{},
Filter
:
[]
SortOptionFilter
{
searchstore
.
TitleSorter
{},
},
}
}
sortAlphaDesc
=
SortOption
{
sortAlphaDesc
=
SortOption
{
Name
:
"alpha-desc"
,
Name
:
"alpha-desc"
,
DisplayName
:
"Alphabetically (Z-A)"
,
DisplayName
:
"Alphabetically (Z-A)"
,
Description
:
"Sort results in an alphabetically descending order"
,
Description
:
"Sort results in an alphabetically descending order"
,
Filter
:
searchstore
.
TitleSorter
{
Descending
:
true
},
Filter
:
[]
SortOptionFilter
{
searchstore
.
TitleSorter
{
Descending
:
true
},
},
}
}
)
)
...
@@ -25,7 +29,11 @@ type SortOption struct {
...
@@ -25,7 +29,11 @@ type SortOption struct {
Name
string
Name
string
DisplayName
string
DisplayName
string
Description
string
Description
string
Filter
searchstore
.
FilterOrderBy
Filter
[]
SortOptionFilter
}
type
SortOptionFilter
interface
{
searchstore
.
FilterOrderBy
}
}
// RegisterSortOption allows for hooking in more search options from
// RegisterSortOption allows for hooking in more search options from
...
...
pkg/services/sqlstore/dashboard.go
View file @
078d08d0
...
@@ -216,12 +216,7 @@ type DashboardSearchProjection struct {
...
@@ -216,12 +216,7 @@ type DashboardSearchProjection struct {
}
}
func
findDashboards
(
query
*
search
.
FindPersistedDashboardsQuery
)
([]
DashboardSearchProjection
,
error
)
{
func
findDashboards
(
query
*
search
.
FindPersistedDashboardsQuery
)
([]
DashboardSearchProjection
,
error
)
{
if
query
.
SortBy
==
nil
{
query
.
SortBy
=
searchstore
.
TitleSorter
{}
}
filters
:=
[]
interface
{}{
filters
:=
[]
interface
{}{
query
.
SortBy
,
permissions
.
DashboardPermissionFilter
{
permissions
.
DashboardPermissionFilter
{
OrgRole
:
query
.
SignedInUser
.
OrgRole
,
OrgRole
:
query
.
SignedInUser
.
OrgRole
,
OrgId
:
query
.
SignedInUser
.
OrgId
,
OrgId
:
query
.
SignedInUser
.
OrgId
,
...
@@ -231,6 +226,8 @@ func findDashboards(query *search.FindPersistedDashboardsQuery) ([]DashboardSear
...
@@ -231,6 +226,8 @@ func findDashboards(query *search.FindPersistedDashboardsQuery) ([]DashboardSear
},
},
}
}
filters
=
append
(
filters
,
query
.
Filters
...
)
if
query
.
OrgId
!=
0
{
if
query
.
OrgId
!=
0
{
filters
=
append
(
filters
,
searchstore
.
OrgFilter
{
OrgId
:
query
.
OrgId
})
filters
=
append
(
filters
,
searchstore
.
OrgFilter
{
OrgId
:
query
.
OrgId
})
}
else
if
query
.
SignedInUser
.
OrgId
!=
0
{
}
else
if
query
.
SignedInUser
.
OrgId
!=
0
{
...
...
pkg/services/sqlstore/dashboard_test.go
View file @
078d08d0
...
@@ -9,9 +9,13 @@ import (
...
@@ -9,9 +9,13 @@ import (
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/search"
"github.com/grafana/grafana/pkg/services/search"
"github.com/grafana/grafana/pkg/services/sqlstore/searchstore"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/util"
"github.com/grafana/grafana/pkg/util"
.
"github.com/smartystreets/goconvey/convey"
.
"github.com/smartystreets/goconvey/convey"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
)
func
TestDashboardDataAccess
(
t
*
testing
.
T
)
{
func
TestDashboardDataAccess
(
t
*
testing
.
T
)
{
...
@@ -401,6 +405,33 @@ func TestDashboardDataAccess(t *testing.T) {
...
@@ -401,6 +405,33 @@ func TestDashboardDataAccess(t *testing.T) {
})
})
}
}
func
TestDashboard_SortingOptions
(
t
*
testing
.
T
)
{
// insertTestDashboard uses GoConvey's assertions. Workaround.
Convey
(
"test with multiple sorting options"
,
t
,
func
()
{
InitTestDB
(
t
)
dashB
:=
insertTestDashboard
(
"Beta"
,
1
,
0
,
false
)
dashA
:=
insertTestDashboard
(
"Alfa"
,
1
,
0
,
false
)
assert
.
NotZero
(
t
,
dashA
.
Id
)
assert
.
Less
(
t
,
dashB
.
Id
,
dashA
.
Id
)
q
:=
&
search
.
FindPersistedDashboardsQuery
{
SignedInUser
:
&
models
.
SignedInUser
{
OrgId
:
1
,
UserId
:
1
,
OrgRole
:
models
.
ROLE_ADMIN
},
// adding two sorting options (silly no-op example, but it'll complicate the query)
Filters
:
[]
interface
{}{
searchstore
.
TitleSorter
{},
searchstore
.
TitleSorter
{
Descending
:
true
},
},
}
dashboards
,
err
:=
findDashboards
(
q
)
require
.
NoError
(
t
,
err
)
require
.
Len
(
t
,
dashboards
,
2
)
assert
.
Equal
(
t
,
dashA
.
Id
,
dashboards
[
0
]
.
Id
)
assert
.
Equal
(
t
,
dashB
.
Id
,
dashboards
[
1
]
.
Id
)
})
}
func
insertTestDashboard
(
title
string
,
orgId
int64
,
folderId
int64
,
isFolder
bool
,
tags
...
interface
{})
*
models
.
Dashboard
{
func
insertTestDashboard
(
title
string
,
orgId
int64
,
folderId
int64
,
isFolder
bool
,
tags
...
interface
{})
*
models
.
Dashboard
{
cmd
:=
models
.
SaveDashboardCommand
{
cmd
:=
models
.
SaveDashboardCommand
{
OrgId
:
orgId
,
OrgId
:
orgId
,
...
...
pkg/services/sqlstore/searchstore/builder.go
View file @
078d08d0
...
@@ -113,13 +113,14 @@ func (b *Builder) applyFilters() (ordering string) {
...
@@ -113,13 +113,14 @@ func (b *Builder) applyFilters() (ordering string) {
b
.
params
=
append
(
b
.
params
,
groupParams
...
)
b
.
params
=
append
(
b
.
params
,
groupParams
...
)
}
}
if
len
(
orders
)
>
0
{
if
len
(
orders
)
<
1
{
orders
=
append
(
orders
,
TitleSorter
{}
.
OrderBy
())
}
orderBy
:=
fmt
.
Sprintf
(
" ORDER BY %s"
,
strings
.
Join
(
orders
,
", "
))
orderBy
:=
fmt
.
Sprintf
(
" ORDER BY %s"
,
strings
.
Join
(
orders
,
", "
))
b
.
sql
.
WriteString
(
orderBy
)
b
.
sql
.
WriteString
(
orderBy
)
order
:=
strings
.
Join
(
orderJoins
,
""
)
order
:=
strings
.
Join
(
orderJoins
,
""
)
order
+=
orderBy
order
+=
orderBy
return
order
return
order
}
return
" ORDER BY dashboard.id"
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment