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
8aa55ee3
Commit
8aa55ee3
authored
Jan 25, 2018
by
Daniel Lee
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
variables: fix when datasource returns error
parent
eb2d4b20
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
8 deletions
+46
-8
public/app/features/templating/editor_ctrl.ts
+6
-8
public/app/features/templating/specs/editor_ctrl.jest.ts
+40
-0
No files found.
public/app/features/templating/editor_ctrl.ts
View file @
8aa55ee3
import
_
from
'lodash'
;
import
coreModule
from
'app/core/core_module'
;
import
{
variableTypes
}
from
'./variable'
;
import
appEvents
from
'app/core/app_events'
;
export
class
VariableEditorCtrl
{
/** @ngInject **/
...
...
@@ -56,16 +57,13 @@ export class VariableEditorCtrl {
}
if
(
!
$scope
.
current
.
name
.
match
(
/^
\w
+$/
))
{
$scope
.
appEvent
(
'alert-warning'
,
[
'Validation'
,
'Only word and digit characters are allowed in variable names'
,
]);
appEvents
.
emit
(
'alert-warning'
,
[
'Validation'
,
'Only word and digit characters are allowed in variable names'
]);
return
false
;
}
var
sameName
=
_
.
find
(
$scope
.
variables
,
{
name
:
$scope
.
current
.
name
});
if
(
sameName
&&
sameName
!==
$scope
.
current
)
{
$scope
.
appEven
t
(
'alert-warning'
,
[
'Validation'
,
'Variable with the same name already exists'
]);
appEvents
.
emi
t
(
'alert-warning'
,
[
'Validation'
,
'Variable with the same name already exists'
]);
return
false
;
}
...
...
@@ -73,7 +71,7 @@ export class VariableEditorCtrl {
$scope
.
current
.
type
===
'query'
&&
$scope
.
current
.
query
.
match
(
new
RegExp
(
'
\\
$'
+
$scope
.
current
.
name
+
'(/| |$)'
))
)
{
$scope
.
appEven
t
(
'alert-warning'
,
[
appEvents
.
emi
t
(
'alert-warning'
,
[
'Validation'
,
'Query cannot contain a reference to itself. Variable: $'
+
$scope
.
current
.
name
,
]);
...
...
@@ -96,11 +94,11 @@ export class VariableEditorCtrl {
};
$scope
.
runQuery
=
function
()
{
return
variableSrv
.
updateOptions
(
$scope
.
current
).
then
(
null
,
function
(
err
)
{
return
variableSrv
.
updateOptions
(
$scope
.
current
).
catch
(
err
=>
{
if
(
err
.
data
&&
err
.
data
.
message
)
{
err
.
message
=
err
.
data
.
message
;
}
$scope
.
appEven
t
(
'alert-error'
,
[
'Templating'
,
'Template variables could not be initialized: '
+
err
.
message
]);
appEvents
.
emi
t
(
'alert-error'
,
[
'Templating'
,
'Template variables could not be initialized: '
+
err
.
message
]);
});
};
...
...
public/app/features/templating/specs/editor_ctrl.jest.ts
0 → 100644
View file @
8aa55ee3
import
{
VariableEditorCtrl
}
from
'../editor_ctrl'
;
let
mockEmit
;
jest
.
mock
(
'app/core/app_events'
,
()
=>
{
mockEmit
=
jest
.
fn
();
return
{
emit
:
mockEmit
,
};
});
describe
(
'VariableEditorCtrl'
,
()
=>
{
let
scope
=
{
runQuery
:
()
=>
{
return
Promise
.
resolve
({});
},
};
describe
(
'When running a variable query and the data source returns an error'
,
()
=>
{
beforeEach
(()
=>
{
const
variableSrv
=
{
updateOptions
:
()
=>
{
return
Promise
.
reject
({
data
:
{
message
:
'error'
},
});
},
};
const
ctrl
=
new
VariableEditorCtrl
(
scope
,
{},
variableSrv
,
{});
});
it
(
'should emit an error'
,
()
=>
{
return
scope
.
runQuery
().
then
(
res
=>
{
expect
(
mockEmit
).
toBeCalled
();
expect
(
mockEmit
.
mock
.
calls
[
0
][
0
]).
toBe
(
'alert-error'
);
expect
(
mockEmit
.
mock
.
calls
[
0
][
1
][
0
]).
toBe
(
'Templating'
);
expect
(
mockEmit
.
mock
.
calls
[
0
][
1
][
1
]).
toBe
(
'Template variables could not be initialized: error'
);
});
});
});
});
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