Browse Source

validate gute nest data

pull/1/head
Angelo DiNardi 3 years ago
parent
commit
208f024ffd
  1. 77
      ui/js/datasheet.jsx
  2. 12
      ui/js/gute-nest-row.jsx
  3. 1
      ui/js/hep-nest-row.jsx

77
ui/js/datasheet.jsx

@ -546,22 +546,52 @@ export const Datasheet = (props: Props) => { @@ -546,22 +546,52 @@ export const Datasheet = (props: Props) => {
// Figure out if this species has invalid data based on focal nest data
// validate these numbers are larger than the focal nest entries.
const speciesFocalNestData = hepNestData.filter(nest => nest.speciesCode === species.code);
const nestCount = speciesFocalNestData.length;
const adultCount = speciesFocalNestData.reduce((acc, val) => {
return acc + val.adultCount;
}, 0);
const youngCount = speciesFocalNestData.reduce((acc, val) => {
return acc + val.chickCount;
}, 0);
const totalNestsInvalid = parseInt(totalNests) < nestCount;
const totalAdultsInvalid = parseInt(totalAdults) < adultCount;
const totalYoungInvalid = parseInt(totalYoung) < youngCount;
if (totalNestsInvalid || totalAdultsInvalid || totalYoungInvalid) {
errors.hepNestData = true;
let totalNestsInvalid = false;
let totalAdultsInvalid = false;
let totalYoungInvalid = false;
// Find any hep records
const hepSpeciesFocalNestData = hepNestData.filter(nest => nest.speciesCode === species.code);
const guteSpeciesFocalNestData = guteNestData.filter(nest => nest.speciesCode === species.code);
let nestCount = hepSpeciesFocalNestData.length;
if (nestCount) {
const adultCount = hepSpeciesFocalNestData.reduce((acc, val) => {
return acc + val.adultCount;
}, 0);
const youngCount = hepSpeciesFocalNestData.reduce((acc, val) => {
return acc + val.chickCount;
}, 0);
totalNestsInvalid = parseInt(totalNests) < nestCount;
totalAdultsInvalid = parseInt(totalAdults) < adultCount;
totalYoungInvalid = parseInt(totalYoung) < youngCount;
if (totalNestsInvalid || totalAdultsInvalid || totalYoungInvalid) {
errors.hepNestData = true;
}
} else if (guteSpeciesFocalNestData.length > 0) {
// Find any gute nests
nestCount = guteSpeciesFocalNestData.reduce((acc, val) => {
return acc + val.stage1Nests;
}, 0);
const adultCount = guteSpeciesFocalNestData.reduce((acc, val) => {
return acc + val.totalAdults;
}, 0);
const youngCount = guteSpeciesFocalNestData.reduce((acc, val) => {
return acc + (val.stage2Chicks || 0) + (val.stage3Chicks || 0) + (val.stage4Chicks || 0);
}, 0);
totalNestsInvalid = (parseInt(totalNests) !== nestCount);
totalAdultsInvalid = (parseInt(totalAdults) !== adultCount);
totalYoungInvalid = (parseInt(totalYoung) !== youngCount);
if (totalNestsInvalid || totalAdultsInvalid || totalYoungInvalid) {
errors.guteNestData = true;
}
}
return (
@ -571,29 +601,29 @@ export const Datasheet = (props: Props) => { @@ -571,29 +601,29 @@ export const Datasheet = (props: Props) => {
<Cell>
<Form.Control
type="number"
isInvalid={totalNestsInvalid}
isInvalid={validated && totalNestsInvalid}
value={totalNests}
onChange={e => updateRecord(e.target.value, undefined, undefined, undefined)}
/>
<Form.Control.Feedback type="invalid">More individual nests reported</Form.Control.Feedback>
<Form.Control.Feedback type="invalid">Doesn't match individual nests reported</Form.Control.Feedback>
</Cell>
<Cell>
<Form.Control
type="number"
isInvalid={totalAdultsInvalid}
isInvalid={validated && totalAdultsInvalid}
value={totalAdults}
onChange={e => updateRecord(undefined, e.target.value, undefined, undefined)}
/>
<Form.Control.Feedback type="invalid">More adults reported</Form.Control.Feedback>
<Form.Control.Feedback type="invalid">Doesn't match adults reported</Form.Control.Feedback>
</Cell>
<Cell>
<Form.Control
type="number"
isInvalid={totalYoungInvalid}
isInvalid={validated && totalYoungInvalid}
value={totalYoung}
onChange={e => updateRecord(undefined, undefined, undefined, e.target.value)}
/>
<Form.Control.Feedback type="invalid">More young reported</Form.Control.Feedback>
<Form.Control.Feedback type="invalid">Doesn't match young reported</Form.Control.Feedback>
</Cell>
<Cell>
<Form.Control
@ -695,6 +725,7 @@ export const Datasheet = (props: Props) => { @@ -695,6 +725,7 @@ export const Datasheet = (props: Props) => {
<HepNestRow
key={`hep-nest-row-${idx}`}
data={item}
validated={validated}
update={data => {
preparedHepNestData[idx] = data;
setHepNestData(preparedHepNestData);
@ -702,6 +733,7 @@ export const Datasheet = (props: Props) => { @@ -702,6 +733,7 @@ export const Datasheet = (props: Props) => {
/>,
)}
</div>
{validated && errors.hepNestData && <Alert variant="danger">Summary data doesn't match nest data.</Alert>}
<br />
<br />
@ -758,6 +790,7 @@ export const Datasheet = (props: Props) => { @@ -758,6 +790,7 @@ export const Datasheet = (props: Props) => {
/>;
})}
</div>
{validated && errors.guteNestData && <Alert variant="danger">Summary data doesn't match nest data.</Alert>}
{missingSubcoloniesFromNests.length > 0 && <Alert variant="danger">Subcolony missing! {missingSubcoloniesFromNests.join(", ")}</Alert>}
<br />

12
ui/js/gute-nest-row.jsx

@ -65,7 +65,7 @@ export const GuteNestRow = (props: {| @@ -65,7 +65,7 @@ export const GuteNestRow = (props: {|
isInvalid={validated && (totalAdults || 0) < (stage0Adults || 0)}
onChange={e => update({
...data,
totalAdults: e.target.value,
totalAdults: parseInt(e.target.value),
})}
/>
</Cell>
@ -75,7 +75,7 @@ export const GuteNestRow = (props: {| @@ -75,7 +75,7 @@ export const GuteNestRow = (props: {|
value={stage0Adults === null ? "" : stage0Adults}
onChange={e => update({
...data,
stage0Adults: e.target.value,
stage0Adults: parseInt(e.target.value),
})}
/>
</Cell>
@ -85,7 +85,7 @@ export const GuteNestRow = (props: {| @@ -85,7 +85,7 @@ export const GuteNestRow = (props: {|
value={stage1Nests === null ? "" : stage1Nests}
onChange={e => update({
...data,
stage1Nests: e.target.value,
stage1Nests: parseInt(e.target.value),
})}
/>
</Cell>
@ -95,7 +95,7 @@ export const GuteNestRow = (props: {| @@ -95,7 +95,7 @@ export const GuteNestRow = (props: {|
value={stage2Chicks === null ? "" : stage2Chicks}
onChange={e => update({
...data,
stage2Chicks: e.target.value,
stage2Chicks: parseInt(e.target.value),
})}
/>
</Cell>
@ -105,7 +105,7 @@ export const GuteNestRow = (props: {| @@ -105,7 +105,7 @@ export const GuteNestRow = (props: {|
value={stage3Chicks === null ? "" : stage3Chicks}
onChange={e => update({
...data,
stage3Chicks: e.target.value,
stage3Chicks: parseInt(e.target.value),
})}
/>
</Cell>
@ -115,7 +115,7 @@ export const GuteNestRow = (props: {| @@ -115,7 +115,7 @@ export const GuteNestRow = (props: {|
value={stage4Chicks === null ? "" : stage4Chicks}
onChange={e => update({
...data,
stage4Chicks: e.target.value,
stage4Chicks: parseInt(e.target.value),
})}
/>
</Cell>

1
ui/js/hep-nest-row.jsx

@ -9,6 +9,7 @@ import type { HepNestRowData } from "./types.js"; @@ -9,6 +9,7 @@ import type { HepNestRowData } from "./types.js";
export const HepNestRow = (props: {|
data: HepNestRowData,
update: (HepNestRowData) => mixed,
validated: boolean,
|}) => {
const {
update,

Loading…
Cancel
Save