Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
ab5aea6
Consolidate URL strings to apiConfig
Duncan-Brain Dec 16, 2025
c3d4b89
Add Location types to frontend api type file
Duncan-Brain Dec 16, 2025
c2c9767
Create first locations API
Duncan-Brain Dec 16, 2025
60f6634
Add check delete location mutation to api
Duncan-Brain Dec 16, 2025
95b3c2b
Add delete location api
Duncan-Brain Dec 17, 2025
60b48e2
Small adjustments
Duncan-Brain Dec 17, 2025
3d5153c
Add location types enum
Duncan-Brain Dec 17, 2025
7bcf861
Remove pin location type
Duncan-Brain Dec 17, 2025
9b6f131
Add post endpoints to api
Duncan-Brain Dec 17, 2025
db01e35
Add invalidates tags to delete endpoint
Duncan-Brain Dec 17, 2025
08b03b0
Add update api endpoint
Duncan-Brain Dec 17, 2025
c169624
Find and replace identical instances of handle retire functionality
Duncan-Brain Dec 18, 2025
0832a27
Delete unused saga
Duncan-Brain Dec 18, 2025
d741b3c
Remove duplicate enum
Duncan-Brain Dec 18, 2025
259b661
Use enum as key names for better typing
Duncan-Brain Dec 18, 2025
29655f2
Add figure types
Duncan-Brain Dec 18, 2025
513b3aa
Update discriminated union types to include never properties
Duncan-Brain Dec 18, 2025
0805f47
Create basic hook that removes excess properties
Duncan-Brain Dec 18, 2025
e4845a0
Add groupBy and filterBy options to hook
Duncan-Brain Dec 18, 2025
5c65007
Add hook capable of replacing sensor selectors
Duncan-Brain Dec 19, 2025
d394d45
Add third groupby option
Duncan-Brain Dec 19, 2025
f874135
Extract out details and Ids for reuse with other types
Duncan-Brain Dec 22, 2025
5e0e32f
Create flattened location types
Duncan-Brain Dec 22, 2025
e740bb5
Update API types
Duncan-Brain Dec 22, 2025
3b098af
Add flatten data function to match pre-existing selectors
Duncan-Brain Dec 22, 2025
c7f2a85
Correct types slightly to include figure_id
Duncan-Brain Dec 22, 2025
6105f7a
Add forgotten deleted property to api type
Duncan-Brain Dec 22, 2025
aee1aee
Filter deleted locations from hook return
Duncan-Brain Dec 22, 2025
e189fcf
Import location type
Duncan-Brain Dec 22, 2025
81b680b
Add manual grouping by figure type
Duncan-Brain Dec 22, 2025
0e72fee
Use hooks instead of selectors - TODO deal with render lag using loading
Duncan-Brain Dec 22, 2025
5e183e4
Add basic Loading screen for map
Duncan-Brain Dec 30, 2025
0106366
Fix Loading for typescript
Duncan-Brain Dec 30, 2025
2e9c8a6
Export isloading boolean
Duncan-Brain Dec 30, 2025
81dfe54
Add basic loading modal to maps, handle merge conflicts for condition…
Duncan-Brain Dec 30, 2025
707f651
Allow useExternalLocations to return undefined when there is no data …
Duncan-Brain Dec 30, 2025
84ba2d0
Allow useLocation to return undefined when data does not exist
Duncan-Brain Dec 30, 2025
25f1f6e
Just duplicate filterBy and groupBy functionality for external locations
Duncan-Brain Jan 2, 2026
27882d6
Update hook call to include groupBy
Duncan-Brain Jan 2, 2026
1412a48
Remove selector use from useMaxZoom and fix possible bug where seneso…
Duncan-Brain Jan 2, 2026
7894258
Remove types now inferred and add shared filterBy and groupBy prop types
Duncan-Brain Jan 3, 2026
94224e3
Use shared types in hooks
Duncan-Brain Jan 4, 2026
67ca713
Create a default filter settings constant that uses rtk API types
Duncan-Brain Jan 5, 2026
e732950
Replace available filter settings selector with a custom hook
Duncan-Brain Jan 5, 2026
0fe5c88
Handle case where locations may be undefined, unsure how previously m…
Duncan-Brain Jan 5, 2026
cf6652a
Allow sensor_arrays to be filterable separate from sensors as a disti…
Duncan-Brain Jan 5, 2026
0e19016
Update hooks to infer better types based on props
Duncan-Brain Jan 5, 2026
3b358e8
Filter out deleted first to reduce more complex loop iterations
Duncan-Brain Jan 5, 2026
21a2714
remove unused imports
Duncan-Brain Jan 6, 2026
b112bc0
retire sensor selectors
Duncan-Brain Jan 8, 2026
a58cca4
Remove farm_id from useGetLocationsQuery and add it directly to the e…
Duncan-Brain Jan 9, 2026
bf4d8ab
Add more defined overloads for filterby
Duncan-Brain Jan 9, 2026
84c16f6
Update useGroupedSensors to use locations hook
Duncan-Brain Jan 9, 2026
7e44973
Update types for geoutils
Duncan-Brain Jan 9, 2026
769124a
Remove unused hook
Duncan-Brain Jan 9, 2026
28e4a20
Add default object to args, comments cleanup
Duncan-Brain Jan 9, 2026
aabd0c6
Add hook that returns locations by known ids
Duncan-Brain Jan 9, 2026
8d8ab5c
Replace locationsSelector in SoilAmendmentTask component
Duncan-Brain Jan 9, 2026
b071fd9
Replace locationsSelector in animals
Duncan-Brain Jan 9, 2026
86087f6
Replace locationsSelector with useLocations in tasks
Duncan-Brain Jan 9, 2026
3b1ef95
Let useLocationsById return a singlar location and accept a singular id
Duncan-Brain Jan 10, 2026
888e380
Replace all locationByIdSelector instances with hook
Duncan-Brain Jan 10, 2026
e0ba2ae
Delete location selector and locationById selector
Duncan-Brain Jan 10, 2026
667a2dc
Add invalidates Locations tags to location sagas
Duncan-Brain Feb 25, 2026
c3795ba
Remove unused locationSlice selectors
Duncan-Brain Feb 25, 2026
6dea925
Update use locations hook to accept an array of location types to fil…
Duncan-Brain Feb 27, 2026
04204f3
Creat useCropLocations hook
Duncan-Brain Feb 27, 2026
4a8d819
Replace cropLocationsSelector accross app
Duncan-Brain Feb 27, 2026
a10bc3e
Make useAnimalLocations hook
Duncan-Brain Feb 27, 2026
4c74a6e
Replace animalLocationSelector
Duncan-Brain Feb 27, 2026
79f4997
replace some in app selector usage with hook usage
Duncan-Brain Feb 27, 2026
9b622e0
rename export to locationApi
Duncan-Brain Feb 27, 2026
e234f98
Add option to allow deleted locations to help mimic entity selectors
Duncan-Brain Feb 27, 2026
868c56f
Make create entities selectors mimic the hook as we migrate managemen…
Duncan-Brain Feb 27, 2026
ac1797f
Did not use the correct replacement for entities selector, these now …
Duncan-Brain Feb 27, 2026
6c1226f
Move location slice out to its new temporary home
Duncan-Brain Feb 27, 2026
6b87e2e
Add a note to the selectors file
Duncan-Brain Feb 27, 2026
bb818fd
For selectors that are temporary to work the endpoint needs to be ini…
Duncan-Brain Mar 10, 2026
a8bed05
Pass isFetching through the hook
Duncan-Brain Mar 11, 2026
b386bb8
use isFetching instead of isLoading temporarily
Duncan-Brain Mar 12, 2026
a339822
Sensor arrays missing errors from clusters
Duncan-Brain Mar 12, 2026
dbbda32
Update copyright notice
Duncan-Brain Mar 12, 2026
3177ef2
One more missing sensor array
Duncan-Brain Mar 12, 2026
040e20a
proper body shape for unused endpoints
Duncan-Brain Mar 16, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/api/src/models/locationModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ class Location extends baseModel {
}
}

/* Mirrors cropLocationsSelector but without buffer zone (which does not return a polygon) */
/* Mirrors useCropLocations hook but without buffer zone (which does not return a polygon) */
static async getCropSupportingLocationsByFarmId(farm_id, trx) {
return Location.query(trx)
.where({ 'location.farm_id': farm_id })
Expand Down
2 changes: 2 additions & 0 deletions packages/webapp/public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,7 @@
"PERIMETER": "Perimeter",
"TOTAL_AREA": "Total area"
},
"ASSETS_LOADING": "Assets are loading...",
"BARN": {
"ANIMALS": "Is this area used for housing animals?",
"COLD_STORAGE": "Does this barn have cold storage?",
Expand Down Expand Up @@ -906,6 +907,7 @@
"RESIDENCE": "Residence",
"SATELLITE": "Satellite background",
"SENSOR": "Sensor",
"SENSOR_ARRAY": "Sensor array",
"SHOW_ALL": "Show all",
"SOIL_SAMPLE_LOCATION": "Soil sample location",
"SURFACE_WATER": "Surface water",
Expand Down
5 changes: 5 additions & 0 deletions packages/webapp/src/apiConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export const farmUrl = `${URI}/farm`;
export const inviteUserUrl = `${URI}/user/invite`;
//export const fieldURL = `${URI}/field`;
export const locationURL = `${URI}/location`;
export const getLocationsByFarmIdUrl = (farm_id) => `${locationURL}/farm/${farm_id}`;
export const checkDeleteLocationUrl = `${locationURL}/check_delete`;
export const cropURL = `${URI}/crop`;
export const cropVarietyURL = `${URI}/crop_variety`;
export const logURL = `${URI}/log`;
Expand Down Expand Up @@ -97,6 +99,7 @@ export const marketDirectoryInfoUrl = `${URI}/market_directory_info`;
export const marketProductCategoryUrl = `${URI}/market_product_categories`;
export const marketDirectoryPartnersUrl = `${URI}/market_directory_partners`;
export const supportTicketUrl = `${URI}/support_ticket`;
export const logUserInfoUrl = `${URI}/userLog`;
export const offlineEventLogUrl = `${URI}/offline_event_log`;

export const url = URI;
Expand All @@ -106,8 +109,10 @@ export default {
pseudoUserUrl,
farmUrl,
inviteUserUrl,
logUserInfoUrl,
//fieldURL,
locationURL,
getLocationsByFarmIdUrl,
cropURL,
cropVarietyURL,
logURL,
Expand Down
7 changes: 3 additions & 4 deletions packages/webapp/src/components/Crop/Management.jsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import Layout from '../Layout';
import CropHeader from './CropHeader';
import RouterTab from '../RouterTab';
import React, { useMemo, useState } from 'react';
import { useMemo, useState } from 'react';
import { AddLink, Semibold } from '../Typography';
import { useTranslation } from 'react-i18next';
import PropTypes from 'prop-types';
import { CardWithStatusContainer } from '../CardWithStatus/CardWithStatusContainer/CardWithStatusContainer';
import { ManagementPlanCard } from '../CardWithStatus/ManagementPlanCard/ManagementPlanCard';
import Input from '../Form/Input';
import { useSelector } from 'react-redux';
import { cropLocationsSelector } from '../../containers/locationSlice';
import LocationCreationModal from '../LocationCreationModal';
import CropPlansModal from '../Modals/CropModals/CropPlansModal';
import navStyles from '@navStyles';
import useCropLocations from '../../hooks/location/useCropLocations';

export default function PureCropManagement({
history,
Expand All @@ -38,7 +37,7 @@ export default function PureCropManagement({
)
: managementPlanCardContents;
}, [searchString, managementPlanCardContents]);
const cropLocations = useSelector(cropLocationsSelector);
const { locations: cropLocations } = useCropLocations();
const [createCropLocation, setCreateCropLocation] = useState(false);

const dismissLocationCreationModal = () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/webapp/src/components/Loading/Loading.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ReactComponent as LoadingAnimation } from '../../assets/images/signUp/animated_loading_farm.svg';
import { colors } from '../../assets/theme';

export function Loading({ children = <LoadingAnimation />, style, ...props }) {
export function Loading({ children = <LoadingAnimation />, style = {}, ...props }) {
return (
<div
style={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ import LineDetails from './LineDetails/LineDetails';
import PointDetails from './PointDetails/PointDetails';
import RouterTab from '../RouterTab';
import useLocationRouterTabs from '../../containers/LocationDetails/useLocationRouterTabs';
import { useSelector } from 'react-redux';
import { locationByIdSelector } from '../../containers/locationSlice';
import { Variant } from '../RouterTab/Tab';
import CardLayout from '../Layout/CardLayout';
import useLocationsById from '../../hooks/location/useLocationsById';

export function PureLocationDetailLayout({
history,
Expand Down Expand Up @@ -51,8 +50,9 @@ export function PureLocationDetailLayout({

// TODO: Move this up to container when just 1 container exists for locations
const { location_id } = match.params;
const location =
isViewLocationPage && location_id && useSelector(locationByIdSelector(location_id));
const { locations: locationById } = useLocationsById(location_id);
const location = isViewLocationPage && location_id && locationById;

const routerTabs = location && useLocationRouterTabs(location);

const details = useMemo(() => {
Expand Down
23 changes: 2 additions & 21 deletions packages/webapp/src/components/Map/Footer/index.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import PropTypes from 'prop-types';
import { useTranslation } from 'react-i18next';
import MapDrawer from '../../MapDrawer';
import { locationEnum } from '../../../containers/Map/constants';
import { MAP_LOCATION_TYPE_BY_FIGURE } from '../../../containers/Map/constants';
import { TourProviderWrapper } from '../../TourProviderWrapper/TourProviderWrapper';
import FloatingContainer from '../../FloatingContainer';
import MapNavigationButtons from './MapNavigationButtons';
Expand All @@ -22,26 +22,7 @@ export default function PureMapFooter({
filterSettings,
onFilterMenuClick,
onAddMenuClick,
availableFilterSettings = {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a duplicated part of a selector migration, also locationEnum should be phased out for typescript versions.

area: [
locationEnum.barn,
locationEnum.ceremonial_area,
locationEnum.farm_site_boundary,
locationEnum.field,
locationEnum.garden,
locationEnum.greenhouse,
locationEnum.surface_water,
locationEnum.natural_area,
locationEnum.residence,
],
line: [locationEnum.buffer_zone, locationEnum.watercourse, locationEnum.fence],
point: [
locationEnum.gate,
locationEnum.water_valve,
locationEnum.soil_sample_location,
locationEnum.sensor,
],
},
availableFilterSettings = MAP_LOCATION_TYPE_BY_FIGURE,
isMapFilterSettingActive = false,
isCompactSideMenu,
isOffline,
Expand Down
6 changes: 6 additions & 0 deletions packages/webapp/src/components/MapDrawer/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { ReactComponent as Gate } from '../../assets/images/farmMapFilter/Gate.s
import { ReactComponent as SoilSampleLocation } from '../../assets/images/farmMapFilter/SoilSampleLocation.svg';
import { ReactComponent as WaterValve } from '../../assets/images/farmMapFilter/WaterValve.svg';
import { ReactComponent as Sensor } from '../../assets/images/farmMapFilter/Sensor.svg';
import { ReactComponent as SensorArray } from '../../assets/images/farmMapFilter/SensorArray.svg';
import { useTranslation } from 'react-i18next';
import PropTypes from 'prop-types';
import { locationEnum } from '../../containers/Map/constants';
Expand Down Expand Up @@ -142,6 +143,11 @@ export default function MapDrawer({
icon: () => <Sensor style={{ transform: 'translate(-5px, 5px)' }} />,
key: locationEnum.sensor,
},
{
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Part of the sensors vs sensor array being filtered separately discussion with Loic.

name: t('FARM_MAP.MAP_FILTER.SENSOR_ARRAY'),
icon: () => <SensorArray />,
key: locationEnum.sensor_array,
},
{
name: t('FARM_MAP.MAP_FILTER.SOIL_SAMPLE_LOCATION'),
icon: () => <SoilSampleLocation />,
Expand Down
40 changes: 40 additions & 0 deletions packages/webapp/src/components/Modals/LoadingMapModal/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2025 LiteFarm.org
* This file is part of LiteFarm.
*
* LiteFarm is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LiteFarm is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details, see <https://www.gnu.org/licenses/>.
*/

import { useTranslation } from 'react-i18next';
import styles from './styles.module.scss';
import { Main } from '../../Typography';
import { Loading } from '../../Loading/Loading';
import { Dialog } from '@mui/material';
import { makeStyles } from '@mui/styles';

const useStyles = makeStyles((_theme) => ({
paper: (_props) => ({
overflow: 'inherit',
}),
}));

export default function LoadingMapModal({ isOpen }: { isOpen: boolean }) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This temporary component will be deleted with part 2 where I implement Loic's loading design.

const { t } = useTranslation();
const classes = useStyles();
return (
<Dialog PaperProps={{ className: classes.paper }} open={isOpen} scroll="paper">
<div className={styles.container}>
<Loading />
<Main>{t('FARM_MAP.ASSETS_LOADING')}</Main>
</div>
</Dialog>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright 2025 LiteFarm.org
* This file is part of LiteFarm.
*
* LiteFarm is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LiteFarm is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details, see <https://www.gnu.org/licenses/>.
*/

.container {
display: flex;
// align-items: center;
flex-direction: column;
max-width: 312px;
width: 90vw;
// height: 320px;
background: #fafafd;
border-radius: 7.05466px;
position: relative;
padding: 24px;
}

.button {
margin-top: 24px;
box-shadow: 0px 2px 4px rgba(102, 115, 138, 0.3);
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;

.downloadSvg {
stroke: var(--labels);
margin-right: 4px;
}

.mailSvg {
stroke: var(--labels);
margin-right: 8px;
font-size: 18px;
}
}

.button:active {
box-shadow: none;
color: var(--grey900);
border-color: var(--grey600);

.svg {
stroke: var(--grey900);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { type ProductId, TASK_PRODUCT_FIELD_NAMES } from './types';
import type { SoilAmendmentProduct } from '../../../store/api/types';
import { ReactComponent as PlusCircleIcon } from '../../../assets/images/plus-circle.svg';
import styles from './styles.module.scss';
import { Location } from './QuantityApplicationRate';
import { FlattenedInternalArea } from '../../../hooks/location/types';

export type AddSoilAmendmentProductsProps = Pick<
ProductCardProps,
Expand All @@ -32,7 +32,7 @@ export type AddSoilAmendmentProductsProps = Pick<
products: SoilAmendmentProduct[];
purposes?: { id: number; key: string }[];
fertiliserTypes?: { id: number; key: string }[];
locations: Location[];
locations: FlattenedInternalArea[];
};

interface ProductFields {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useMemo, useState, useRef } from 'react';
import { useEffect, useMemo, useState } from 'react';
import { Label, Underlined } from '../../Typography';
import { useTranslation } from 'react-i18next';
import { Controller } from 'react-hook-form';
Expand All @@ -16,8 +16,8 @@ import WaterUsageCalculatorModal from '../../Modals/WaterUsageCalculatorModal';
import { getIrrigationTaskTypes } from '../../../containers/Task/IrrigationTaskTypes/saga';
import { useDispatch, useSelector } from 'react-redux';
import { irrigationTaskTypesSliceSelector } from '../../../containers/irrigationTaskTypesSlice';
import { cropLocationsSelector } from '../../../containers/locationSlice';
import { BsFillExclamationCircleFill } from 'react-icons/bs';
import useCropLocations from '../../../hooks/location/useCropLocations';

export const generateIrrigationTypeOption = (type, defaultTypes, t) => {
return {
Expand Down Expand Up @@ -51,7 +51,7 @@ export default function PureIrrigationTask({
const [showWaterUseCalculatorModal, setShowWaterUseCalculatorModal] = useState(false);
const irrigationTaskTypes =
useSelector(irrigationTaskTypesSliceSelector)?.irrigationTaskTypes || [];
const cropLocations = useSelector(cropLocationsSelector);
const { locations: cropLocations } = useCropLocations();
const location =
locations?.length &&
cropLocations.filter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
*/

import { useTranslation } from 'react-i18next';
import { useSelector } from 'react-redux';
import { Controller, FormProvider, UseFormReturn } from 'react-hook-form';
import {
useGetSoilAmendmentMethodsQuery,
Expand All @@ -28,10 +27,11 @@ import Unit from '../../Form/Unit';
import AddSoilAmendmentProducts from '../AddSoilAmendmentProducts';
import { type ProductCardProps } from '../AddSoilAmendmentProducts/ProductCard';
import { MolecularCompound, Nutrients, TASK_FIELD_NAMES } from '../AddSoilAmendmentProducts/types';
import type { SoilAmendmentProduct } from '../../../store/api/types';
import type { SoilAmendmentProduct, WithLocationId } from '../../../store/api/types';
import { furrow_hole_depth } from '../../../util/convert-units/unit';
import styles from './styles.module.scss';
import { locationsSelector } from '../../../containers/locationSlice';
import useLocationsById from '../../../hooks/location/useLocationsById';
import { FlattenedInternalArea } from '../../../hooks/location/types';

// Return products in inventory plus removed ones already used in the task.
const getAvailableProducts = (
Expand All @@ -46,10 +46,10 @@ type PureSoilAmendmentTaskProps = UseFormReturn &
Pick<ProductCardProps, 'farm' | 'system' | 'products'> & {
disabled: boolean;
task?: {
locations: { location_id: number }[];
locations: FlattenedInternalArea[];
soil_amendment_task_products: SoilAmendmentProduct[];
};
locations: { location_id: number }[];
locations: WithLocationId[];
};

export const hasNoValue = (
Expand Down Expand Up @@ -79,9 +79,7 @@ const PureSoilAmendmentTask = ({

const { task, locations: propLocations } = props;
const taskLocationIds = (task?.locations || propLocations)?.map(({ location_id }) => location_id);
const locations = useSelector(locationsSelector).filter(({ location_id }) =>
taskLocationIds?.includes(location_id),
);
const { locations = [] } = useLocationsById<FlattenedInternalArea>(taskLocationIds);

const { data: methods = [] } = useGetSoilAmendmentMethodsQuery();
const { data: purposes = [] } = useGetSoilAmendmentPurposesQuery();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@ import { AnimalOrBatchKeys } from '../types';
import { generateInventoryId } from '../../../util/animal';
import { AnimalTypeIconKey, isAnimalTypeIconKey } from '../../../components/Icons/icons';
import { createSingleAnimalViewURL } from '../../../util/siteMapConstants';
import { useSelector } from 'react-redux';
import { locationsSelector } from '../../locationSlice';
import { Location } from '../../../types';
import { getComparator, orderEnum, animalDescendingComparator } from '../../../util/sort';
import useLocations from '../../../hooks/location/useLocations';

export type AnimalInventoryItem = {
id: string;
Expand Down Expand Up @@ -276,7 +274,7 @@ export const buildInventory = ({
};

const useAnimalInventory = (showRemoved = false) => {
const { data, isLoading } = useQueries([
const { data, isLoading: isLoadingAnimalsData } = useQueries([
{ label: 'animals', hook: useGetAnimalsQuery },
{ label: 'animalBatches', hook: useGetAnimalBatchesQuery },
{ label: 'customAnimalBreeds', hook: useGetCustomAnimalBreedsQuery },
Expand All @@ -295,12 +293,14 @@ const useAnimalInventory = (showRemoved = false) => {
defaultAnimalTypes,
} = data;

const locations: Location[] = useSelector(locationsSelector);
const { locations, isLoading: isLoadingLocations } = useLocations();
const locationsMap = locations?.reduce(
(map, { location_id, name }) => ({ ...map, [location_id]: name }),
{},
);

const isLoading = isLoadingAnimalsData || isLoadingLocations;

const inventory = useMemo(() => {
if (isLoading) {
return [];
Expand Down
Loading
Loading