-
Notifications
You must be signed in to change notification settings - Fork 248
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
(feat) O3-2814: Add field validation to the lab order form #1649
(feat) O3-2814: Add field validation to the lab order form #1649
Conversation
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 good work here, @usamaidrsk, thanks! Just a few things to clean up before this is ready to go.
packages/esm-patient-labs-app/src/lab-orders/add-lab-order/add-lab-order.test.tsx
Outdated
Show resolved
Hide resolved
packages/esm-patient-labs-app/src/lab-orders/add-lab-order/add-lab-order.test.tsx
Outdated
Show resolved
Hide resolved
packages/esm-patient-labs-app/src/lab-orders/add-lab-order/add-lab-order.test.tsx
Outdated
Show resolved
Hide resolved
packages/esm-patient-labs-app/src/lab-orders/add-lab-order/add-lab-order.test.tsx
Show resolved
Hide resolved
packages/esm-patient-labs-app/src/lab-orders/add-lab-order/add-lab-order.test.tsx
Outdated
Show resolved
Hide resolved
packages/esm-patient-labs-app/src/lab-orders/add-lab-order/add-lab-order.test.tsx
Outdated
Show resolved
Hide resolved
packages/esm-patient-labs-app/src/lab-orders/add-lab-order/add-lab-order.test.tsx
Outdated
Show resolved
Hide resolved
packages/esm-patient-labs-app/src/lab-orders/add-lab-order/lab-order-form.component.tsx
Outdated
Show resolved
Hide resolved
packages/esm-patient-labs-app/src/lab-orders/add-lab-order/lab-order-form.component.tsx
Show resolved
Hide resolved
labReferenceNumber: z.string({ | ||
required_error: 'Lab reference number is required', | ||
invalid_type_error: 'Lab reference number is required', | ||
}), | ||
testType: z.object( | ||
{ label: z.string(), conceptUuid: z.string() }, | ||
{ required_error: 'Test type is required', invalid_type_error: 'Test type is required' }, |
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.
AFAICT, invalid_type_error is used to specify a custom error message that will be displayed when the type of a value does not match the expected type defined in the schema. So, in this case, it will complain if the values provided in the validated fields are not strings. The error message provided should be reflective of that. Or if we're not validating type mismatches, we could remove it entirely.
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.
Hi, @denniskigen!
We should use invalid_type_error
for objects, because the error thrown by Zod in case the input is removed says "Expected object, recieved null".
@usamaidrsk, we don't need need invalid_type_error
messages for string, required_error should handle that for the strings. Please see if removing invalid_type_error
for z.object doesn't throw the error I shared above, i.e. required_error
takes care of it or not.
Thanks!
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.
Thanks @denniskigen
Here I used the same error message as of required, just because Expected string, received null
would not give clear meaning to the user on the form.
If there is a suggestion, I would like to know, then I can replace with that.
packages/esm-patient-labs-app/src/lab-orders/add-lab-order/add-lab-order.test.tsx
Outdated
Show resolved
Hide resolved
packages/esm-patient-labs-app/src/lab-orders/add-lab-order/lab-order-form.component.tsx
Outdated
Show resolved
Hide resolved
labReferenceNumber: z.string({ | ||
required_error: 'Lab reference number is required', | ||
invalid_type_error: 'Lab reference number is required', | ||
}), | ||
testType: z.object( | ||
{ label: z.string(), conceptUuid: z.string() }, | ||
{ required_error: 'Test type is required', invalid_type_error: 'Test type is required' }, |
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.
Hi, @denniskigen!
We should use invalid_type_error
for objects, because the error thrown by Zod in case the input is removed says "Expected object, recieved null".
@usamaidrsk, we don't need need invalid_type_error
messages for string, required_error should handle that for the strings. Please see if removing invalid_type_error
for z.object doesn't throw the error I shared above, i.e. required_error
takes care of it or not.
Thanks!
packages/esm-patient-labs-app/src/lab-orders/add-lab-order/lab-order-form.component.tsx
Show resolved
Hide resolved
packages/esm-patient-labs-app/src/lab-orders/add-lab-order/lab-order-form.component.tsx
Outdated
Show resolved
Hide resolved
); | ||
|
||
const cancelOrder = useCallback(() => { | ||
setOrders(orders.filter((order) => order.testType.conceptUuid !== inProgressLabOrder.testType.conceptUuid)); | ||
setOrders(orders.filter((order) => order.testType.conceptUuid !== getValues().testType.conceptUuid)); |
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.
getValues expect an arg 🤔
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.
If no arguments, it returns the entire form values. which I used here
Thanks @vasharma05
packages/esm-patient-labs-app/src/lab-orders/add-lab-order/lab-order-form.component.tsx
Outdated
Show resolved
Hide resolved
packages/esm-patient-labs-app/src/lab-orders/add-lab-order/lab-order-form.component.tsx
Outdated
Show resolved
Hide resolved
packages/esm-patient-labs-app/src/lab-orders/add-lab-order/lab-order-form.component.tsx
Show resolved
Hide resolved
packages/esm-patient-labs-app/src/lab-orders/add-lab-order/lab-order-form.component.tsx
Outdated
Show resolved
Hide resolved
packages/esm-patient-labs-app/src/lab-orders/add-lab-order/add-lab-order.test.tsx
Show resolved
Hide resolved
Just me, or does it appear as though the Removing this override should fix it, I think: :global(.cds--list-box) {
border: none;
} Thanks for being patient, it's very close! |
:global(.cds--list-box) {
border: none;
} removing this in the |
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.
Thanks, @usamaidrsk!
6861ede
to
860a17d
Compare
860a17d
to
4592b26
Compare
Requirements
Summary
This PR adds form validation to the lab orders from
Screenshots
Related Issue
O3-2814
Other