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
c722ea4f
Commit
c722ea4f
authored
Nov 30, 2018
by
Johannes Schill
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
react-panel: Input validation should be optional
parent
6cbbffff
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
12 deletions
+19
-12
public/app/core/components/Form/Input.tsx
+13
-11
public/app/core/utils/validate.ts
+6
-1
No files found.
public/app/core/components/Form/Input.tsx
View file @
c722ea4f
import
React
,
{
PureComponent
}
from
'react'
;
import
{
ValidationEvents
,
ValidationRule
}
from
'app/types'
;
import
{
validate
}
from
'app/core/utils/validate'
;
import
{
validate
,
hasValidationEvent
}
from
'app/core/utils/validate'
;
export
enum
InputStatus
{
Invalid
=
'invalid'
,
...
...
@@ -21,7 +21,7 @@ export enum EventsWithValidation {
}
interface
Props
extends
React
.
HTMLProps
<
HTMLInputElement
>
{
validationEvents
:
ValidationEvents
;
validationEvents
?
:
ValidationEvents
;
hideErrorMessage
?:
boolean
;
// Override event props and append status as argument
...
...
@@ -57,15 +57,17 @@ export class Input extends PureComponent<Props> {
populateEventPropsWithStatus
=
(
restProps
,
validationEvents
:
ValidationEvents
)
=>
{
const
inputElementProps
=
{
...
restProps
};
Object
.
keys
(
EventsWithValidation
).
forEach
(
eventName
=>
{
inputElementProps
[
eventName
]
=
async
evt
=>
{
if
(
validationEvents
[
eventName
])
{
await
this
.
validatorAsync
(
validationEvents
[
eventName
]).
apply
(
this
,
[
evt
]);
}
if
(
restProps
[
eventName
])
{
restProps
[
eventName
].
apply
(
null
,
[
evt
,
this
.
status
]);
}
};
Object
.
keys
(
EventsWithValidation
).
forEach
((
eventName
:
EventsWithValidation
)
=>
{
if
(
hasValidationEvent
(
eventName
,
validationEvents
)
||
restProps
[
eventName
])
{
inputElementProps
[
eventName
]
=
async
evt
=>
{
if
(
hasValidationEvent
(
eventName
,
validationEvents
))
{
await
this
.
validatorAsync
(
validationEvents
[
eventName
]).
apply
(
this
,
[
evt
]);
}
if
(
restProps
[
eventName
])
{
restProps
[
eventName
].
apply
(
null
,
[
evt
,
this
.
status
]);
}
};
}
});
return
inputElementProps
;
};
...
...
public/app/core/utils/validate.ts
View file @
c722ea4f
import
{
ValidationRule
}
from
'app/types'
;
import
{
ValidationRule
,
ValidationEvents
}
from
'app/types'
;
import
{
EventsWithValidation
}
from
'app/core/components/Form/Input'
;
export
const
validate
=
(
value
:
string
,
validationRules
:
ValidationRule
[])
=>
{
const
errors
=
validationRules
.
reduce
((
acc
,
currRule
)
=>
{
...
...
@@ -9,3 +10,7 @@ export const validate = (value: string, validationRules: ValidationRule[]) => {
},
[]);
return
errors
.
length
>
0
?
errors
:
null
;
};
export
const
hasValidationEvent
=
(
event
:
EventsWithValidation
,
validationEvents
:
ValidationEvents
)
=>
{
return
validationEvents
&&
validationEvents
[
event
];
};
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