New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"Create Product" page #2037
"Create Product" page #2037
Conversation
b426c57
to
01da96f
Compare
if (error) { | ||
if (Object.prototype.hasOwnProperty.call(error, 'validationErrors')) { | ||
const { validationErrors } = (error as unknown as ValidationException) | ||
const newValidations: Validations = {} | ||
Object.keys(validationErrors).forEach((id) => { | ||
newValidations[id] = { | ||
validation: 'error', | ||
errors: validationErrors[id] | ||
} | ||
}) | ||
setValidations({ ...validations, ...newValidations }) | ||
} else { | ||
addAlert({ id: String(Date.now()), title: error.message, variant: 'danger' }) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So validationErrors
are not provided in the data
object, but within error
and not always. We might want to leverage this inside the http module. Then, would be easy to check that if error
is true, data will be validationErrors
. Since the parsing of this can't be done without modifying useAsync
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, error can be anything, including a validation error we're gonna need to check for it either way. Consider as if Object.prototype.hasOwnProperty.call(error, 'validationErrors')
were typeof error === 'ValidationException'
...
There's no way to work around this. It's either check the error for validationErrors
or the data, but I think it belongs to error.
01da96f
to
5e06f20
Compare
5e06f20
to
d4463d0
Compare
53285d2
to
11e4b7d
Compare
46c1cee
to
7e1e999
Compare
3eebbdb
to
f26c4f2
Compare
import { ValidationException, Validator } from 'utils' | ||
|
||
type Validations = Record<string, { | ||
validation: 'default' | 'success' | 'error', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we can simplify the API with something like:
validation: 'default' | 'success' | 'error', | |
validation?: boolean, |
thus, if undefined
means is not yet validated, and the boolean will define if it was success or error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's given by PF I'm afraid https://www.patternfly.org/v4/documentation/react/components/textinput#props
(minus warning because apparently we don't want to use it)
const validator = Validator() | ||
.for('name', () => (name.length > 0 ? 'success' : 'error')) | ||
// eslint-disable-next-line no-nested-ternary | ||
.for('system_name', () => (!systemName ? 'default' : (systemName.length > 0 ? 'success' : 'error'))) | ||
.for('description', () => (description.length > 0 ? 'success' : 'default')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it more than the switch case version, good!
I was thinking that maybe we can pass the Validator
factory a validation rules object like:
const validator = Validator() | |
.for('name', () => (name.length > 0 ? 'success' : 'error')) | |
// eslint-disable-next-line no-nested-ternary | |
.for('system_name', () => (!systemName ? 'default' : (systemName.length > 0 ? 'success' : 'error'))) | |
.for('description', () => (description.length > 0 ? 'success' : 'default')) | |
const validator = Validator({ | |
name: () => (name.length > 0 ? 'success' : 'error'), | |
'system_name': () => (!systemName ? 'default' : (systemName.length > 0 ? 'success' : 'error')), | |
description: () => (description.length > 0 ? 'success' : 'default')) | |
}) |
then in the implementation you could assert the case with Object.prototype.hasOwnProperty
and execute the fn
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But isn't that how it works already? Only with a sugar coating on top of it https://github.com/3scale/porta/pull/2037/files#diff-9d8e17e1d9797344cd149b6d58dc6377
What this PR does / why we need it:
Adds a page component for Products > New.
Which issue(s) this PR fixes
THREESCALE-5636: Component for "Create product" page
Verification steps
Go to
/products/new
products/:id
)