-
Notifications
You must be signed in to change notification settings - Fork 78
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
LF-4158: Create animal creation details cards for animal #3192
LF-4158: Create animal creation details cards for animal #3192
Conversation
594690f
to
93df228
Compare
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 looks GREAT!! (And huge!)
I left some minor comments but the only two vaguely important ones were:
- The field named USED_FOR_PRODUCTION -- I think that one was meant to be USED_FOR_REPRODUCTION throughout
- Whether writing for react-hook-form's
<FormProvider />
to start with might be a better idea. That would clean up the prop drilling offormMethods
and also future-proof for using MultiStepForm once that PR is merged
packages/webapp/src/components/Animals/AddAnimalsDetails/styles.module.scss
Outdated
Show resolved
Hide resolved
packages/webapp/src/components/Animals/AddAnimalsDetails/type.ts
Outdated
Show resolved
Hide resolved
packages/webapp/src/stories/Animals/Details/AnimalDetails.stories.tsx
Outdated
Show resolved
Hide resolved
]; | ||
|
||
export const sexOptions = [ | ||
{ value: 0, label: `I don't know` }, |
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 not a question for this PR, but regarding my backend ticket... 'I don't know' is just a frontend implementation of null
, right? We don't have to add a key in the animal_sexes
table for it?
Edit: I should also say, I prefer it to be merely a frontend implementation of 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.
Thank you for bringing this up!
I didn't think we would need to add a key in the table, but I started feeling we should differentiate "undefined" and "unknown"! If we didn't have the key, "sex" would be "I don't know" in the read-only view when the user didn't select anything.
Do you agree with adding unknown
to animal_sex
table?
Oh you edited your comment 😂
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 we didn't have the key, "sex" would be "I don't know" in the read-only view when the user didn't select anything.
@SayakaOno yes, I think I prefer this!!
I think I also just saw something similar in another place on the AddAnimal flow -- maybe an "I don't know" breed? -- and I could have sworn we scrapped the idea of an UNKNOWN
breed key at one point in discussion 😅 At least for sure they didn't make it into the tables.
Let's revisit after soil amendment!
@SayakaOno I don't think the |
@navDhammu! |
{previewUrl ? ( | ||
<div className={styles.imageContainer}> | ||
{previewUrl === defaultUrl ? ( | ||
<MediaWithAuthentication fileUrls={[defaultUrl]} alt="image thumbnail" /> |
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.
This can probably be removed along with previewUrl === defaultUrl
. The parent component can use the useMediaWithAuthentication
hook to fetch the private image url and pass it as defaultUrl
to ImagePicker
.
component: ImagePicker, | ||
decorators: [ | ||
...componentDecorators, | ||
(Story) => { |
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.
Do we really need this decorator? The behavior isn't dependant on react hook form and it works without it.
type Story = StoryObj<typeof ImagePicker>; | ||
|
||
export const Default: Story = { | ||
render: (args, context) => { |
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.
Is it possible to just use args for these stories instead of the render method?
@navDhammu Thank you so much for your input, the component and stories look much better now. |
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.
This looks good! Although I didn't review all the files but the stories are working well. I left some minor comments to possibly clean up the stories a bit.
Note:- I created components for animal type and breed selects in (#3201) that could be used here maybe once that is approved. This is the file containing the inputs
|
||
export const Animal: Story = { | ||
args: { | ||
...commonProps, |
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 not necessary to spread the common props in each story - you can just put them in the global meta object and they will be applied to every story
import * as commonProps from './mockData
const meta: Meta<GeneralDetailsProps> = {
args: commonProps
// other code
}
...commonProps, | ||
animalOrBatch: AnimalOrBatchKeys.BATCH, | ||
}, | ||
render: (args, context) => <GeneralDetails {...args} {...context} />, |
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 think these render functions on stories can be removed if you have one render in the meta object, and then also the decorator can be removed. Like:
const meta: Meta<GeneralDetailsProps> = {
title: 'Components/AddAnimalsDetails/General',
component: GeneralDetails,
render: (args) => {
const { t } = useTranslation();
const formMethods = useForm({ mode: 'onBlur' });
const sex = formMethods.watch(DetailsFields.SEX);
const isMaleSelected = sex === 1;
return (
<FormProvider {...formMethods}>
<GeneralDetails {...args} t={t} isMaleSelected={isMaleSelected} />
</FormProvider>
);
},
args: commonProps,
decorators: componentDecorators,
// avoid "Maximum update depth exceeded" https://github.com/storybookjs/storybook/issues/12306
parameters: { docs: { source: { type: 'code' } } },
};
Something else I noticed while using the stories - the Expandable component doesn't expand if you click on it - you have to click on the chevron down icon. Is that the expected behaviour? Normally as a user I would expect that it expands anywhere I click on it, and also that I can open it with just the keyboard by tabbing and pressing enter. |
@navDhammu Thank you for the comments! |
Description
Create a pure component for animal details view. This is such a huge PR... I would scan the code briefly and check stories if components look okay. Thank you for reviewing!
Input
component to validate input when the field is cleared.ImagePicker
component and story. (it hasMediaWithAuthentication
container, so I made it a container, but does it mean a component that usesImagePicker
needs to be a container?)It is almost a copy of FarmImagePicker.tsx, but the major difference is a removal of
isImageRemoved
. Whether to show a preview depends on the existence ofpreviewUrl
, and unlesspreviewUrl
is updated, the preview is shown withMediaWithAuthentication
.@navDhammu It would be appreciated if you could take a look at this component! 🙏
AddAnimalsDetails
component that holds the four details cards.NOTE:
I had to pass
t
to the four detail cards because doinguseTranslation([...])
(especially with more than two namespaces) in mui'sCollapse
causedMaximum update depth exceeded
error.Jira link: https://lite-farm.atlassian.net/browse/LF-4158, a little bit of https://lite-farm.atlassian.net/browse/LF-4159
Type of change
How Has This Been Tested?
Checklist: