Skip to content

Commit

Permalink
feat: [NR-NMP-112] Beef Cattle flow (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
raarielgrace authored Feb 12, 2025
1 parent 968b3cc commit 7eef0a5
Show file tree
Hide file tree
Showing 21 changed files with 738 additions and 154 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -361,5 +361,3 @@ poetry.toml
pyrightconfig.json

# End of https://www.toptal.com/developers/gitignore/api/node,java,python,go
.env.template
backend/.env.template
20 changes: 20 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@fortawesome/react-fontawesome": "^0.2.2",
"axios": "^1.7.9",
"react": "^18.3.1",
"react-collapsed": "^4.2.0",
"react-dom": "^18.3.1",
"react-router-dom": "^6.28.0",
"typography": "^0.16.24"
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/common/Card/card.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const CardWrapper = styled.div<CardWrapperProps>`
text-align: center;
position: relative;
justify-content: ${(props) => props.justifyContent};
overflow: auto;
`;

export default CardWrapper;
1 change: 1 addition & 0 deletions frontend/src/components/common/Tabs/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export function TabOptions({ tabs, activeTab, setActiveTab, clickable = true }:
<Tab
key={tab.id}
active={index === activeTab}
clickable={clickable}
onClick={() => clickable && setActiveTab && setActiveTab(index)}
>
{tab.label}
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/common/Tabs/tabs.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ export const TabsWrapper = styled.div`
align-items: flex-end; // Align tabs to the bottom
`;

export const Tab = styled.button<{ active: boolean }>`
export const Tab = styled.button<{ active: boolean; clickable: boolean }>`
padding: 10px 20px;
cursor: pointer;
cursor: ${({ clickable }) => (clickable ? 'pointer' : 'default')};
background-color: ${({ active }) => (active ? '#fff' : '#ccc')};
color: ${({ active }) => (active ? '#000' : '#000')};
border-bottom: ${({ active }) => (active ? 'none' : 'none')};
Expand Down
71 changes: 71 additions & 0 deletions frontend/src/constants/BlankNMPFileYearData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
const blankNMPFileYearData = {
Year: '',
Fields: [],
// Keeping these properties to show what used to be stored in the NMP file
/*
Fields: [
{
Id: 0,
FieldName: '',
Area: 0,
Comment: null,
Nutrients: null,
HasNutrients: false,
Crops: [
{
id: 0,
cropId: '',
cropOther: null,
cropName: '',
cropTypeName: '',
yield: 0,
reqN: 0,
stdN: 0,
reqP2o5: 0,
reqK2o: 0,
remN: 0,
remP2o5: 0,
remK2o: 0,
crudeProtien: 0,
prevCropId: 0,
coverCropHarvested: null,
prevYearManureAppl_volCatCd: 0,
yieldHarvestUnit: 0,
yieldByHarvestUnit: 0,
plantAgeYears: null,
numberOfPlantsPerAcre: 0,
distanceBtwnPlantsRows: null,
willPlantsBePruned: false,
whereWillPruningsGo: null,
willSawdustBeApplied: false,
},
],
FeedForageAnalyses: [],
SoilTest: null,
LeafTest: null,
HasSoilTest: false,
PreviousYearManureApplicationFrequency: '',
PreviousYearManureApplicationNitrogenCredit: null,
SoilTestNitrateOverrideNitrogenCredit: null,
IsSeasonalFeedingArea: false,
SeasonalFeedingArea: null,
FeedingDaysSpentInFeedingArea: null,
FeedingPercentageOutsideFeeingArea: null,
MatureAnimalCount: null,
GrowingAnimalCount: null,
MatureAnimalAverageWeight: null,
GrowingAnimalAverageWeight: null,
MatureAnimalDailyFeedRequirementId: 0,
GrowingAnimalDailyFeedRequirementId: 0,
},
],
*/
FarmAnimals: [],
FarmManures: [],
GeneratedManures: [],
ImportedManures: [],
SeparatedSolidManures: [],
ManureStorageSystems: [],
};

export default blankNMPFileYearData;
74 changes: 2 additions & 72 deletions frontend/src/constants/DefaultNMPFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ const defaultNMPFile: NMPFile = {
Manure: null,
HasSelectedFarmType: false,
ImportsManureCompost: false,
HasAnimals: false,
HasDairyCows: false,
HasBeefCows: false,
HasPoultry: false,
HasMixedLiveStock: false,
FarmAnimals: [],
HasHorticulturalCrops: false,
HasBerries: false,
HasVegetables: false,
Expand All @@ -24,73 +20,7 @@ const defaultNMPFile: NMPFile = {
UserJourney: 0,
},
unsaved: false,
years: [
{
Year: '',
Fields: [
{
Id: 0,
FieldName: '',
Area: 0,
Comment: null,
Nutrients: null,
HasNutrients: false,
Crops: [
{
id: 0,
cropId: '',
cropOther: null,
cropName: '',
cropTypeName: '',
yield: 0,
reqN: 0,
stdN: 0,
reqP2o5: 0,
reqK2o: 0,
remN: 0,
remP2o5: 0,
remK2o: 0,
crudeProtien: 0,
prevCropId: 0,
coverCropHarvested: null,
prevYearManureAppl_volCatCd: 0,
yieldHarvestUnit: 0,
yieldByHarvestUnit: 0,
plantAgeYears: null,
numberOfPlantsPerAcre: 0,
distanceBtwnPlantsRows: null,
willPlantsBePruned: false,
whereWillPruningsGo: null,
willSawdustBeApplied: false,
},
],
FeedForageAnalyses: [],
SoilTest: null,
LeafTest: null,
HasSoilTest: false,
PreviousYearManureApplicationFrequency: '',
PreviousYearManureApplicationNitrogenCredit: null,
SoilTestNitrateOverrideNitrogenCredit: null,
IsSeasonalFeedingArea: false,
SeasonalFeedingArea: null,
FeedingDaysSpentInFeedingArea: null,
FeedingPercentageOutsideFeeingArea: null,
MatureAnimalCount: null,
GrowingAnimalCount: null,
MatureAnimalAverageWeight: null,
GrowingAnimalAverageWeight: null,
MatureAnimalDailyFeedRequirementId: 0,
GrowingAnimalDailyFeedRequirementId: 0,
},
],
FarmAnimals: [],
FarmManures: [],
GeneratedManures: [],
ImportedManures: [],
SeparatedSolidManures: [],
ManureStorageSystems: [],
},
],
years: [],
LastAppliedFarmManureId: null,
NMPReleaseVersion: 0,
};
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/routes/ViewRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Routes, Route } from 'react-router-dom';
import LandingPage from '../views/LandingPage/LandingPage';
import FarmInformation from '../views/FarmInformation/FarmInformation';
import FieldAndSoil from '@/views/FieldAndSoil/FieldAndSoil';
import AnimalsAndManure from '@/views/AnimalsAndManure/AnimalsAndManure';
import CalculateNutrients from '@/views/CalculateNutrients/CalculateNutrients';

export default function ViewRouter() {
Expand All @@ -27,6 +28,10 @@ export default function ViewRouter() {
path="/calculate-nutrients"
Component={CalculateNutrients}
/>
<Route
path="/animals-and-manure"
Component={AnimalsAndManure}
/>
</Routes>
);
}
10 changes: 3 additions & 7 deletions frontend/src/types/NMPFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

type NMPFile = {
farmDetails?: {
farmDetails: {
Year?: string;
FarmName?: string;
FarmRegion?: number;
Expand All @@ -13,11 +13,7 @@ type NMPFile = {
Manure?: any | null;
HasSelectedFarmType?: boolean;
ImportsManureCompost?: boolean;
HasAnimals?: boolean;
HasDairyCows?: boolean;
HasBeefCows?: boolean;
HasPoultry?: boolean;
HasMixedLiveStock?: boolean;
FarmAnimals?: string[];
HasHorticulturalCrops?: boolean;
HasBerries?: boolean;
HasVegetables?: boolean;
Expand All @@ -26,7 +22,7 @@ type NMPFile = {
UserJourney?: number;
};
unsaved?: boolean;
years?: Array<{
years: Array<{
Year?: string;
Fields?: Array<{
Id?: number;
Expand Down
36 changes: 36 additions & 0 deletions frontend/src/utils/useEventfulCollapse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { useCollapse, UseCollapseInput } from 'react-collapsed';

export class ExpandEvent extends Event {
public initiator: string;

constructor(initiator: string) {
super('expand');
this.initiator = initiator;
}
}

interface UseEventfulCollapseInput extends UseCollapseInput {
id: string | number;
}

export function useEventfulCollapse(settings: UseEventfulCollapseInput) {
const { isExpanded, setExpanded, getCollapseProps, getToggleProps } = useCollapse({
...settings,
onTransitionStateChange: (state) => {
if (state === 'expandStart') {
window.dispatchEvent(new ExpandEvent(settings.id.toString()));
}
},
});
window.addEventListener('expand', (e) => {
// If this is not the initiating element, collapse it
if ((e as ExpandEvent).initiator === settings.id) return;
setExpanded(false);
});
return {
isExpanded,
setExpanded,
getCollapseProps,
getToggleProps,
};
}
Loading

0 comments on commit 7eef0a5

Please sign in to comment.