Skip to content
This repository has been archived by the owner on Sep 16, 2024. It is now read-only.

Commit

Permalink
chore: Bb 351 update nmp compatibility (#352)
Browse files Browse the repository at this point in the history
* Merge with BB-254

* INvert plants per acre

* Search fert type option

* Fix region load

* Update conversion function

* Lint

* Removed console.log
  • Loading branch information
GDamaso authored Aug 14, 2024
1 parent ffe3d6c commit 0d14edf
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,10 @@ const CalculateNutrientsComponent: FC<InputModuleProps> = ({
};

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 [];
Expand Down
12 changes: 6 additions & 6 deletions frontend/src/Commons/Forms/InputModules/Crops/CropsInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,27 +128,27 @@ const CropsInfoComponent: FC<InputModuleProps> = ({
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
interface SubmissionValues {
FarmName: string;
Year: string;
FarmRegion: string;
FarmRegion: number;
}

const FarmInfoComponent: FC<InputModuleProps> = ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ const FertilizersInfo: FC<InputModuleProps> = ({
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') ? (
<StyledCustomNumberField>
<CustomField
label="N (%)"
Expand Down Expand Up @@ -200,9 +200,9 @@ const FertilizersInfo: FC<InputModuleProps> = ({
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
: []
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -32,11 +33,16 @@ const FertilizersListComponent: FC<FertilizerProps> = ({ fertilizerDetails, remo
mobileWidth="127px"
>
<h2>Fertilizer Type</h2>
<p>{fertilizer.fertilizerTypeId}</p>
<p>
{
FertilizerTypeOptions.find(
(option) => option.value.toString() === fertilizer.fertilizerTypeId,
)?.label
}
</p>
</StyledListItem>
<DesktopFertilizerGroup>
{fertilizer.fertilizerTypeId === 'Dry Fertilizer (Custom)' ||
fertilizer.fertilizerTypeId === 'Liquid Fertilizer (Custom)' ? (
{fertilizer.fertilizerTypeId === '2' || fertilizer.fertilizerTypeId === '4' ? (
<StyledCustomFertilizerGroup>
<StyledListItem
desktopWidth="80px"
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/Constants/FertilizersOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ import OptionInterface from '@Interface/OptionInterface';

const FertilizerTypeOptions: OptionInterface[] = [
{
value: 'Dry Fertilizer',
value: '1',
label: 'Dry Fertilizer',
},
{
value: 'Dry Fertilizer (Custom)',
value: '2',
label: 'Dry Fertilizer (Custom)',
},
{
value: 'Liquid Fertilizer',
value: '3',
label: 'Liquid Fertilizer',
},
{
value: 'Liquid Fertilizer (Custom)',
value: '4',
label: 'Liquid Fertilizer (Custom)',
},
];
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/Constants/SoilTestOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ import OptionInterface from 'src/Interface/OptionInterface';

const soilTestOptions: OptionInterface[] = [
{
value: 'Other Lab (Bicarbonate and Amm Acetate)',
value: '11',
label: 'Other Lab (Bicarbonate and Amm Acetate)',
},
{
value: 'Other Lab (Original Kelowna Method)',
value: '12',
label: 'Other Lab (Original Kelowna Method)',
},
{
value: 'AGAT (Mod Bray-1 and Amm Acetate)',
value: '1',
label: 'AGAT (Mod Bray-1 and Amm Acetate)',
},
{
value: 'A and L Canada (Bray-1 and Mehlich 3)',
value: '2',
label: 'A and L Canada (Bray-1 and Mehlich 3)',
},
];
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/Interface/FarmDetailsInterface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import FieldDetailInterface from './FieldDetailsInterface';
interface FarmDetailsInterface {
Year: string;
FarmName: string;
FarmRegion: string;
FarmRegion: number;
HasBerries: boolean;
Fields: FieldDetailInterface[];
}
Expand Down
20 changes: 13 additions & 7 deletions frontend/src/Utils/convertToNMP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ const convertToNMP = (
newDetails: FarmDetailsInterface,
prevDetails: NmpInterface,
): NmpInterface => {
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,
Expand All @@ -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)
Expand All @@ -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,
Expand Down Expand Up @@ -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 }],
};
Expand Down
5 changes: 1 addition & 4 deletions frontend/src/Utils/getLocalDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 0d14edf

Please sign in to comment.