From 0d14edffb288e57c7ec78fabac6c6d0a68128649 Mon Sep 17 00:00:00 2001 From: GDamaso <80939533+GDamaso@users.noreply.github.com> Date: Wed, 14 Aug 2024 09:31:57 -0700 Subject: [PATCH] chore: Bb 351 update nmp compatibility (#352) * Merge with BB-254 * INvert plants per acre * Search fert type option * Fix region load * Update conversion function * Lint * Removed console.log --- .../CalculateNutrients/CalculateNutrients.tsx | 4 ++-- .../Forms/InputModules/Crops/CropsInfo.tsx | 12 +++++------ .../FarmInformation/FarmInformation.tsx | 2 +- .../InputModules/Fertilizers/Fertilizers.tsx | 8 ++++---- .../Fertilizers/FertilizersListComponent.tsx | 12 ++++++++--- frontend/src/Constants/FertilizersOptions.ts | 8 ++++---- frontend/src/Constants/SoilTestOptions.ts | 8 ++++---- .../src/Interface/FarmDetailsInterface.tsx | 2 +- frontend/src/Utils/convertToNMP.ts | 20 ++++++++++++------- frontend/src/Utils/getLocalDetails.ts | 5 +---- 10 files changed, 45 insertions(+), 36 deletions(-) diff --git a/frontend/src/Commons/Forms/InputModules/CalculateNutrients/CalculateNutrients.tsx b/frontend/src/Commons/Forms/InputModules/CalculateNutrients/CalculateNutrients.tsx index f12414bd..44cb72fb 100644 --- a/frontend/src/Commons/Forms/InputModules/CalculateNutrients/CalculateNutrients.tsx +++ b/frontend/src/Commons/Forms/InputModules/CalculateNutrients/CalculateNutrients.tsx @@ -285,10 +285,10 @@ const CalculateNutrientsComponent: FC = ({ }; const displayFertilizerOption = (): OptionInterface[] => { - if (fertilizersDetails[selectedIndex]?.fertilizerTypeId.includes('Dry Fertilizer')) { + if (fertilizersDetails[selectedIndex]?.fertilizerTypeId.includes('1')) { return DryApplicationUnits; } - if (fertilizersDetails[selectedIndex]?.fertilizerTypeId.includes('Liquid Fertilizer')) { + if (fertilizersDetails[selectedIndex]?.fertilizerTypeId.includes('3')) { return LiquidApplicationUnits; } return []; diff --git a/frontend/src/Commons/Forms/InputModules/Crops/CropsInfo.tsx b/frontend/src/Commons/Forms/InputModules/Crops/CropsInfo.tsx index 248ad6dc..43a71633 100644 --- a/frontend/src/Commons/Forms/InputModules/Crops/CropsInfo.tsx +++ b/frontend/src/Commons/Forms/InputModules/Crops/CropsInfo.tsx @@ -128,27 +128,27 @@ const CropsInfoComponent: FC = ({ switch (distanceCombination) { case '0.6x2.7': res = '(2ft x 9ft)'; - setplantsPerHa(getPlantsPerAcre(5)); + setplantsPerHa(getPlantsPerAcre(0)); break; case '0.6x3.0': res = '(2ft x 10ft)'; - setplantsPerHa(getPlantsPerAcre(4)); + setplantsPerHa(getPlantsPerAcre(1)); break; case '0.75x2.7': res = '(2.5ft x 9ft)'; - setplantsPerHa(getPlantsPerAcre(3)); + setplantsPerHa(getPlantsPerAcre(2)); break; case '0.75x3.0': res = '(2.5ft x 10ft)'; - setplantsPerHa(getPlantsPerAcre(2)); + setplantsPerHa(getPlantsPerAcre(3)); break; case '0.9x2.7': res = '(3ft x 9ft)'; - setplantsPerHa(getPlantsPerAcre(1)); + setplantsPerHa(getPlantsPerAcre(4)); break; case '0.9x3.0': res = '(3ft x 10ft)'; - setplantsPerHa(getPlantsPerAcre(0)); + setplantsPerHa(getPlantsPerAcre(5)); break; default: break; diff --git a/frontend/src/Commons/Forms/InputModules/FarmInformation/FarmInformation.tsx b/frontend/src/Commons/Forms/InputModules/FarmInformation/FarmInformation.tsx index 183887b1..25552ccb 100644 --- a/frontend/src/Commons/Forms/InputModules/FarmInformation/FarmInformation.tsx +++ b/frontend/src/Commons/Forms/InputModules/FarmInformation/FarmInformation.tsx @@ -27,7 +27,7 @@ import { interface SubmissionValues { FarmName: string; Year: string; - FarmRegion: string; + FarmRegion: number; } const FarmInfoComponent: FC = ({ diff --git a/frontend/src/Commons/Forms/InputModules/Fertilizers/Fertilizers.tsx b/frontend/src/Commons/Forms/InputModules/Fertilizers/Fertilizers.tsx index 9a80a6ba..0ac7aa8b 100644 --- a/frontend/src/Commons/Forms/InputModules/Fertilizers/Fertilizers.tsx +++ b/frontend/src/Commons/Forms/InputModules/Fertilizers/Fertilizers.tsx @@ -166,8 +166,8 @@ const FertilizersInfo: FC = ({ mobileWidth="100%" onChange={(e) => handleChange(e, setFieldValue)} /> - {values.fertilizerTypeId.includes('Dry Fertilizer (Custom)') || - values.fertilizerTypeId.includes('Liquid Fertilizer (Custom)') ? ( + {values.fertilizerTypeId.includes('2') || + values.fertilizerTypeId.includes('4') ? ( = ({ id="fertilizerId" label="Fertilizer Name" options={ - values.fertilizerTypeId.includes('Dry Fertilizer') + values.fertilizerTypeId.includes('1') ? DryFertilizerOptions - : values.fertilizerTypeId.includes('Liquid Fertilizer') + : values.fertilizerTypeId.includes('3') ? LiquidFertilizerOptions : [] } diff --git a/frontend/src/Commons/Forms/InputModules/Fertilizers/FertilizersListComponent.tsx b/frontend/src/Commons/Forms/InputModules/Fertilizers/FertilizersListComponent.tsx index a3dad2f7..6bcd33d4 100644 --- a/frontend/src/Commons/Forms/InputModules/Fertilizers/FertilizersListComponent.tsx +++ b/frontend/src/Commons/Forms/InputModules/Fertilizers/FertilizersListComponent.tsx @@ -3,6 +3,7 @@ import { faTrashCan } from '@fortawesome/free-solid-svg-icons'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import FertilizerInterface from '@Interface/FertilizerInterface'; import getFertilizerOption from '@Utils/getFertID'; +import { FertilizerTypeOptions } from '@Constants/FertilizersOptions'; import { StyledFieldInfoList, StyledListItem, @@ -32,11 +33,16 @@ const FertilizersListComponent: FC = ({ fertilizerDetails, remo mobileWidth="127px" >

Fertilizer Type

-

{fertilizer.fertilizerTypeId}

+

+ { + FertilizerTypeOptions.find( + (option) => option.value.toString() === fertilizer.fertilizerTypeId, + )?.label + } +

- {fertilizer.fertilizerTypeId === 'Dry Fertilizer (Custom)' || - fertilizer.fertilizerTypeId === 'Liquid Fertilizer (Custom)' ? ( + {fertilizer.fertilizerTypeId === '2' || fertilizer.fertilizerTypeId === '4' ? ( { + let hasLeafTest = false; + let testingMethod = ''; const newFields: NmpFieldInterface[] = newDetails.Fields.map((field: FieldDetailInterface) => { + if (field.HasLeafTest) hasLeafTest = true; + if (field.HasSoilTest) testingMethod = field.SoilTest.TestingMethod; + const newCrops: NmpCropInterface[] = field.Crops?.map((crop: CropsDetailsInterface) => ({ ...templateCropNMP, id: crop.id, @@ -39,9 +44,9 @@ const convertToNMP = ( plantAgeYears: crop.plantAgeYears, numberOfPlantsPerAcre: crop.numberOfPlantsPerAcre, distanceBtwnPlantsRows: crop.distanceBtwnPlantsRows, - willPlantsBePruned: crop.willPlantsBePruned === true, + willPlantsBePruned: crop.willPlantsBePruned ?? false, whereWillPruningsGo: crop.whereWillPruningsGo, - willSawdustBeApplied: crop.willSawdustBeApplied === true, + willSawdustBeApplied: crop.willSawdustBeApplied ?? false, })); const newNutrients: FertilizerInterface[] = Array.isArray(field.Nutrients?.nutrientFertilizers) @@ -62,14 +67,13 @@ const convertToNMP = ( ValP: field.SoilTest.ValP || templateFieldNMP.SoilTest?.ValP, valK: field.SoilTest.valK || templateFieldNMP.SoilTest?.valK, valPH: field.SoilTest.valPH || templateFieldNMP.SoilTest?.valPH, - // sampleDate: field.SoilTest?.sampleDate || templateFieldNMP.SoilTest?.sampleDate, - sampleDate: '2024-07-01T00:00:00', + sampleDate: field.SoilTest.sampleDate ?? '2024-07-01T00:00:00', } : null, LeafTest: field.HasLeafTest ? { - leafTissueP: field.LeafTest?.leafTissueP, - leafTissueK: field.LeafTest?.leafTissueK, + leafTissueP: field.LeafTest.leafTissueP, + leafTissueK: field.LeafTest.leafTissueK, } : null, Crops: newCrops, @@ -108,13 +112,15 @@ const convertToNMP = ( }, }; }); - return { ...prevDetails, farmDetails: { ...prevDetails.farmDetails, FarmName: newDetails.FarmName, Year: newDetails.Year, + FarmRegion: newDetails.FarmRegion, + LeafTestingMethod: hasLeafTest ? '0' : '', + TestingMethod: testingMethod, }, years: [{ ...prevDetails.years[0], Year: newDetails.Year, Fields: newFields }], }; diff --git a/frontend/src/Utils/getLocalDetails.ts b/frontend/src/Utils/getLocalDetails.ts index 44f1e8de..47225cc4 100644 --- a/frontend/src/Utils/getLocalDetails.ts +++ b/frontend/src/Utils/getLocalDetails.ts @@ -27,10 +27,7 @@ const loadFarmDetails = (farmDetails: FarmDetailsInterface): FarmDetailsInterfac updatedFarmDetails.FarmName = nmpFarmDetails.FarmName; updatedFarmDetails.Year = nmpFarmDetails.Year; - - if (nmpFarmDetails.FarmRegion === 21) { - updatedFarmDetails.FarmRegion = 'Vancouver Island'; - } + updatedFarmDetails.FarmRegion = nmpFarmDetails.FarmRegion ?? 0; fieldsJSON.forEach((field) => { const updateField: FieldDetailInterface = field;