Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
X
xpub-faraday
Manage
Activity
Members
Labels
Plan
Issues
2
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Container Registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
xpub
xpub-faraday
Commits
6df41016
Commit
6df41016
authored
6 years ago
by
Alexandru Munteanu
Browse files
Options
Downloads
Patches
Plain Diff
feat(adminUserForm): add validate array to each field and fix wasteful rerenders
parent
c52341fa
No related branches found
Branches containing commit
No related tags found
Tags containing commit
3 merge requests
!233
S26 updates
,
!230
S26 Updates
,
!223
Admin formik
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
packages/component-faraday-ui/src/ValidatedFormField.js
+20
-5
20 additions, 5 deletions
packages/component-faraday-ui/src/ValidatedFormField.js
packages/component-user/app/components/AdminUserForm.js
+6
-6
6 additions, 6 deletions
packages/component-user/app/components/AdminUserForm.js
with
26 additions
and
11 deletions
packages/component-faraday-ui/src/ValidatedFormField.js
+
20
−
5
View file @
6df41016
...
@@ -4,7 +4,13 @@ import { Field } from 'formik'
...
@@ -4,7 +4,13 @@ import { Field } from 'formik'
import
PropTypes
from
'
prop-types
'
import
PropTypes
from
'
prop-types
'
import
styled
from
'
styled-components
'
import
styled
from
'
styled-components
'
import
{
th
}
from
'
@pubsweet/ui-toolkit
'
import
{
th
}
from
'
@pubsweet/ui-toolkit
'
import
{
compose
,
withHandlers
,
withProps
}
from
'
recompose
'
import
{
compose
,
withProps
,
withHandlers
,
shouldUpdate
,
setDisplayName
,
}
from
'
recompose
'
const
WrappedComponent
=
compose
(
const
WrappedComponent
=
compose
(
withHandlers
({
withHandlers
({
...
@@ -23,6 +29,11 @@ const WrappedComponent = compose(
...
@@ -23,6 +29,11 @@ const WrappedComponent = compose(
error
:
hasError
&&
get
(
errors
,
name
),
error
:
hasError
&&
get
(
errors
,
name
),
validationStatus
:
hasError
?
'
error
'
:
'
default
'
,
validationStatus
:
hasError
?
'
error
'
:
'
default
'
,
})),
})),
shouldUpdate
(
(
prev
,
next
)
=>
get
(
prev
,
'
field.value
'
)
!==
get
(
next
,
'
field.value
'
)
||
get
(
prev
,
'
error
'
)
!==
get
(
next
,
'
error
'
),
),
)(
)(
({
({
error
,
error
,
...
@@ -70,10 +81,14 @@ ValidatedFormField.propTypes = {
...
@@ -70,10 +81,14 @@ ValidatedFormField.propTypes = {
]).
isRequired
,
]).
isRequired
,
}
}
export
default
withProps
(({
validate
})
=>
({
export
default
compose
(
validateFn
:
value
=>
setDisplayName
(
'
ValidatedFormikField
'
),
validate
.
filter
(
fn
=>
fn
(
value
)).
reduce
((
acc
,
fn
)
=>
fn
(
value
),
''
),
withProps
(({
validate
=
[]
})
=>
({
}))(
ValidatedFormField
)
validateFn
:
(
value
=
''
)
=>
validate
.
reduce
((
acc
,
fn
)
=>
acc
||
fn
(
value
),
''
),
})),
shouldUpdate
(()
=>
false
),
)(
ValidatedFormField
)
// #region styles
// #region styles
const
MessageWrapper
=
styled
.
div
`
const
MessageWrapper
=
styled
.
div
`
...
...
This diff is collapsed.
Click to expand it.
packages/component-user/app/components/AdminUserForm.js
+
6
−
6
View file @
6df41016
...
@@ -11,13 +11,14 @@ import {
...
@@ -11,13 +11,14 @@ import {
Text
,
Text
,
Label
,
Label
,
IconButton
,
IconButton
,
MenuCountry
,
RowOverrideAlert
,
RowOverrideAlert
,
ItemOverrideAlert
,
ItemOverrideAlert
,
ValidatedFormField
,
ValidatedFormField
,
withRoles
,
withRoles
,
withFetching
,
withFetching
,
withCountries
,
withCountries
,
MenuCountry
,
validators
,
}
from
'
pubsweet-component-faraday-ui
'
}
from
'
pubsweet-component-faraday-ui
'
// #region helpers
// #region helpers
...
@@ -87,7 +88,7 @@ const FormModal = ({
...
@@ -87,7 +88,7 @@ const FormModal = ({
component
=
{
TextField
}
component
=
{
TextField
}
inline
inline
name
=
"
email
"
name
=
"
email
"
validate
=
{[
min3
,
max6
]}
validate
=
{[
validators
.
emailValidator
]}
/
>
/
>
<
/ItemOverrideAlert
>
<
/ItemOverrideAlert
>
...
@@ -195,10 +196,9 @@ export default compose(
...
@@ -195,10 +196,9 @@ export default compose(
})),
})),
withHandlers
({
withHandlers
({
onSubmit
:
({
onSubmit
,
...
props
})
=>
(
values
,
formProps
)
=>
{
onSubmit
:
({
onSubmit
,
...
props
})
=>
(
values
,
formProps
)
=>
{
console
.
log
(
'
the values
'
,
values
)
if
(
typeof
onSubmit
===
'
function
'
)
{
// if (typeof onSubmit === 'function') {
onSubmit
(
values
,
{
...
formProps
,
...
props
})
// onSubmit(values, { ...formProps, ...props })
}
// }
},
},
onClose
:
({
onCancel
,
...
props
})
=>
()
=>
{
onClose
:
({
onCancel
,
...
props
})
=>
()
=>
{
if
(
typeof
onCancel
===
'
function
'
)
{
if
(
typeof
onCancel
===
'
function
'
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment