-
Notifications
You must be signed in to change notification settings - Fork 73
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
Events v2: Implement optimistic file upload and FILE type input #8246
Conversation
Oops! Looks like you forgot to update the changelog. When updating CHANGELOG.md, please consider the following:
|
Fixed some types as requested |
const FIELD_SEPARATOR = '____' | ||
function unflatten<T>(data: Record<string, T>) { | ||
return Object.fromEntries( | ||
Object.entries(data).map(([key, value]) => [ | ||
key.replaceAll('.', FIELD_SEPARATOR), | ||
value | ||
]) | ||
) | ||
} | ||
|
||
function flatten<T>(data: Record<string, T>) { | ||
return Object.fromEntries( | ||
Object.entries(data).map(([key, value]) => [ | ||
key.replaceAll(FIELD_SEPARATOR, '.'), | ||
value | ||
]) | ||
) | ||
} |
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.
Let's document this very carefully why we do this, it's so annoying :(
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.
Yup :D
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.
Some stylistic comments. Will continue soon!
allowedDocType={allowedDocType} | ||
description={description} | ||
error={''} | ||
file={file ? file : undefined} |
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 understand that null is easier for browser default, could we have either undefined
or null
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.
👍 Good point. I changed the default now to be undefined. Was first changing it to null but remembered I wanted to keep "null" as an explicit empty value in the form field generator and undefined more a "this field is not defined (yet)", so went with undefined here as well
description={description} | ||
error={''} | ||
file={file ? file : undefined} | ||
label={file ? file.originalFilename : ''} |
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.
Could we generate a label or make it optional, passing empty strings along the line will contain surprises in the end
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.
Changed this to just be undefined or a real label
uploadFiles(newFile) | ||
} else { | ||
setFile(null) | ||
onChange(undefined) |
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.
might be a matter of taste, but could be left out
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.
setFile
needs to want the value to be explicitly set 🤔 Maybe best to have both the same way so explicit?
requiredErrorMessage, | ||
touched | ||
}: IFullProps) { | ||
const [error, setError] = useState('') |
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.
We could just use undefined value
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.
Yea, this was some og code brought back from the core side. Don't want to touch it quite yet
return <></> | ||
} | ||
|
||
return <>{value.toString() || ''}</> |
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.
will the fallback ever trigger?
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.
Yea probably doesn't anymore 👍
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.
Looks good!
…ore into events-v2-file-input
opencrvs/opencrvs-countryconfig#348