Skip to content

Commit

Permalink
feat: [NR-NMP-149] Added regions and subregions (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
raarielgrace authored and lunamoonmoon committed Feb 4, 2025
1 parent b0d22e8 commit f0bb1b2
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 66 deletions.
5 changes: 0 additions & 5 deletions backend/apps/animals/admin.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
from django.contrib import admin
from .models import Animals

admin.site.register(Animals)

from django.contrib import admin
from .models import *

Expand Down
7 changes: 6 additions & 1 deletion backend/apps/animals/serializers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
from rest_framework import serializers
from .models import Animals
from .models import *

class AnimalsSerializer(serializers.ModelSerializer):
class Meta:
model = Animals
fields = '__all__'

class AnimalSubtypeSerializer(serializers.ModelSerializer):
class Meta:
model = AnimalSubtype
fields = '__all__'
Empty file removed backend/apps/api/__init__.py
Empty file.
28 changes: 0 additions & 28 deletions backend/apps/api/urls.py

This file was deleted.

32 changes: 0 additions & 32 deletions backend/apps/api/views.py

This file was deleted.

1 change: 1 addition & 0 deletions backend/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
# Apps for this project
'apps.crops',
'apps.animals',
'apps.shared',
]

MIDDLEWARE = [
Expand Down
35 changes: 35 additions & 0 deletions frontend/src/views/FarmInformation/FarmInformation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,30 @@ export default function FarmInformation() {
const apiCache = useContext(APICacheContext);

const [rawAnimalNames, setRawAnimalNames] = useState<string[]>([]);
<<<<<<< HEAD
<<<<<<< HEAD
const [regionOptions, setRegionOptions] = useState<{ value: number; label: string }[]>([]);
const [subregionOptions, setSubregionOptions] = useState<{ value: number; label: string }[]>([]);
=======
>>>>>>> f2d4648 (feat: [NR-NMP-111] "I have animals" radio buttons (#146))
=======
const [regionOptions, setRegionOptions] = useState<{ value: number; label: string }[]>([]);
const [subregionOptions, setSubregionOptions] = useState<{ value: number; label: string }[]>([]);
>>>>>>> 885b602 (feat: [NR-NMP-149] Added regions and subregions (#150))

// Initialize non-bool values to prevent errors on first render
const [formData, setFormData] = useState<{ [name: string]: any }>({
Year: '',
FarmName: '',
FarmRegion: 0,
<<<<<<< HEAD
<<<<<<< HEAD
FarmSubRegion: null,
=======
>>>>>>> f2d4648 (feat: [NR-NMP-111] "I have animals" radio buttons (#146))
=======
FarmSubRegion: null,
>>>>>>> 885b602 (feat: [NR-NMP-149] Added regions and subregions (#150))
});

// Flagging for potential issues if the state.nmpFile object can change
Expand All @@ -55,18 +64,25 @@ export default function FarmInformation() {
Year: parsedData.farmDetails.Year || '',
FarmName: parsedData.farmDetails.FarmName || '',
FarmRegion: parsedData.farmDetails.FarmRegion || 0,
<<<<<<< HEAD
<<<<<<< HEAD
FarmSubRegion: parsedData.farmDetails.FarmSubRegion || null,
=======
>>>>>>> f2d4648 (feat: [NR-NMP-111] "I have animals" radio buttons (#146))
=======
FarmSubRegion: parsedData.farmDetails.FarmSubRegion || null,
>>>>>>> 885b602 (feat: [NR-NMP-149] Added regions and subregions (#150))
HasAnimals: parsedData.farmDetails.HasAnimals || false,
HasDairyCows: parsedData.farmDetails.HasDairyCows || false,
HasBeefCows: parsedData.farmDetails.HasBeefCows || false,
HasPoultry: parsedData.farmDetails.HasPoultry || false,
<<<<<<< HEAD
<<<<<<< HEAD
=======
Animals: [],
>>>>>>> f2d4648 (feat: [NR-NMP-111] "I have animals" radio buttons (#146))
=======
>>>>>>> 885b602 (feat: [NR-NMP-149] Added regions and subregions (#150))
HasVegetables: parsedData.farmDetails.HasVegetables || false,
HasBerries: parsedData.farmDetails.HasBerries || false,
Crops: parsedData.farmDetails.HasHorticulturalCrops.toString() || 'false',
Expand All @@ -87,6 +103,9 @@ export default function FarmInformation() {
}
});
<<<<<<< HEAD
<<<<<<< HEAD
=======
>>>>>>> 885b602 (feat: [NR-NMP-149] Added regions and subregions (#150))
apiCache.callEndpoint('api/regions/').then((response) => {
const { data } = response;
const regions: { value: number; label: string }[] = (
Expand All @@ -112,11 +131,14 @@ export default function FarmInformation() {
});
}, [formData.FarmRegion, apiCache]);

<<<<<<< HEAD
=======
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

>>>>>>> f2d4648 (feat: [NR-NMP-111] "I have animals" radio buttons (#146))
=======
>>>>>>> 885b602 (feat: [NR-NMP-149] Added regions and subregions (#150))
const handleChange = useCallback(
(e: React.ChangeEvent<HTMLInputElement | HTMLSelectElement>) => {
const { name, value, type, checked } = e.target as HTMLInputElement;
Expand Down Expand Up @@ -213,6 +235,19 @@ export default function FarmInformation() {
name="FarmRegion"
value={formData.FarmRegion}
options={regionOptions}
<<<<<<< HEAD
=======
onChange={handleChange}
flex="0.35"
/>
</RegionContainer>
<RegionContainer>
<Dropdown
label="Subregion"
name="FarmSubRegion"
value={formData.FarmSubRegion}
options={subregionOptions}
>>>>>>> 885b602 (feat: [NR-NMP-149] Added regions and subregions (#150))
onChange={handleChange}
flex="0.35"
/>
Expand Down

0 comments on commit f0bb1b2

Please sign in to comment.