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
31948867
Unverified
Commit
31948867
authored
Jul 06, 2018
by
Marcus Efraimsson
Committed by
GitHub
Jul 06, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #12521 from grafana/davkal/fix-datasource-sort
Fix datasource sorting with template variables
parents
f2980bb9
7ddcaf22
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
15 deletions
+32
-15
public/app/features/plugins/datasource_srv.ts
+4
-2
public/app/features/plugins/specs/datasource_srv.jest.ts
+28
-13
No files found.
public/app/features/plugins/datasource_srv.ts
View file @
31948867
...
...
@@ -142,10 +142,12 @@ export class DatasourceSrv {
var
ds
=
config
.
datasources
[
first
];
if
(
ds
)
{
const
key
=
`$
${
variable
.
name
}
`
;
list
.
push
({
name
:
'$'
+
variable
.
name
,
value
:
'$'
+
variable
.
name
,
name
:
key
,
value
:
key
,
meta
:
ds
.
meta
,
sort
:
key
,
});
}
}
...
...
public/app/features/plugins/specs/datasource_srv.jest.ts
View file @
31948867
...
...
@@ -2,8 +2,21 @@ import config from 'app/core/config';
import
'app/features/plugins/datasource_srv'
;
import
{
DatasourceSrv
}
from
'app/features/plugins/datasource_srv'
;
// Datasource variable $datasource with current value 'BBB'
const
templateSrv
=
{
variables
:
[
{
type
:
'datasource'
,
name
:
'datasource'
,
current
:
{
value
:
'BBB'
,
},
},
],
};
describe
(
'datasource_srv'
,
function
()
{
let
_datasourceSrv
=
new
DatasourceSrv
({},
{},
{},
{}
);
let
_datasourceSrv
=
new
DatasourceSrv
({},
{},
{},
templateSrv
);
let
metricSources
;
describe
(
'when loading metric sources'
,
()
=>
{
...
...
@@ -35,25 +48,27 @@ describe('datasource_srv', function() {
};
beforeEach
(()
=>
{
config
.
datasources
=
unsortedDatasources
;
metricSources
=
_datasourceSrv
.
getMetricSources
({
skipVariables
:
true
});
metricSources
=
_datasourceSrv
.
getMetricSources
({});
config
.
defaultDatasource
=
'BBB'
;
});
it
(
'should return a list of sources sorted case insensitively with builtin sources last'
,
()
=>
{
expect
(
metricSources
[
0
].
name
).
toBe
(
'aaa'
);
expect
(
metricSources
[
1
].
name
).
toBe
(
'BBB'
);
expect
(
metricSources
[
2
].
name
).
toBe
(
'mmm'
);
expect
(
metricSources
[
3
].
name
).
toBe
(
'ZZZ'
);
expect
(
metricSources
[
4
].
name
).
toBe
(
'--Grafana--'
);
expect
(
metricSources
[
5
].
name
).
toBe
(
'--Mixed--'
);
expect
(
metricSources
[
1
].
name
).
toBe
(
'aaa'
);
expect
(
metricSources
[
2
].
name
).
toBe
(
'BBB'
);
expect
(
metricSources
[
3
].
name
).
toBe
(
'mmm'
);
expect
(
metricSources
[
4
].
name
).
toBe
(
'ZZZ'
);
expect
(
metricSources
[
5
].
name
).
toBe
(
'--Grafana--'
);
expect
(
metricSources
[
6
].
name
).
toBe
(
'--Mixed--'
);
});
beforeEach
(()
=>
{
config
.
defaultDatasource
=
'BBB'
;
it
(
'should set default data source'
,
()
=>
{
expect
(
metricSources
[
3
].
name
).
toBe
(
'default'
);
expect
(
metricSources
[
3
].
sort
).
toBe
(
'BBB'
);
});
it
(
'should set default
data source
'
,
()
=>
{
expect
(
metricSources
[
2
].
name
).
toBe
(
'default
'
);
expect
(
metricSources
[
2
].
sort
).
toBe
(
'BBB
'
);
it
(
'should set default
inject the variable datasources
'
,
()
=>
{
expect
(
metricSources
[
0
].
name
).
toBe
(
'$datasource
'
);
expect
(
metricSources
[
0
].
sort
).
toBe
(
'$datasource
'
);
});
});
});
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