Skip to content

Commit

Permalink
Merge pull request #3574 from LiteFarmOrg/LF-4558/Adjust_tasks_for_fa…
Browse files Browse the repository at this point in the history
…rms_with_no_animals

LF-4558: Adjust tasks for farms with no animals
  • Loading branch information
Duncan-Brain authored Dec 6, 2024
2 parents 97a2ca9 + 1d5839e commit f6cf50f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export const PureTaskTypeSelection = ({
shouldShowPlantTaskSpotLight,
updatePlantTaskSpotlight,
hasCurrentManagementPlans,
hasAnimals,
}) => {
const { t } = useTranslation();
const { watch, getValues, register, setValue } = useForm({
Expand Down Expand Up @@ -110,7 +111,7 @@ export const PureTaskTypeSelection = ({
};

const shouldDisplayTaskType = (taskType) => {
const supportedTaskTypes = getSupportedTaskTypesSet(isAdmin);
const supportedTaskTypes = getSupportedTaskTypesSet(isAdmin, hasAnimals);
const { farm_id, task_translation_key } = taskType;

if (farm_id === null && supportedTaskTypes.has(task_translation_key)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@
* @param isAdmin {boolean}
* @return {Set<string>}
*/
export const getSupportedTaskTypesSet = (isAdmin) => {
export const getSupportedTaskTypesSet = (isAdmin, hasAnimals) => {
const supportedTaskTypes = new Set([
'SOIL_AMENDMENT_TASK',
'FIELD_WORK_TASK',
'PEST_CONTROL_TASK',
'CLEANING_TASK',
'HARVEST_TASK',
'IRRIGATION_TASK',
'MOVEMENT_TASK',
]);

if (hasAnimals) {
supportedTaskTypes.add('MOVEMENT_TASK');
}

if (isAdmin) {
supportedTaskTypes.add('PLANT_TASK');
supportedTaskTypes.add('TRANSPLANT_TASK');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ const useAnimalsExist = () => {
{ label: 'animalBatches', hook: useGetAnimalBatchesQuery },
]);

const animalsExistOnFarm = !isLoading && (data.animals.length || data.animalBatches.length);
const animalsExistOnFarm =
!isLoading &&
[...data.animals, ...data.animalBatches].some((entity) => !entity.animal_removal_reason_id);

return { animalsExistOnFarm };
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { defaultTaskTypesSelector, userCreatedTaskTypesSelector } from '../../ta
import { showedSpotlightSelector } from '../../showedSpotlightSlice';
import { setSpotlightToShown } from '../../Map/saga';
import { currentAndPlannedManagementPlansSelector } from '../../managementPlanSlice';
import useAnimalsExist from '../../Animals/Inventory/useAnimalsExist';

function TaskTypeSelection({ history, match, location }) {
const userFarm = useSelector(userFarmSelector);
Expand All @@ -19,6 +20,7 @@ function TaskTypeSelection({ history, match, location }) {
const persistedPaths = [continuePath, customTaskPath];
const { planting_task } = useSelector(showedSpotlightSelector);
const isAdmin = useSelector(isAdminSelector);
const { animalsExistOnFarm } = useAnimalsExist();

useEffect(() => {
dispatch(getTaskTypes());
Expand Down Expand Up @@ -58,6 +60,7 @@ function TaskTypeSelection({ history, match, location }) {
shouldShowPlantTaskSpotLight={!planting_task}
updatePlantTaskSpotlight={updatePlantTaskSpotlight}
hasCurrentManagementPlans={hasCurrentManagementPlans}
hasAnimals={animalsExistOnFarm}
/>
</HookFormPersistProvider>
</>
Expand Down

0 comments on commit f6cf50f

Please sign in to comment.