Get some validation in order

pull/1/head
Angelo DiNardi 3 years ago
parent 7fe8ca8703
commit cf6ffd5699
  1. 1
      package.json
  2. 48
      ui/js/datasheet.jsx
  3. 2
      ui/js/gute-nest-location-row.jsx
  4. 70
      yarn.lock

@ -41,6 +41,7 @@
"react-bootstrap": "^1.0.0-beta.14",
"react-dom": "^16.10.2",
"react-router-dom": "^5.1.2",
"react-time-picker": "^3.8.0",
"whatwg-fetch": "^3.0.0"
},
"engines": {

@ -7,6 +7,8 @@ import Row from "react-bootstrap/Row";
import Col from "react-bootstrap/Col";
import Button from "react-bootstrap/Button";
import "whatwg-fetch";
import TimePicker from "react-time-picker";
import Alert from "react-bootstrap/Alert";
import { Cell, HeaderInfoCell } from "./cell.jsx";
import { HepNestRow } from "./hep-nest-row.jsx";
@ -105,6 +107,7 @@ type SurveySummaryData = {
export const Datasheet = (props: Props) => {
let speciesCounter = 3;
const [validated, setValidated] = useState(false);
const [savingData, setSavingData] = useState(false);
const [colonies, setColonies] = useState<Array<{
id: number,
@ -147,6 +150,8 @@ export const Datasheet = (props: Props) => {
return;
}
setValidated(true);
const saveToServer = async() => {
try {
const response = await fetch(`${API_HOST}/data/sheet/save`, {
@ -239,6 +244,23 @@ export const Datasheet = (props: Props) => {
});
}
// Do data validation to ensure gute nest and location data has the same subcolonies
const guteNestSubcolonies = guteNestData.map(item => item.subcolony);
const guteLocationSubcolonies = guteNestLocationData.map(item => item.subcolony);
const missingSubcoloniesFromNests = guteLocationSubcolonies.filter(item => {
if (guteNestSubcolonies.findIndex(s => s === item) > -1) {
return false;
}
return true;
});
const missingSubcoloniesFromLocations = guteNestSubcolonies.filter(item => {
if (guteLocationSubcolonies.findIndex(s => s === item) > -1) {
return false;
}
return true;
});
return (
<Container>
<div className="text-center">
@ -249,13 +271,14 @@ export const Datasheet = (props: Props) => {
<p>Please use a separate form for every visit. Do not summarize visits here.</p>
</div>
<hr />
<Form>
<Form validated={validated}>
<Form.Group as={Form.Row} controlId="submitter-name">
<Form.Label column sm="2">
Submitter's Name:
</Form.Label>
<Col>
<Form.Control
required
type="text"
onChange={e => setSubmitterName(e.target.value)}
value={submitterName}
@ -268,6 +291,7 @@ export const Datasheet = (props: Props) => {
</Form.Label>
<Col>
<Form.Control
required
as="select"
id="colony-id"
onChange={e => setColonyId(e.target.value)}
@ -284,6 +308,7 @@ export const Datasheet = (props: Props) => {
</Form.Label>
<Col>
<Form.Control
required
type="date"
id="datasheet-date"
value={date}
@ -306,22 +331,22 @@ export const Datasheet = (props: Props) => {
Start time:
</Form.Label>
<Col>
<Form.Control
type="text"
id="start-time"
<TimePicker
required
disableClock
value={startTime}
onChange={e => setStartTime(e.target.value)}
onChange={e => setStartTime(e || "")}
/>
</Col>
<Form.Label column sm="2" htmlFor="end-time">
End time:
</Form.Label>
<Col>
<Form.Control
type="text"
id="end-time"
<TimePicker
required
disableClock
value={endTime}
onChange={e => setEndTime(e.target.value)}
onChange={e => setEndTime(e || "")}
/>
</Col>
</Form.Group>
@ -332,6 +357,7 @@ export const Datasheet = (props: Props) => {
</Form.Label>
<Col>
<Form.Check
required
inline
label="Good"
type="radio"
@ -342,6 +368,7 @@ export const Datasheet = (props: Props) => {
/>
<Form.Check
inline
required
label="Moderate"
type="radio"
id="vis-check-mod"
@ -350,6 +377,7 @@ export const Datasheet = (props: Props) => {
checked={nestVisibility === "moderate"}
/>
<Form.Check
required
inline
label="Poor"
type="radio"
@ -659,6 +687,7 @@ export const Datasheet = (props: Props) => {
/>,
)}
</div>
{missingSubcoloniesFromNests.length > 0 && <Alert variant="danger">Subcolony missing! {missingSubcoloniesFromNests}</Alert>}
<br />
<br />
@ -680,6 +709,7 @@ export const Datasheet = (props: Props) => {
/>,
)}
</div>
{missingSubcoloniesFromLocations.length > 0 && <Alert variant="danger">Subcolony missing! {missingSubcoloniesFromLocations}</Alert>}
<Button disabled={savingData} onClick={() => setSavingData(true)}>Save</Button>
</Container>

@ -31,6 +31,7 @@ export const GuteNestLocationRow = (props: {|
...data,
subcolony: e.target.value,
})}
isInvalid={!subcolony && (location || includedOnMap)}
/>
</Cell>
<Cell>
@ -41,6 +42,7 @@ export const GuteNestLocationRow = (props: {|
...data,
location: e.target.value,
})}
isInvalid={!location && (subcolony || includedOnMap)}
/>
</Cell>
<Cell>

@ -911,6 +911,11 @@
"@types/prop-types" "*"
csstype "^2.2.0"
"@wojtekmaj/date-utils@^1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@wojtekmaj/date-utils/-/date-utils-1.0.0.tgz#97aebf5ab317cf40d56492642f921480d4f89342"
integrity sha512-tHzSlWCmb1GjxjiPRTju7i2bQigYriFDmCpaf1dC4SebFRjhBiuRpIxy5oI3b3ZMg9OzqGnApdZJrlYSwEUJAg==
abab@^2.0.0:
version "2.0.2"
resolved "https://registry.yarnpkg.com/abab/-/abab-2.0.2.tgz#a2fba1b122c69a85caa02d10f9270c7219709a9d"
@ -2731,6 +2736,11 @@ destroy@~1.0.4:
resolved "https://registry.yarnpkg.com/destroy/-/destroy-1.0.4.tgz#978857442c44749e4206613e37946205826abd80"
integrity sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=
detect-element-overflow@^1.1.1:
version "1.2.0"
resolved "https://registry.yarnpkg.com/detect-element-overflow/-/detect-element-overflow-1.2.0.tgz#86e504292ffedc3aef813395fbdf0261aaf6afa9"
integrity sha512-Jtr9ivYPhpd9OJux+hjL0QjUKiS1Ghgy8tvIufUjFslQgIWvgGr4mn57H190APbKkiOmXnmtMI6ytaKzMusecg==
detect-libc@^1.0.2:
version "1.0.3"
resolved "https://registry.yarnpkg.com/detect-libc/-/detect-libc-1.0.3.tgz#fa137c4bd698edf55cd5cd02ac559f91a4c4ba9b"
@ -3574,6 +3584,13 @@ get-stream@^4.0.0:
dependencies:
pump "^3.0.0"
get-user-locale@^1.2.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/get-user-locale/-/get-user-locale-1.3.0.tgz#21ea740e413541281ae7b2b42e70ee523b7725b2"
integrity sha512-c5N8P0upjxCF9unIC2vTA+B+8nN7kU/D/TeItMAVYhWIIksyoULM1aflKflXM3w+Ij6vF/JZys+QcwIoDuy3Ag==
dependencies:
lodash.once "^4.1.1"
get-value@^2.0.3, get-value@^2.0.6:
version "2.0.6"
resolved "https://registry.yarnpkg.com/get-value/-/get-value-2.0.6.tgz#dc15ca1c672387ca76bd37ac0a395ba2042a2c28"
@ -4573,6 +4590,11 @@ lodash.memoize@^4.1.2:
resolved "https://registry.yarnpkg.com/lodash.memoize/-/lodash.memoize-4.1.2.tgz#bcc6c49a42a2840ed997f323eada5ecd182e0bfe"
integrity sha1-vMbEmkKihA7Zl/Mj6tpezRguC/4=
lodash.once@^4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/lodash.once/-/lodash.once-4.1.1.tgz#0dd3971213c7c56df880977d504c88fb471a97ac"
integrity sha1-DdOXEhPHxW34gJd9UEyI+0cal6w=
lodash.set@^4.3.2:
version "4.3.2"
resolved "https://registry.yarnpkg.com/lodash.set/-/lodash.set-4.3.2.tgz#d8757b1da807dde24816b0d6a84bea1a76230b23"
@ -4629,6 +4651,11 @@ magic-string@^0.22.4:
dependencies:
vlq "^0.2.2"
make-event-props@^1.1.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/make-event-props/-/make-event-props-1.2.0.tgz#96b87d88919533b8f8934b58b4c3d5679459a0cf"
integrity sha512-BmWFkm/jZzVH9A0tEBdkjAARUz/eha+5IRyfOndeSMKRadkgR5DawoBHoRwLxkYmjJOI5bHkXKpaZocxj+dKgg==
map-age-cleaner@^0.1.1:
version "0.1.3"
resolved "https://registry.yarnpkg.com/map-age-cleaner/-/map-age-cleaner-0.1.3.tgz#7d583a7306434c055fe474b0f45078e6e1b4b92a"
@ -4680,6 +4707,11 @@ mem@^4.0.0:
mimic-fn "^2.0.0"
p-is-promise "^2.0.0"
merge-class-names@^1.1.1:
version "1.3.0"
resolved "https://registry.yarnpkg.com/merge-class-names/-/merge-class-names-1.3.0.tgz#c4cdc1a981a81dd9afc27aa4287e912a337c5dee"
integrity sha512-k0Qaj36VBpKgdc8c188LEZvo6v/zzry/FUufwopWbMSp6/knfVFU/KIB55/hJjeIpg18IH2WskXJCRnM/1BrdQ==
merge-source-map@1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/merge-source-map/-/merge-source-map-1.0.4.tgz#a5de46538dae84d4114cc5ea02b4772a6346701f"
@ -5956,7 +5988,7 @@ prop-types-extra@^1.1.0:
react-is "^16.3.2"
warning "^3.0.0"
prop-types@^15.6.1, prop-types@^15.6.2, prop-types@^15.7.2:
prop-types@^15.6.0, prop-types@^15.6.1, prop-types@^15.6.2, prop-types@^15.7.2:
version "15.7.2"
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.7.2.tgz#52c41e75b8c87e72b9d9360e0206b99dcbffa6c5"
dependencies:
@ -6103,6 +6135,14 @@ react-bootstrap@^1.0.0-beta.14:
uncontrollable "^7.0.0"
warning "^4.0.3"
react-clock@^2.3.0:
version "2.4.0"
resolved "https://registry.yarnpkg.com/react-clock/-/react-clock-2.4.0.tgz#39540f84e16f8b2c2137640f535c162041bd2a1e"
integrity sha512-BlzkzbhLEzLwdqtl+PAPvzMhRvg4xyxsiQnGpb+ZzL4YY5iFQgJa7C48EUGhbpnTtNwyMuaBG4KeYmUuUlTQUQ==
dependencies:
merge-class-names "^1.1.1"
prop-types "^15.6.0"
react-context-toolbox@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/react-context-toolbox/-/react-context-toolbox-2.0.2.tgz#35637287cb23f801e6ed802c2bb7a97e1f04e3fb"
@ -6118,6 +6158,14 @@ react-dom@^16.10.2:
prop-types "^15.6.2"
scheduler "^0.17.0"
react-fit@^1.0.3:
version "1.0.5"
resolved "https://registry.yarnpkg.com/react-fit/-/react-fit-1.0.5.tgz#971490a2e15613712596d9fdad549293d3d30684"
integrity sha512-TTR/nfFi0d+pJ1ukoKXjd22a9dVbAXFf7IVjny3RIzoI7gt4y26jHds8GHY8jWRy3kDNpQyrC70JOVnkmxoebw==
dependencies:
detect-element-overflow "^1.1.1"
prop-types "^15.6.0"
react-is@^16.3.2, react-is@^16.6.0, react-is@^16.7.0:
version "16.10.2"
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.10.2.tgz#984120fd4d16800e9a738208ab1fba422d23b5ab"
@ -6187,6 +6235,21 @@ react-router@5.1.2:
tiny-invariant "^1.0.2"
tiny-warning "^1.0.0"
react-time-picker@^3.8.0:
version "3.8.0"
resolved "https://registry.yarnpkg.com/react-time-picker/-/react-time-picker-3.8.0.tgz#77c6ee6b76711b707ccc99996662d22dfc49869d"
integrity sha512-NL0+kCZWL1vmh+1Hybn8LcAOpa5S+QavQu2+rQpVM8llksqfQQXlc/E8AICZcNeoBoG9ZikAvoTUIeIUhbgMgQ==
dependencies:
"@wojtekmaj/date-utils" "^1.0.0"
get-user-locale "^1.2.0"
make-event-props "^1.1.0"
merge-class-names "^1.1.1"
prop-types "^15.6.0"
react-clock "^2.3.0"
react-fit "^1.0.3"
react-lifecycles-compat "^3.0.4"
update-input-width "^1.1.1"
react-transition-group@^4.0.0:
version "4.3.0"
resolved "https://registry.yarnpkg.com/react-transition-group/-/react-transition-group-4.3.0.tgz#fea832e386cf8796c58b61874a3319704f5ce683"
@ -7427,6 +7490,11 @@ upath@^1.1.1:
resolved "https://registry.yarnpkg.com/upath/-/upath-1.2.0.tgz#8f66dbcd55a883acdae4408af8b035a5044c1894"
integrity sha512-aZwGpamFO61g3OlfT7OQCHqhGnW43ieH9WZeP7QxN/G/jS4jfqUkZxoryvJgVPEcrl5NL/ggHsSmLMHuH64Lhg==
update-input-width@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/update-input-width/-/update-input-width-1.1.1.tgz#075cad85e20f542a5eccc216937ab8d57a1ab892"
integrity sha512-khNPvsmV9CJbvOlK0Wou2FLPNcKFQepq5yKHyClxz39A3TTkCkkDOOdOs1xoMNWKTesN+qQALffoNP4P8Jydgw==
uri-js@^4.2.2:
version "4.2.2"
resolved "https://registry.yarnpkg.com/uri-js/-/uri-js-4.2.2.tgz#94c540e1ff772956e2299507c010aea6c8838eb0"

Loading…
Cancel
Save