-
Notifications
You must be signed in to change notification settings - Fork 93
LF-4980: Show valid soil amendment products #3899
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
Merged
Duncan-Brain
merged 27 commits into
integration
from
LF-4980/Show_valid_soil_amendment_products
Oct 24, 2025
Merged
Changes from 22 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
8b9b61c
LF-4980 Add filteredProductsSelector
SayakaOno fae28cd
LF-4980 Replace products selector for inventory
SayakaOno 7985513
LF-4980 Add isLibraryProduct function
SayakaOno 1497067
LF-4980 Use isLibraryProduct in products selector
SayakaOno 4b7b938
LF-4980 Adjust products for SoilAmdnementProductForm read-only
SayakaOno f597a1b
LF-4980 Adjust new product name validation
SayakaOno 70e9d7c
LF-4980 Adjust products selector for task creation
SayakaOno fb48e8d
LF-4980 Reset product form values when mounting SoilAmendmentProductCard
SayakaOno dcd6947
LF-4980 Add translation string
SayakaOno 0bcaadc
LF-4980 Update Product type
SayakaOno f8158c3
LF-4980 Adjust productOptions generation in SoilAmendmentProductCard
SayakaOno 8568d8f
LF-4980 Fix productOptions generation logic
SayakaOno 731f927
LF-4980 Fix products selector factory and memoize selectors
SayakaOno b46644c
LF-4980 Tweaks
SayakaOno efc6632
LF-4980 Add missing includeLibrary default value in makeFilteredProdu…
SayakaOno 02147f7
LF-4980 Update ProductForm's productsSelectorArgs
SayakaOno aa6e712
LF-4980 Improve makeFilteredProductsSelector
SayakaOno cacdef4
LF-4980 Fix productsSelectorArgs in TaskDetails
SayakaOno a390fbd
LF-4980 Add comment
SayakaOno 87c7cfd
LF-4980 Add ProductInventorySelector and use it in ProductInventory
SayakaOno d63722f
LF-4980 Replace makeFilteredProductsSelector with global selector
SayakaOno 6eda9e6
LF-4980 Update productsForTaskTypeSelector from factory to global sel…
SayakaOno 0ab2718
Merge branch 'integration' into LF-4980/Show_valid_soil_amendment_pro…
SayakaOno abc5e21
LF-4980 Filter products in PureSoilAmendmentTask
SayakaOno 3a692e6
LF-4980 Update hasAvailableProductsSelector to use productInventorySe…
SayakaOno 4945585
LF-4980 Remove products filter in TaskDetails
SayakaOno 845a2bd
LF-4980 Simplify customProductNames in PureSoilAmendmentProductForm
SayakaOno File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,13 @@ import { hookFormMaxCharsValidation } from '../../../Form/hookformValidationUtil | |
| import { soilAmendmentProductDetailsDefaultValues } from '../../../../containers/ProductInventory/ProductForm/constants'; | ||
| import { getSoilAmendmentFormValues } from '../../../Form/ProductDetails/utils'; | ||
|
|
||
| const findProduct = ( | ||
Duncan-Brain marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| products?: SoilAmendmentProduct[], | ||
| productId?: SoilAmendmentProduct['product_id'], | ||
| ) => { | ||
| return products?.find(({ product_id }) => product_id === productId); | ||
| }; | ||
|
|
||
| export type ProductCardProps = ProductDetailsProps & { | ||
| namePrefix: string; | ||
| system: 'metric' | 'imperial'; | ||
|
|
@@ -126,9 +133,17 @@ const SoilAmendmentProductCard = ({ | |
| const productId = getValues(PRODUCT_ID); | ||
| const purposes = watch(PURPOSES); | ||
|
|
||
| const initialProductId = useRef(productId); | ||
|
||
|
|
||
| const selectRef = useRef<SelectRef>(null); | ||
| const productOptions = products.map(({ product_id, name, ...rest }) => { | ||
| return { value: product_id, label: name, data: rest }; | ||
| const productOptions = products.flatMap(({ product_id, name, ...rest }) => { | ||
Duncan-Brain marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (rest.removed && product_id !== initialProductId.current) { | ||
| return []; | ||
| } | ||
|
|
||
| const label = name + (rest.removed ? ` (${t('common:REMOVED')})` : ''); | ||
|
|
||
| return { value: product_id, label, data: rest }; | ||
| }); | ||
|
|
||
| useEffect(() => { | ||
|
|
@@ -137,6 +152,11 @@ const SoilAmendmentProductCard = ({ | |
| } | ||
| }, [otherPurposeId]); | ||
|
|
||
| useEffect(() => { | ||
| const selectedProduct = findProduct(products, productId); | ||
| nestedFormMethods.reset(getSoilAmendmentFormValues(selectedProduct)); | ||
| }, []); | ||
|
|
||
| return ( | ||
| <div className={styles.productCard}> | ||
| {!isReadOnly && onRemove && ( | ||
|
|
@@ -154,7 +174,7 @@ const SoilAmendmentProductCard = ({ | |
| options={productOptions} | ||
| onChange={(e) => { | ||
| onChange(e?.value); | ||
| const selectedProduct = products.find(({ product_id }) => product_id === e?.value); | ||
| const selectedProduct = findProduct(products, e?.value); | ||
| nestedFormMethods.reset(getSoilAmendmentFormValues(selectedProduct)); | ||
| }} | ||
| placeholder={t('ADD_PRODUCT.PRESS_ENTER')} | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| /* | ||
| * Copyright 2025 LiteFarm.org | ||
| * This file is part of LiteFarm. | ||
| * | ||
| * LiteFarm is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * LiteFarm is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details, see <https://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| import { Product } from '../store/api/types'; | ||
|
|
||
| // LF-4963 - confirm property that will distinguish custom from library products | ||
| export const isLibraryProduct = (product: Product) => { | ||
| return !!product.product_translation_key; | ||
| }; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
libraryProductsOutsideInventoryis it defined somewhere? I imagine that a user could duplicate a library product multiple times to tweak values. Is this in preparation for showing a library without the already duplicated library products?Also is there a chance this will be reused and should this be a createSelector?
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 don't think users would be able to duplicate a library product directly. They would first add it to the inventory, then duplicate it.
I expect
libraryProductsOutsideInventoryto be used as the options to add to the inventory:I can’t think of a use case where we’d want to reuse it right now... can 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.
Maybe I am wrong but I think what I expect is that we always show
allLibraryProductsinstead of removing already addedlibraryProductsOutsideInventory.How I understood library products was that the user can checkout their own copy and make edits to it as they choose? Adding a library product multiple times makes sense if the user is allowed to edit the values of the local copy. Maybe I misunderstood how library products work. At least currently, a library product is editable and so if I wanted the original unedited values I could not find it in
libraryProductsOutsideInventoryif it is removed.Reuse: Maybe I was wishful thinking but I thought that this function looked generic enough for pest control and cleaning products too. Hopefully we don't have multiple product architecture for a long time!
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 haven’t handled library products yet, but eventually we’ll need to prevent them from being modified!
I removed
libraryProductsOutsideInventoryfor now since it's hard to envision without the actual UI/UX. I could have created a function to generatecustomProductNames, but I'm leaving that for later too!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.
Oh we might need to align on that! I thought for sure the library products ARE modifiable .. as a copy of the core library product. Anyways thanks for removing for now as we discuss!