Skip to content

Commit

Permalink
#263 Add child sample distance warning
Browse files Browse the repository at this point in the history
  • Loading branch information
kazlauskis committed Nov 10, 2023
1 parent 58ca75d commit e7d6068
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 21 deletions.
45 changes: 42 additions & 3 deletions 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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"@ionic/react-router": "7.3.3",
"@sentry/browser": "7.68.0",
"@sentry/integrations": "7.68.0",
"@turf/distance": "^6.5.0",
"axios": "1.5.0",
"clsx": "2.0.0",
"cordova-launch-review": "4.0.1",
Expand Down
26 changes: 18 additions & 8 deletions src/Survey/List/Home/Main/index.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
import { FC } from 'react';
import { observer } from 'mobx-react';
import { Trans as T } from 'react-i18next';
import { useRouteMatch } from 'react-router';
import { InfoMessage, Main } from '@flumens';
import { IonButton, IonLabel, IonList } from '@ionic/react';
import { Main } from '@flumens';
import MenuDynamicAttrs from 'Survey/common/Components/MenuDynamicAttrs';
import MenuAttr from 'Survey/common/Components/MenuAttr';
import Sample from 'models/sample';
import DisabledRecordMessage from 'Survey/common/Components/DisabledRecordMessage';
import MenuAttr from 'Survey/common/Components/MenuAttr';
import MenuDynamicAttrs from 'Survey/common/Components/MenuDynamicAttrs';
import SpeciesList from 'Survey/common/Components/SpeciesList';
import Sample from 'models/sample';
import { useRouteMatch } from 'react-router';
import { Trans as T } from 'react-i18next';
import './styles.scss';

type Props = {
sample: Sample;
onDelete: any;
showChildSampleDistanceWarning: boolean;
};

const HomeMain: FC<Props> = ({ sample, onDelete }) => {
const HomeMain = ({
sample,
onDelete,
showChildSampleDistanceWarning,
}: Props) => {
const { url } = useRouteMatch();

// calculate unique taxa
Expand Down Expand Up @@ -51,6 +55,12 @@ const HomeMain: FC<Props> = ({ sample, onDelete }) => {
)}

<div className="rounded">
{showChildSampleDistanceWarning && (
<InfoMessage color="warning">
Some species are located far from the survey area. Please check
that this is correct.
</InfoMessage>
)}
<MenuDynamicAttrs model={sample} skipLocks />
</div>
</IonList>
Expand Down
23 changes: 21 additions & 2 deletions src/Survey/List/Home/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { FC, useContext } from 'react';
import { observer } from 'mobx-react';
import { Page, Header, useToast } from '@flumens';
import { NavContext } from '@ionic/react';
import distance from '@turf/distance';
import Sample, { useValidateCheck } from 'models/sample';
import { useUserStatusCheck } from 'models/user';
import { Page, Header, useToast } from '@flumens';
import AppHeaderBand from 'Survey/common/Components/AppHeaderBand';
import PrimaryHeaderButton from 'Survey/common/Components/PrimaryHeaderButton';
import Main from './Main';
Expand Down Expand Up @@ -57,6 +58,20 @@ const ListHome: FC<Props> = ({ sample }) => {

const subheader = !!training && <AppHeaderBand training />;

const { location } = sample.attrs;

const isLocationFurtherThan5000m = (smp: Sample) =>
distance(
[location.latitude, location.longitude],
[smp.attrs.location.latitude, smp.attrs.location.longitude],
{
units: 'meters',
}
) > 5000;
const showChildSampleDistanceWarning = sample.samples.some(
isLocationFurtherThan5000m
);

return (
<Page id="survey-complex-default-edit">
<Header
Expand All @@ -65,7 +80,11 @@ const ListHome: FC<Props> = ({ sample }) => {
defaultHref="/home/surveys"
subheader={subheader}
/>
<Main sample={sample} onDelete={onSubSampleDelete} />
<Main
sample={sample}
onDelete={onSubSampleDelete}
showChildSampleDistanceWarning={showChildSampleDistanceWarning}
/>
</Page>
);
};
Expand Down
24 changes: 17 additions & 7 deletions src/Survey/Plant/Home/Main/index.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
import { FC } from 'react';
import { observer } from 'mobx-react';
import { Trans as T } from 'react-i18next';
import { useRouteMatch } from 'react-router';
import { InfoMessage, Main } from '@flumens';
import { IonButton, IonLabel, IonList } from '@ionic/react';
import MenuDynamicAttrs from 'Survey/common/Components/MenuDynamicAttrs';
import Sample from 'models/sample';
import DisabledRecordMessage from 'Survey/common/Components/DisabledRecordMessage';
import MenuDynamicAttrs from 'Survey/common/Components/MenuDynamicAttrs';
import SpeciesList from 'Survey/common/Components/SpeciesList';
import { Main } from '@flumens';
import Sample from 'models/sample';
import { useRouteMatch } from 'react-router';
import { Trans as T } from 'react-i18next';
import './styles.scss';

type Props = {
sample: Sample;
onDelete: any;
showChildSampleDistanceWarning: boolean;
};

const PlantHomeMain: FC<Props> = ({ sample, onDelete }) => {
const PlantHomeMain = ({
sample,
onDelete,
showChildSampleDistanceWarning,
}: Props) => {
const { url } = useRouteMatch();

const isDisabled = sample.isDisabled();
Expand All @@ -30,6 +34,12 @@ const PlantHomeMain: FC<Props> = ({ sample, onDelete }) => {
)}

<div className="rounded">
{showChildSampleDistanceWarning && (
<InfoMessage color="warning">
Some species are located far from the survey area. Please check
that this is correct.
</InfoMessage>
)}
<MenuDynamicAttrs model={sample} skipLocks />
</div>
</IonList>
Expand Down
21 changes: 20 additions & 1 deletion src/Survey/Plant/Home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
InfoButton,
} from '@flumens';
import { NavContext, IonToolbar, isPlatform } from '@ionic/react';
import distance from '@turf/distance';
import appModel from 'models/app';
import Sample, { useValidateCheck } from 'models/sample';
import { useUserStatusCheck } from 'models/user';
Expand Down Expand Up @@ -123,6 +124,20 @@ const PlantHome: FC<Props> = ({ sample }) => {
</div>
);

const { location } = sample.attrs;

const isLocationFurtherThan5000m = (smp: Sample) =>
distance(
[location.latitude, location.longitude],
[smp.attrs.location.latitude, smp.attrs.location.longitude],
{
units: 'meters',
}
) > 5000;
const showChildSampleDistanceWarning = sample.samples.some(
isLocationFurtherThan5000m
);

return (
<Page id="survey-complex-plant-edit">
<Header
Expand All @@ -131,7 +146,11 @@ const PlantHome: FC<Props> = ({ sample }) => {
defaultHref="/home/surveys"
subheader={subheader}
/>
<Main sample={sample} onDelete={onSubSampleDelete} />
<Main
sample={sample}
onDelete={onSubSampleDelete}
showChildSampleDistanceWarning={showChildSampleDistanceWarning}
/>
</Page>
);
};
Expand Down

0 comments on commit e7d6068

Please sign in to comment.