-
Notifications
You must be signed in to change notification settings - Fork 93
LF-4987: New product not visible until load more clicked #3903
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 14 commits into
integration
from
LF-4987/New_Product_Not_Visible_Until_Load_More_Clicked
Oct 22, 2025
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
4142fa0
LF-4987 Set inventory table minRows to 20
SayakaOno 494bb79
LF-4987 Hide product edit button for worker accounts
SayakaOno 16ad669
LF-4987 Remove soil amendment task product select placeholder
SayakaOno c60ed40
LF-4987 Refactor PureTaskTypeSelection
SayakaOno 753ce3d
LF-4987 Add hasAvailableProductsSelector
SayakaOno f00617a
LF-4987 Add new strings
SayakaOno 3027094
LF-4987 Add NoSoilAmendmentProductsModal
SayakaOno f4928a6
LF-4987 Add NoSoilAmendmentProductsModal to PureTaskTypeSelection
SayakaOno b001f02
LF-4987 Add closeButtonLabel prop to Drawer
SayakaOno 3fc941d
LF-4987 Add 'cancel' label to ProductForm drawer
SayakaOno 6c0f45f
LF-4987 Improve hasAvailableProductsSelector
SayakaOno 640b924
LF-4987 Update NoSoilAmendmentProductsModal texts
SayakaOno 4a4921e
LF-4987 Make Drawer's close label clickable
SayakaOno 29dbc47
LF-4987 Remove unnecessary space
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
59 changes: 59 additions & 0 deletions
59
packages/webapp/src/components/Modals/NoSoilAmendmentProductsModal/index.tsx
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,59 @@ | ||
| /* | ||
| * 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 { useTranslation } from 'react-i18next'; | ||
| import ModalComponent from '../ModalComponent/v2'; | ||
| import Button from '../../Form/Button'; | ||
|
|
||
| interface NoSoilAmendmentProductsModalProps { | ||
| dismissModal: () => void; | ||
| goToInventory: () => void; | ||
| } | ||
|
|
||
| export function NoSoilAmendmentProductsModal({ | ||
| dismissModal, | ||
| goToInventory, | ||
| }: NoSoilAmendmentProductsModalProps) { | ||
| const { t } = useTranslation(); | ||
|
|
||
| return ( | ||
| <ModalComponent | ||
| title={t('ADD_TASK.NO_SOIL_AMENDMENT_PRODUCTS')} | ||
| contents={[t('ADD_TASK.NEED_SOIL_AMENDMENT_PRODUCTS')]} | ||
| dismissModal={dismissModal} | ||
| buttonGroup={ | ||
| <> | ||
| <Button | ||
| data-cy="tasks-noSoilAmendmentProductsCancel" | ||
| onClick={dismissModal} | ||
| color={'secondary'} | ||
| type={'button'} | ||
| sm | ||
| > | ||
| {t('common:GO_BACK')} | ||
| </Button> | ||
| <Button | ||
| data-cy="tasks-noSoilAmendmentProductsContinue" | ||
| onClick={goToInventory} | ||
| type={'submit'} | ||
| sm | ||
| > | ||
| {t('ADD_TASK.GO_TO_INVENTORY')} | ||
| </Button> | ||
| </> | ||
| } | ||
| ></ModalComponent> | ||
| ); | ||
| } |
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,8 @@ import { ANIMAL_TASKS } from '../../../containers/Task/constants'; | |
| import { CantFindCustomType } from '../../Finances/PureFinanceTypeSelection/CantFindCustomType'; | ||
| import { NoAnimalLocationsModal } from '../../Modals/NoAnimalLocationsModal'; | ||
| import { NoSoilSampleLocationsModal } from '../../Modals/NoSoilSampleLocationsModal'; | ||
| import { NoSoilAmendmentProductsModal } from '../../Modals/NoSoilAmendmentProductsModal'; | ||
| import { PRODUCT_INVENTORY_URL } from '../../../util/siteMapConstants'; | ||
|
|
||
| const icons = { | ||
| SOIL_AMENDMENT_TASK: <SoilAmendment />, | ||
|
|
@@ -72,6 +74,7 @@ export const PureTaskTypeSelection = ({ | |
| hasAnimalMovementLocations, | ||
| hasAnimals, | ||
| hasSoilSampleLocations, | ||
| hasSoilAmendmentProducts, | ||
| }) => { | ||
| const { t } = useTranslation(); | ||
| const { watch, getValues, register, setValue } = useForm({ | ||
|
|
@@ -92,39 +95,32 @@ export const PureTaskTypeSelection = ({ | |
| onContinue(); | ||
| }; | ||
|
|
||
| const [showPlantTaskModal, setShowPlantTaskModal] = useState(); | ||
| const [errorModal, setErrorModal] = useState(''); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❤️ |
||
|
|
||
| const goToCatalogue = () => history.push('/crop_catalogue'); | ||
| const goToMap = () => history.push('/map'); | ||
| const goToInventory = () => history.push(PRODUCT_INVENTORY_URL); | ||
| const onPlantTaskTypeClick = () => { | ||
| if (shouldShowPlantTaskSpotLight) { | ||
| setShowPlantTaskModal(true); | ||
| setErrorModal('PLANT_TASK'); | ||
| } else { | ||
| goToCatalogue(); | ||
| } | ||
| }; | ||
| const [showNoManagementPlanModal, setShowNoManagementPlanModal] = useState(); | ||
| const onHarvestTransplantTaskClick = (task_type_id) => { | ||
| hasCurrentManagementPlans ? onSelectTask(task_type_id) : setShowNoManagementPlanModal(true); | ||
| }; | ||
|
|
||
| const [showNoAnimalLocationsModal, setShowNoAnimalLocationsModal] = useState(); | ||
| const onMovementTaskClick = (task_type_id) => { | ||
| hasAnimalMovementLocations ? onSelectTask(task_type_id) : setShowNoAnimalLocationsModal(true); | ||
| }; | ||
|
|
||
| const [showNoSoilSampleLocationsModal, setShowNoSoilSampleLocationsModal] = useState(); | ||
| const onSoilSampleTaskClick = (task_type_id) => { | ||
| hasSoilSampleLocations ? onSelectTask(task_type_id) : setShowNoSoilSampleLocationsModal(true); | ||
| }; | ||
|
|
||
| const onTileClick = (taskType) => { | ||
| if (isTaskType(taskType, 'PLANT_TASK')) return onPlantTaskTypeClick(taskType.task_type_id); | ||
| if (isTaskType(taskType, 'TRANSPLANT_TASK') || isTaskType(taskType, 'HARVEST_TASK')) { | ||
| return onHarvestTransplantTaskClick(taskType.task_type_id); | ||
| if (isTaskType(taskType, 'PLANT_TASK')) { | ||
| return onPlantTaskTypeClick(taskType.task_type_id); | ||
| } | ||
| if ( | ||
| ((isTaskType(taskType, 'TRANSPLANT_TASK') || isTaskType(taskType, 'HARVEST_TASK')) && | ||
| !hasCurrentManagementPlans) || | ||
| (isTaskType(taskType, 'MOVEMENT_TASK') && !hasAnimalMovementLocations) || | ||
| (isTaskType(taskType, 'SOIL_SAMPLE_TASK') && !hasSoilSampleLocations) || | ||
| (isTaskType(taskType, 'SOIL_AMENDMENT_TASK') && !hasSoilAmendmentProducts) | ||
| ) { | ||
| return setErrorModal(taskType.task_translation_key); | ||
| } | ||
| if (isTaskType(taskType, 'MOVEMENT_TASK')) return onMovementTaskClick(taskType.task_type_id); | ||
| if (isTaskType(taskType, 'SOIL_SAMPLE_TASK')) | ||
| return onSoilSampleTaskClick(taskType.task_type_id); | ||
| return onSelectTask(taskType.task_type_id); | ||
| }; | ||
|
|
||
|
|
@@ -225,32 +221,35 @@ export const PureTaskTypeSelection = ({ | |
| </div> | ||
| )} | ||
| </Form> | ||
| {showPlantTaskModal && shouldShowPlantTaskSpotLight && ( | ||
| {errorModal === 'PLANT_TASK' && shouldShowPlantTaskSpotLight && ( | ||
| <PlantingTaskModal | ||
| goToCatalogue={goToCatalogue} | ||
| dismissModal={() => setShowPlantTaskModal(false)} | ||
| dismissModal={() => setErrorModal('')} | ||
| updatePlantTaskSpotlight={updatePlantTaskSpotlight} | ||
| /> | ||
| )} | ||
| {showNoManagementPlanModal && ( | ||
| {['TRANSPLANT_TASK', 'HARVEST_TASK'].includes(errorModal) && ( | ||
| <NoCropManagementPlanModal | ||
| dismissModal={() => setShowNoManagementPlanModal(false)} | ||
| dismissModal={() => setErrorModal('')} | ||
| goToCatalogue={goToCatalogue} | ||
| /> | ||
| )} | ||
| {showNoAnimalLocationsModal && ( | ||
| <NoAnimalLocationsModal | ||
| dismissModal={() => setShowNoAnimalLocationsModal(false)} | ||
| goToMap={goToMap} | ||
| /> | ||
| {errorModal === 'MOVEMENT_TASK' && ( | ||
| <NoAnimalLocationsModal dismissModal={() => setErrorModal('')} goToMap={goToMap} /> | ||
| )} | ||
| {showNoSoilSampleLocationsModal && ( | ||
| {errorModal === 'SOIL_SAMPLE_TASK' && ( | ||
| <NoSoilSampleLocationsModal | ||
| dismissModal={() => setShowNoSoilSampleLocationsModal(false)} | ||
| dismissModal={() => setErrorModal('')} | ||
| goToMap={goToMap} | ||
| isAdmin={isAdmin} | ||
| /> | ||
| )} | ||
| {errorModal === 'SOIL_AMENDMENT_TASK' && ( | ||
| <NoSoilAmendmentProductsModal | ||
| dismissModal={() => setErrorModal('')} | ||
| goToInventory={goToInventory} | ||
| /> | ||
| )} | ||
| </> | ||
| ); | ||
| }; | ||
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
Oops, something went wrong.
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.
In Animal inventory we set it to
totalInventoryCount. Is there a reason we want to limit to 20?Uh oh!
There was an error while loading. Please reload this page.
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 chose 20 arbitrarily, but I thought it was reasonable.
When there are no products,
totalInventoryCountis0. After creating a new product, the "Load more" button appears because the number of rows to display is determined at render time based ontotalInventoryCount, and it never updates dynamically.In the Animal Inventory,
totalInventoryCountdoesn’t increase, so the button won’t appear unexpectedly. But in the Product Inventory, it can change, so we need a fixed number of rows. Should we set it higher?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 can't update the inventory count dynamically to re-render. Then 20 is fine by me!
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.
Ah sorry,
totalInventoryCountchanges, butminRowsdetermines therowsPerPagein<Table />at render time, androwsPerPagecan't be updated externally after that!