-
Notifications
You must be signed in to change notification settings - Fork 79
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-4384: End to end animal details #3534
Conversation
… for single step form
(fix filtered animalUseOptions)
…ack only after successful API call
8b561f3
to
b9d72e3
Compare
Sorry I haven't gotten very far yet but 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.
Left a few minor comments but this is great, thanks for catching all the little details that were missing to make the feature work!
When an animal is removed from the single animal view, the success toast reads "Successfully removed selected animals". Should we change this to "animal" singular when there's only one animal?
options={options} | ||
classes={{ button: isEditing ? styles.editingStatusButton : '' }} | ||
/> | ||
{!hideMenu && ( |
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.
NIT but I'd probably reverse the logic here and have a showMenu
prop with a default true, just because the combo of hide + negation seems a bit counter intuitive to me
) | ||
} | ||
> | ||
const renderContent = () => ( |
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.
NIT and not prescriptive, but I'm not a huge fan of render functions because they're "undercover" functional components minus reusability and ability to incorporate state. I'd make this into its own component even if it lives within this same file
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 wasn't sure about this... I created a wrapper component, thank you!
|
||
const { onConfirmRemoveAnimals, removalModalOpen, setRemovalModalOpen } = useAnimalOrBatchRemoval( | ||
[getInventoryId()], | ||
() => ({}), |
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.
Should this callback just be an optional parameter for the hook?
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 didn't feel like adding ?
all over the hook 😅 but I agree that's the right thing to do!
I’ve fixed this for now, and the refactor should tidy things up a bit!
}; | ||
|
||
const getInventoryId = () => { | ||
if (!selectedAnimal && !selectedBatch) { |
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.
Since there's a redirect to another page on the effect above if the batch or animal doesn't exist, is this check necessary?
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 I was hoping to avoid doing (selectedAnimal || selectedBatch)!
on line 175. It didn't work as expected, so I removed it!
}; | ||
|
||
const { onConfirmRemoveAnimals, removalModalOpen, setRemovalModalOpen } = useAnimalOrBatchRemoval( | ||
[getInventoryId()], |
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.
Perhaps we could modify useAnimalOrBatchRemoval
to receive the actual entity IDs and whether they're a batch or animal instead of the inventory IDs? Seems more straight forward since here we're generating the inventory ID just to pass it to the hook, and then the hook has to re-parse the actual IDs from it
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 hesitated to refactor since it would involve changes to an unrelated file, but it’s true that I wasn’t happy with the inefficiency. Let me open another PR for this!
* Update useInitialAnimalData hook - return isFetchingAnimalsOrBatches - return defaultFormValues when ready * Update SingleAnimalView - avoid redirecting to UnknownRecord during fetching animals - render form when default values are ready
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 reviewing!!
The bug Duncan found was caused by defaultValue
being set after the ReactSelect was rendered. I’ve updated it to render the form only after the default values are ready.(commit)
Regarding making the success message singular, I noticed Denis created a bug ticket for the inventory view, so I'll leave the fix for that ticket.
I plan to refactor the useAnimalOrBatchRemoval
hook in a separate PR, but this one should now be ready for re-reviews. Thank you! 🙏
Update: Here is the PR to refactor the hook
) | ||
} | ||
> | ||
const renderContent = () => ( |
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 wasn't sure about this... I created a wrapper component, thank you!
}; | ||
|
||
const getInventoryId = () => { | ||
if (!selectedAnimal && !selectedBatch) { |
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 I was hoping to avoid doing (selectedAnimal || selectedBatch)!
on line 175. It didn't work as expected, so I removed it!
}; | ||
|
||
const { onConfirmRemoveAnimals, removalModalOpen, setRemovalModalOpen } = useAnimalOrBatchRemoval( | ||
[getInventoryId()], |
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 hesitated to refactor since it would involve changes to an unrelated file, but it’s true that I wasn’t happy with the inefficiency. Let me open another PR for this!
|
||
const { onConfirmRemoveAnimals, removalModalOpen, setRemovalModalOpen } = useAnimalOrBatchRemoval( | ||
[getInventoryId()], | ||
() => ({}), |
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 didn't feel like adding ?
all over the hook 😅 but I agree that's the right thing to do!
I’ve fixed this for now, and the refactor should tidy things up a bit!
export enum OrganicStatus { | ||
'NON_ORGANIC' = 'Non-Organic', | ||
'TRANSITIONAL' = 'Transitional', | ||
'ORGANIC' = 'Organic', | ||
} | ||
|
||
// Custom RouteComponentProps with a custom history type from the 'history' library | ||
export type CustomRouteComponentProps<T extends { [K in keyof T]?: string | undefined }> = Omit< |
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!! ❤️
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.
Everything is looks great to me thanks for wrapping up! Left a couple small inline comments which aren't blockers.
Only other thing I saw not working was the upload image functionality -- not sure if that is addressable here. nvm gotta start bucket 😂
Feel free to merge!
packages/webapp/src/components/Animals/AnimalSingleViewHeader/styles.module.scss
Show resolved
Hide resolved
packages/webapp/src/containers/Animals/Inventory/useAnimalOrBatchRemoval.ts
Show resolved
Hide resolved
@@ -109,6 +117,7 @@ export const WithStepperProgressBar = ({ | |||
if (isFinalStep) { | |||
setIsSaving(true); | |||
await handleSubmit((data: FieldValues) => onSave(data, onGoForward, setFormResultData))(); | |||
reset(getValues()); |
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.
At first I was worried that this would clear the edited values when unsuccessful (api is down). But instead It kept them? Do you think this is expected?
Screen.Recording.2024-11-26.at.1.07.32.PM.mov
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.
reset()
will reset the form to the default values. However, reset(getValues())
updates the default values to the current form values before resetting, so this behaviour is expected. You can find a brief explanation in the RULES section on this page.
Thank you Duncan for thoroughly testing this, I don't think reset
, setIsSaving
and setIsEditing
shouldn't be called unless the API call is successful. Let me see if I can fix this!
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.
Interesting use of reset! and sounds good!
* handle onGoForward within the component * properly handle success actions
I made some additional changes, thank you!
|
@@ -96,7 +96,7 @@ export function AnimalBreedSelect<T extends FieldValues>({ | |||
placeholder={isTypeSelected ? undefined : t('ADD_ANIMAL.BREED_PLACEHOLDER_DISABLED')} | |||
isDisabled={!isTypeSelected || isDisabled} | |||
onChange={(option) => onChange(option)} | |||
value={value} | |||
value={value || 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.
undefined
doesn't clear the select, but null
does.
Screen.Recording.2024-11-27.at.9.53.27.AM.mov
@@ -108,10 +107,6 @@ export const ContextForm = ({ | |||
setIsEditing={setIsEditing} | |||
showCancelFlow={showCancelFlow} | |||
setShowCancelFlow={setShowCancelFlow} | |||
onSave={(...args: any) => { | |||
setActiveStepIndex(0); |
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 found this has changed behaviour of the other form (it displays the first page of the form for a second). I believe it's working without it, but if any problems are found, we will need another solution.
Screen.Recording.2024-11-27.at.9.45.35.AM.mov
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 for fixing error behaviour!
Only thing I think I see now is that for some reason the sex_detail input is not allowing enabled in edit mode unless count is changed. We could probably make a bug ticket and just merge this though!
Thank you @Duncan-Brain! I think that's one of the things Denis was mentioning yesterday, let me check with him! |
@SayakaOno I'm merging this one and we can create a separate one for the bug if that's okay! |
Description
desiredKeys
toanimalBatchController
'seditAnimalBatches
so that all fields sent to the backend are updatedgetRecordIfExists
middleware helper to exclude removed animalsWithStepperProgressBar
not to useFixedHeaderContainer
for single step forms which don't have headersSingleAnimalView
MeatballsMenu
andDropdownButton
to accept disabled propCustomRouteComponentProps
type to override the default history fromreact-router
with the history object from theHistory
libraryparseUniqueDefaultId
to handle exception (it was returningNaN
when typing a new animal type, causingfilteredUses
- the animal use options - to be undefined)AnimalSingleViewHeader
. (Counts with more than five digits are not properly handled, but if necessary, we can create a new ticket to address this)useAnimalOrBatchRemoval
to return the API resultSingleAnimalView
to handle actions based on the resultSingleAnimalView
to:FixedHeaderContainer
history.push
withhistory.back
for navigationUnknownRecord
when no animal or batch is found for the URLNOTE: I didn't implement the floating button, as it was mentioned as a nice-to-have in the Jira ticket.
Jira link: https://lite-farm.atlassian.net/browse/LF-4384
Type of change
How Has This Been Tested?
Checklist: