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
2acfbdb7
Unverified
Commit
2acfbdb7
authored
Jan 28, 2020
by
Hugo Häggmark
Committed by
GitHub
Jan 28, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Annotations: Fixes this.templateSrv.replace is not a function error for Grafana datasource (#21778)
parent
be09722d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
14 deletions
+21
-14
public/app/plugins/datasource/grafana/datasource.ts
+13
-5
public/app/plugins/datasource/grafana/specs/datasource.test.ts
+8
-9
No files found.
public/app/plugins/datasource/grafana/datasource.ts
View file @
2acfbdb7
import
_
from
'lodash'
;
import
_
from
'lodash'
;
import
{
TemplateSrv
}
from
'app/features/templating/template_srv'
;
import
{
getBackendSrv
}
from
'@grafana/runtime'
;
import
{
getBackendSrv
}
from
'@grafana/runtime'
;
import
{
DataSourceApi
,
DataSourceInstanceSettings
}
from
'@grafana/data'
;
class
GrafanaDatasource
{
import
templateSrv
from
'app/features/templating/template_srv'
;
class
GrafanaDatasource
extends
DataSourceApi
<
any
>
{
/** @ngInject */
/** @ngInject */
constructor
(
private
templateSrv
:
TemplateSrv
)
{}
constructor
(
instanceSettings
:
DataSourceInstanceSettings
)
{
super
(
instanceSettings
);
}
query
(
options
:
any
)
{
query
(
options
:
any
)
{
return
getBackendSrv
()
return
getBackendSrv
()
...
@@ -33,7 +37,7 @@ class GrafanaDatasource {
...
@@ -33,7 +37,7 @@ class GrafanaDatasource {
}
}
metricFindQuery
(
options
:
any
)
{
metricFindQuery
(
options
:
any
)
{
return
Promise
.
resolve
(
{
data
:
[]
}
);
return
Promise
.
resolve
(
[]
);
}
}
annotationQuery
(
options
:
any
)
{
annotationQuery
(
options
:
any
)
{
...
@@ -62,7 +66,7 @@ class GrafanaDatasource {
...
@@ -62,7 +66,7 @@ class GrafanaDatasource {
const
delimiter
=
'__delimiter__'
;
const
delimiter
=
'__delimiter__'
;
const
tags
=
[];
const
tags
=
[];
for
(
const
t
of
params
.
tags
)
{
for
(
const
t
of
params
.
tags
)
{
const
renderedValues
=
t
his
.
t
emplateSrv
.
replace
(
t
,
{},
(
value
:
any
)
=>
{
const
renderedValues
=
templateSrv
.
replace
(
t
,
{},
(
value
:
any
)
=>
{
if
(
typeof
value
===
'string'
)
{
if
(
typeof
value
===
'string'
)
{
return
value
;
return
value
;
}
}
...
@@ -78,6 +82,10 @@ class GrafanaDatasource {
...
@@ -78,6 +82,10 @@ class GrafanaDatasource {
return
getBackendSrv
().
get
(
'/api/annotations'
,
params
);
return
getBackendSrv
().
get
(
'/api/annotations'
,
params
);
}
}
testDatasource
()
{
return
Promise
.
resolve
();
}
}
}
export
{
GrafanaDatasource
};
export
{
GrafanaDatasource
};
public/app/plugins/datasource/grafana/specs/datasource.test.ts
View file @
2acfbdb7
import
{
dateTime
}
from
'@grafana/data'
;
import
{
DataSourceInstanceSettings
,
dateTime
}
from
'@grafana/data'
;
import
{
backendSrv
}
from
'app/core/services/backend_srv'
;
// will use the version in __mocks__
import
{
backendSrv
}
from
'app/core/services/backend_srv'
;
// will use the version in __mocks__
import
{
GrafanaDatasource
}
from
'../datasource'
;
import
{
GrafanaDatasource
}
from
'../datasource'
;
...
@@ -7,6 +7,12 @@ jest.mock('@grafana/runtime', () => ({
...
@@ -7,6 +7,12 @@ jest.mock('@grafana/runtime', () => ({
getBackendSrv
:
()
=>
backendSrv
,
getBackendSrv
:
()
=>
backendSrv
,
}));
}));
jest
.
mock
(
'app/features/templating/template_srv'
,
()
=>
({
replace
:
(
val
:
string
)
=>
{
return
val
.
replace
(
'$var2'
,
'replaced__delimiter__replaced2'
).
replace
(
'$var'
,
'replaced'
);
},
}));
describe
(
'grafana data source'
,
()
=>
{
describe
(
'grafana data source'
,
()
=>
{
const
getMock
=
jest
.
spyOn
(
backendSrv
,
'get'
);
const
getMock
=
jest
.
spyOn
(
backendSrv
,
'get'
);
...
@@ -16,7 +22,6 @@ describe('grafana data source', () => {
...
@@ -16,7 +22,6 @@ describe('grafana data source', () => {
describe
(
'when executing an annotations query'
,
()
=>
{
describe
(
'when executing an annotations query'
,
()
=>
{
let
calledBackendSrvParams
:
any
;
let
calledBackendSrvParams
:
any
;
let
templateSrvStub
:
any
;
let
ds
:
GrafanaDatasource
;
let
ds
:
GrafanaDatasource
;
beforeEach
(()
=>
{
beforeEach
(()
=>
{
getMock
.
mockImplementation
((
url
:
string
,
options
:
any
)
=>
{
getMock
.
mockImplementation
((
url
:
string
,
options
:
any
)
=>
{
...
@@ -24,13 +29,7 @@ describe('grafana data source', () => {
...
@@ -24,13 +29,7 @@ describe('grafana data source', () => {
return
Promise
.
resolve
([]);
return
Promise
.
resolve
([]);
});
});
templateSrvStub
=
{
ds
=
new
GrafanaDatasource
({}
as
DataSourceInstanceSettings
);
replace
:
(
val
:
string
)
=>
{
return
val
.
replace
(
'$var2'
,
'replaced__delimiter__replaced2'
).
replace
(
'$var'
,
'replaced'
);
},
};
ds
=
new
GrafanaDatasource
(
templateSrvStub
as
any
);
});
});
describe
(
'with tags that have template variables'
,
()
=>
{
describe
(
'with tags that have template variables'
,
()
=>
{
...
...
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