Skip to content

Commit

Permalink
address pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mauberti-bc committed Feb 5, 2025
1 parent b2fb691 commit 2dd51f8
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const SurveySpatialAnimal = (props: ISurveySpatialAnimalProps) => {
properties: {}
}
})) ?? [],
popup: (feature) => <SurveySpatialAnimalCapturePopup captureId={`${feature.id}`} />,
popup: (feature) => <SurveySpatialAnimalCapturePopup captureId={String(feature.id)} />,

Check warning on line 71 in app/src/features/surveys/view/survey-spatial/components/animal/SurveySpatialAnimal.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/view/survey-spatial/components/animal/SurveySpatialAnimal.tsx#L71

Added line #L71 was not covered by tests
tooltip: (feature) => <SurveyMapTooltip title="Animal Capture" key={`mortality-tooltip-${feature.id}`} />
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import dayjs from 'dayjs';
import { SurveyMapPopup } from 'features/surveys/view/SurveyMapPopup';
import { useCritterbaseApi } from 'hooks/useCritterbaseApi';
import useDataLoader from 'hooks/useDataLoader';
import { useMemo } from 'react';
import { Popup } from 'react-leaflet';
import { isDefined } from 'utils/Utils';

interface ISurveySpatialAnimalCapturePopupProps {
captureId: string;
Expand All @@ -23,8 +25,10 @@ export const SurveySpatialAnimalCapturePopup = (props: ISurveySpatialAnimalCaptu
const captureDataLoader = useDataLoader(() => critterbaseApi.capture.getCapture(captureId));
const animalDataLoader = useDataLoader(critterbaseApi.critters.getCritterSimple);

Check warning on line 26 in app/src/features/surveys/view/survey-spatial/components/animal/SurveySpatialAnimalCapturePopup.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/view/survey-spatial/components/animal/SurveySpatialAnimalCapturePopup.tsx#L25-L26

Added lines #L25 - L26 were not covered by tests

const formatPopupMetadata = () => {
if (!captureDataLoader.data || !animalDataLoader.data) return [];
const popupMetadata = useMemo(() => {

Check warning on line 28 in app/src/features/surveys/view/survey-spatial/components/animal/SurveySpatialAnimalCapturePopup.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/view/survey-spatial/components/animal/SurveySpatialAnimalCapturePopup.tsx#L28

Added line #L28 was not covered by tests
if (!captureDataLoader.data || !animalDataLoader.data) {
return [];

Check warning on line 30 in app/src/features/surveys/view/survey-spatial/components/animal/SurveySpatialAnimalCapturePopup.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/view/survey-spatial/components/animal/SurveySpatialAnimalCapturePopup.tsx#L30

Added line #L30 was not covered by tests
}

const { capture_date, capture_time, capture_location } = captureDataLoader.data;
const { animal_id } = animalDataLoader.data;

Check warning on line 34 in app/src/features/surveys/view/survey-spatial/components/animal/SurveySpatialAnimalCapturePopup.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/view/survey-spatial/components/animal/SurveySpatialAnimalCapturePopup.tsx#L33-L34

Added lines #L33 - L34 were not covered by tests
Expand All @@ -36,12 +40,12 @@ export const SurveySpatialAnimalCapturePopup = (props: ISurveySpatialAnimalCaptu
{
label: 'Coordinates',
value: [capture_location?.latitude, capture_location?.longitude]
.filter((coord): coord is number => coord !== null)
.filter((coord): coord is number => isDefined(coord))

Check warning on line 43 in app/src/features/surveys/view/survey-spatial/components/animal/SurveySpatialAnimalCapturePopup.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/view/survey-spatial/components/animal/SurveySpatialAnimalCapturePopup.tsx#L43

Added line #L43 was not covered by tests
.map((coord) => coord.toFixed(6))
.join(', ')
}
];
};
}, [captureDataLoader.data, animalDataLoader.data]);

return (
<Popup
Expand All @@ -51,14 +55,16 @@ export const SurveySpatialAnimalCapturePopup = (props: ISurveySpatialAnimalCaptu
eventHandlers={{
add: async () => {
const capture = await captureDataLoader.load();

Check warning on line 57 in app/src/features/surveys/view/survey-spatial/components/animal/SurveySpatialAnimalCapturePopup.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/view/survey-spatial/components/animal/SurveySpatialAnimalCapturePopup.tsx#L57

Added line #L57 was not covered by tests
// Fetch critter information to get the animal's nickname to display, which isn't included in the capture response
if (capture) animalDataLoader.load(capture.critter_id);
// Fetch critter information to get the animal's animal_id to display, which isn't included in the capture response
if (capture) {
animalDataLoader.load(capture.critter_id);

Check warning on line 60 in app/src/features/surveys/view/survey-spatial/components/animal/SurveySpatialAnimalCapturePopup.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/view/survey-spatial/components/animal/SurveySpatialAnimalCapturePopup.tsx#L60

Added line #L60 was not covered by tests
}
}
}}>
<SurveyMapPopup
isLoading={captureDataLoader.isLoading || animalDataLoader.isLoading}
title="Capture Details"
metadata={formatPopupMetadata()}
metadata={popupMetadata}
key={`capture-feature-popup-${captureId}`}
/>
</Popup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import dayjs from 'dayjs';
import { SurveyMapPopup } from 'features/surveys/view/SurveyMapPopup';
import { useCritterbaseApi } from 'hooks/useCritterbaseApi';
import useDataLoader from 'hooks/useDataLoader';
import { useMemo } from 'react';
import { Popup } from 'react-leaflet';
import { isDefined } from 'utils/Utils';

interface ISurveySpatialAnimalMortalityPopupProps {
mortalityId: string;
Expand All @@ -23,8 +25,10 @@ export const SurveySpatialAnimalMortalityPopup = (props: ISurveySpatialAnimalMor
const mortalityDataLoader = useDataLoader(critterbaseApi.mortality.getMortality);
const animalDataLoader = useDataLoader(critterbaseApi.critters.getCritterSimple);

Check warning on line 26 in app/src/features/surveys/view/survey-spatial/components/animal/SurveySpatialAnimalMortalityPopup.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/view/survey-spatial/components/animal/SurveySpatialAnimalMortalityPopup.tsx#L25-L26

Added lines #L25 - L26 were not covered by tests

const formatPopupMetadata = () => {
if (!mortalityDataLoader.data || !animalDataLoader.data) return [];
const popupMetadata = useMemo(() => {

Check warning on line 28 in app/src/features/surveys/view/survey-spatial/components/animal/SurveySpatialAnimalMortalityPopup.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/view/survey-spatial/components/animal/SurveySpatialAnimalMortalityPopup.tsx#L28

Added line #L28 was not covered by tests
if (!mortalityDataLoader.data || !animalDataLoader.data) {
return [];

Check warning on line 30 in app/src/features/surveys/view/survey-spatial/components/animal/SurveySpatialAnimalMortalityPopup.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/view/survey-spatial/components/animal/SurveySpatialAnimalMortalityPopup.tsx#L30

Added line #L30 was not covered by tests
}

const { mortality_timestamp, location } = mortalityDataLoader.data;
const { animal_id } = animalDataLoader.data;

Check warning on line 34 in app/src/features/surveys/view/survey-spatial/components/animal/SurveySpatialAnimalMortalityPopup.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/view/survey-spatial/components/animal/SurveySpatialAnimalMortalityPopup.tsx#L33-L34

Added lines #L33 - L34 were not covered by tests
Expand All @@ -34,17 +38,17 @@ export const SurveySpatialAnimalMortalityPopup = (props: ISurveySpatialAnimalMor
{
label: 'Date',
// Critterbase does not provide time as its own string so mortalities without time data will erroneously show 12:00 AM in the popup
value: dayjs(mortality_timestamp).format(DATE_FORMAT.MediumDateTimeFormat)
value: dayjs(mortality_timestamp).format(DATE_FORMAT.LongDateTimeFormat)
},
{
label: 'Coordinates',
value: [location?.latitude, location?.longitude]
.filter(Boolean)
.map((coord) => coord!.toFixed(6))
.filter((coord): coord is number => isDefined(coord))

Check warning on line 46 in app/src/features/surveys/view/survey-spatial/components/animal/SurveySpatialAnimalMortalityPopup.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/view/survey-spatial/components/animal/SurveySpatialAnimalMortalityPopup.tsx#L46

Added line #L46 was not covered by tests
.map((coord) => coord.toFixed(6))
.join(', ')
}
];
};
}, [mortalityDataLoader.data, animalDataLoader.data]);

return (
<Popup
Expand All @@ -54,13 +58,15 @@ export const SurveySpatialAnimalMortalityPopup = (props: ISurveySpatialAnimalMor
eventHandlers={{
add: async () => {
const mortality = await mortalityDataLoader.load(mortalityId);

Check warning on line 60 in app/src/features/surveys/view/survey-spatial/components/animal/SurveySpatialAnimalMortalityPopup.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/view/survey-spatial/components/animal/SurveySpatialAnimalMortalityPopup.tsx#L60

Added line #L60 was not covered by tests
if (mortality) animalDataLoader.load(mortality.critter_id);
if (mortality) {
animalDataLoader.load(mortality.critter_id);

Check warning on line 62 in app/src/features/surveys/view/survey-spatial/components/animal/SurveySpatialAnimalMortalityPopup.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/view/survey-spatial/components/animal/SurveySpatialAnimalMortalityPopup.tsx#L62

Added line #L62 was not covered by tests
}
}
}}>
<SurveyMapPopup
isLoading={mortalityDataLoader.isLoading || animalDataLoader.isLoading}
title="Mortality Details"
metadata={formatPopupMetadata()}
metadata={popupMetadata}
key={`mortality-feature-popup-${mortalityId}`}
/>
</Popup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { ScientificNameTypography } from 'features/surveys/animals/components/Sc
import { useSurveyContext } from 'hooks/useContext';
import { useCritterbaseApi } from 'hooks/useCritterbaseApi';
import useDataLoader from 'hooks/useDataLoader';
import { useEffect } from 'react';
import { useEffect, useMemo } from 'react';

const rowHeight = 52;

Expand All @@ -39,17 +39,18 @@ export const SurveySpatialAnimalTable = (props: ISurveyDataAnimalTableProps) =>

const { critterDataLoader } = useSurveyContext();

Check warning on line 40 in app/src/features/surveys/view/survey-spatial/components/animal/SurveySpatialAnimalTable.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/view/survey-spatial/components/animal/SurveySpatialAnimalTable.tsx#L40

Added line #L40 was not covered by tests
const critterbaseApi = useCritterbaseApi();
const animals = critterDataLoader.data ?? [];

const animals = useMemo(() => critterDataLoader.data ?? [], [critterDataLoader.data]);

const animalsDataLoader = useDataLoader(() =>
critterbaseApi.critters.getMultipleCrittersByIds(
animals.map(({ critterbase_critter_id }) => critterbase_critter_id)
)
critterbaseApi.critters.getMultipleCrittersByIds(animals.map((animal) => animal.critterbase_critter_id))
);

useEffect(() => {

Check warning on line 49 in app/src/features/surveys/view/survey-spatial/components/animal/SurveySpatialAnimalTable.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/view/survey-spatial/components/animal/SurveySpatialAnimalTable.tsx#L49

Added line #L49 was not covered by tests
if (animals.length) animalsDataLoader.load();
}, [animals]);
if (animals.length) {
animalsDataLoader.load();

Check warning on line 51 in app/src/features/surveys/view/survey-spatial/components/animal/SurveySpatialAnimalTable.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/view/survey-spatial/components/animal/SurveySpatialAnimalTable.tsx#L51

Added line #L51 was not covered by tests
}
}, [animals, animalsDataLoader]);

const rows: IAnimalRow[] =
animalsDataLoader.data?.map((animal) => ({
Expand Down

0 comments on commit 2dd51f8

Please sign in to comment.