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
a187500c
Unverified
Commit
a187500c
authored
Dec 12, 2019
by
Hugo Häggmark
Committed by
GitHub
Dec 12, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prometheus: Prevents validation of inputs when clicking in them without changing the value (#21059)
Fixes #21056
parent
e69ec6ca
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
17 deletions
+66
-17
public/app/plugins/datasource/prometheus/configuration/PromSettings.test.tsx
+55
-1
public/app/plugins/datasource/prometheus/configuration/PromSettings.tsx
+11
-16
No files found.
public/app/plugins/datasource/prometheus/configuration/PromSettings.test.tsx
View file @
a187500c
import
{
getValueFromEventItem
}
from
'./PromSettings'
;
import
{
getValueFromEventItem
,
promSettingsValidationEvents
}
from
'./PromSettings'
;
import
{
EventsWithValidation
}
from
'@grafana/ui'
;
describe
(
'PromSettings'
,
()
=>
{
describe
(
'PromSettings'
,
()
=>
{
describe
(
'getValueFromEventItem'
,
()
=>
{
describe
(
'getValueFromEventItem'
,
()
=>
{
...
@@ -25,4 +26,57 @@ describe('PromSettings', () => {
...
@@ -25,4 +26,57 @@ describe('PromSettings', () => {
});
});
});
});
});
});
describe
(
'promSettingsValidationEvents'
,
()
=>
{
const
validationEvents
=
promSettingsValidationEvents
;
it
(
'should have one event handlers'
,
()
=>
{
expect
(
Object
.
keys
(
validationEvents
).
length
).
toEqual
(
1
);
});
it
(
'should have an onBlur handler'
,
()
=>
{
expect
(
validationEvents
.
hasOwnProperty
(
EventsWithValidation
.
onBlur
)).
toBe
(
true
);
});
it
(
'should have one rule'
,
()
=>
{
expect
(
validationEvents
[
EventsWithValidation
.
onBlur
].
length
).
toEqual
(
1
);
});
describe
(
'when calling the rule with an empty string'
,
()
=>
{
it
(
'then it should return true'
,
()
=>
{
expect
(
validationEvents
[
EventsWithValidation
.
onBlur
][
0
].
rule
(
''
)).
toBe
(
true
);
});
});
it
.
each
`
value | expected
${
'1ms'
}
|
${
true
}
${
'1M'
}
|
${
true
}
${
'1w'
}
|
${
true
}
${
'1d'
}
|
${
true
}
${
'1h'
}
|
${
true
}
${
'1m'
}
|
${
true
}
${
'1s'
}
|
${
true
}
${
'1y'
}
|
${
true
}
`
(
"when calling the rule with correct formatted value: '$value' then result should be '$expected'"
,
({
value
,
expected
})
=>
{
expect
(
validationEvents
[
EventsWithValidation
.
onBlur
][
0
].
rule
(
value
)).
toBe
(
expected
);
}
);
it
.
each
`
value | expected
${
'1 ms'
}
|
${
false
}
${
'1x'
}
|
${
false
}
${
' '
}
|
${
false
}
${
'w'
}
|
${
false
}
${
'1.0s'
}
|
${
false
}
`
(
"when calling the rule with incorrect formatted value: '$value' then result should be '$expected'"
,
({
value
,
expected
})
=>
{
expect
(
validationEvents
[
EventsWithValidation
.
onBlur
][
0
].
rule
(
value
)).
toBe
(
expected
);
}
);
});
});
});
public/app/plugins/datasource/prometheus/configuration/PromSettings.tsx
View file @
a187500c
...
@@ -31,14 +31,7 @@ export const PromSettings = (props: Props) => {
...
@@ -31,14 +31,7 @@ export const PromSettings = (props: Props) => {
value=
{
value
.
jsonData
.
timeInterval
}
value=
{
value
.
jsonData
.
timeInterval
}
spellCheck=
{
false
}
spellCheck=
{
false
}
onChange=
{
onChangeHandler
(
'timeInterval'
,
value
,
onChange
)
}
onChange=
{
onChangeHandler
(
'timeInterval'
,
value
,
onChange
)
}
validationEvents=
{
{
validationEvents=
{
promSettingsValidationEvents
}
[
EventsWithValidation
.
onBlur
]:
[
regexValidation
(
/^
\d
+
(
ms|
[
Mwdhmsy
])
$/
,
'Value is not valid, you can use number with time unit specifier: y, M, w, d, h, m, s'
),
],
}
}
/>
/>
}
}
tooltip=
"Set this to your global scrape interval defined in your Prometheus config file. This will be used as a lower limit for the
tooltip=
"Set this to your global scrape interval defined in your Prometheus config file. This will be used as a lower limit for the
...
@@ -58,14 +51,7 @@ export const PromSettings = (props: Props) => {
...
@@ -58,14 +51,7 @@ export const PromSettings = (props: Props) => {
onChange=
{
onChangeHandler
(
'queryTimeout'
,
value
,
onChange
)
}
onChange=
{
onChangeHandler
(
'queryTimeout'
,
value
,
onChange
)
}
spellCheck=
{
false
}
spellCheck=
{
false
}
placeholder=
"60s"
placeholder=
"60s"
validationEvents=
{
{
validationEvents=
{
promSettingsValidationEvents
}
[
EventsWithValidation
.
onBlur
]:
[
regexValidation
(
/^
\d
+
(
ms|
[
Mwdhmsy
])
$/
,
'Value is not valid, you can use number with time unit specifier: y, M, w, d, h, m, s'
),
],
}
}
/>
/>
}
}
tooltip=
"Set the Prometheus query timeout."
tooltip=
"Set the Prometheus query timeout."
...
@@ -112,6 +98,15 @@ export const PromSettings = (props: Props) => {
...
@@ -112,6 +98,15 @@ export const PromSettings = (props: Props) => {
);
);
};
};
export
const
promSettingsValidationEvents
=
{
[
EventsWithValidation
.
onBlur
]:
[
regexValidation
(
/^$|^
\d
+
(
ms|
[
Mwdhmsy
])
$/
,
'Value is not valid, you can use number with time unit specifier: y, M, w, d, h, m, s'
),
],
};
export
const
getValueFromEventItem
=
(
eventItem
:
SyntheticEvent
<
HTMLInputElement
>
|
SelectableValue
<
string
>
)
=>
{
export
const
getValueFromEventItem
=
(
eventItem
:
SyntheticEvent
<
HTMLInputElement
>
|
SelectableValue
<
string
>
)
=>
{
if
(
!
eventItem
)
{
if
(
!
eventItem
)
{
return
''
;
return
''
;
...
...
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