From 5dca5fb087f4b3eefae50535e3ee7950ecdd63b8 Mon Sep 17 00:00:00 2001 From: Hannah Livnat Date: Fri, 14 Aug 2020 16:29:59 -0700 Subject: [PATCH 01/18] added * message and asterisks to all required fields --- client/components/main/menu/Menu.jsx | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/client/components/main/menu/Menu.jsx b/client/components/main/menu/Menu.jsx index 615ccc232..b36a215ce 100644 --- a/client/components/main/menu/Menu.jsx +++ b/client/components/main/menu/Menu.jsx @@ -71,8 +71,10 @@ const Menu = ({

Comparison Filters

+

* Indicates to make at least one selection

+

Filters

+

* Indicates to make at least one selection

Date: Fri, 14 Aug 2020 16:55:16 -0700 Subject: [PATCH 02/18] started working on error boundaries and messaging. Added formerrorcomponent, starting to work on error messaging within handleSubmit function to combine the handleSubmit and submitbutton disabling logic --- client/components/common/FormErrorMessage.jsx | 9 +++++++ client/components/main/menu/Submit.jsx | 25 ++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 client/components/common/FormErrorMessage.jsx diff --git a/client/components/common/FormErrorMessage.jsx b/client/components/common/FormErrorMessage.jsx new file mode 100644 index 000000000..46fe28da6 --- /dev/null +++ b/client/components/common/FormErrorMessage.jsx @@ -0,0 +1,9 @@ +import React from 'react'; +import PropTypes from 'proptypes'; +import classNames from 'classnames'; + +const FormErrorMessage = ({ + +}) + +export defaul FormErrorMessage; \ No newline at end of file diff --git a/client/components/main/menu/Submit.jsx b/client/components/main/menu/Submit.jsx index b881b28ad..8f438d5fa 100644 --- a/client/components/main/menu/Submit.jsx +++ b/client/components/main/menu/Submit.jsx @@ -17,7 +17,30 @@ const Submit = ({ const handleSubmit = () => { switch (pathname) { - case '/data': return getData(); + case '/data': { + const { + startDate, + endDate, + councils, + requestTypes, + } = filters; + + if (startDate + && endDate + && councils.length > 0 + && Object.values(requestTypes).includes(true)) { + return getData(); + } else { + if(!endDate){ + + } else if(councils.length < 1){ + + } else if(!(Object.values(requestTypes).includes(true))){ + + } + } + break; + } case '/comparison': return getComparisonData(); default: return null; } From 0e2fbc45b05f8f961f982bc4f4063303658934a0 Mon Sep 17 00:00:00 2001 From: Hannah Livnat Date: Sat, 15 Aug 2020 17:10:34 -0700 Subject: [PATCH 03/18] took out submit button disable and added in form validation for data and comparison maps. Currently able to log whether each value is filled out, but currently erroring on submit --- client/components/common/FormErrorMessage.jsx | 9 -- client/components/main/menu/Submit.jsx | 131 +++++++++++------- 2 files changed, 84 insertions(+), 56 deletions(-) delete mode 100644 client/components/common/FormErrorMessage.jsx diff --git a/client/components/common/FormErrorMessage.jsx b/client/components/common/FormErrorMessage.jsx deleted file mode 100644 index 46fe28da6..000000000 --- a/client/components/common/FormErrorMessage.jsx +++ /dev/null @@ -1,9 +0,0 @@ -import React from 'react'; -import PropTypes from 'proptypes'; -import classNames from 'classnames'; - -const FormErrorMessage = ({ - -}) - -export defaul FormErrorMessage; \ No newline at end of file diff --git a/client/components/main/menu/Submit.jsx b/client/components/main/menu/Submit.jsx index 8f438d5fa..14c14084e 100644 --- a/client/components/main/menu/Submit.jsx +++ b/client/components/main/menu/Submit.jsx @@ -13,35 +13,95 @@ const Submit = ({ comparisonFilters, }) => { const { pathname } = useLocation(); - const [disableSubmit, setDisableSubmit] = useState(true); + const [dataErrors, setDataErrors] = useState({ + missingStartDate: false, + missingEndDate: false, + missingCouncils: false, + missingRequestTypes: false + }); + const [comparisonErrors, setComparisonErrors] = useState({ + missingStartDate: false, + missingEndDate: false, + missingChart: false, + missingDistrictOne: false, + missingDistrictTwo: false, + missingRequestTypes: false + }) - const handleSubmit = () => { - switch (pathname) { - case '/data': { - const { - startDate, - endDate, - councils, - requestTypes, - } = filters; + const validateDataForm = () => { + const { + startDate, + endDate, + councils, + requestTypes, + } = filters; + + const noStartDate = (startDate) ? false : true; + const noEndDate = (endDate) ? false : true; + const noCouncils = councils.length <= 0; + const noRequestTypes = !(Object.values(requestTypes).includes(true)); + console.log(`noStartDate is ${noStartDate}, noEndDate is ${noEndDate}, noCouncils is ${noCouncils}, noRequestTypes is ${noRequestTypes}`); + + if(!noStartDate && !noEndDate && !noCouncils && !noRequestTypes){ + return true; + } - if (startDate - && endDate - && councils.length > 0 - && Object.values(requestTypes).includes(true)) { - return getData(); - } else { - if(!endDate){ - - } else if(councils.length < 1){ + setDataErrors({ + missingStartDate: noStartDate, + missingEndDate: noEndDate, + missingCouncils: noCouncils, + missingRequestTypes: noRequestTypes, + }); + return false; + } - } else if(!(Object.values(requestTypes).includes(true))){ + const validateComparisonForm = () => { + const { + startDate, + endDate, + comparison: { + chart, + set1, + set2, + }, + requestTypes, + } = comparisonFilters; - } + const noStartDate = (startDate) ? false : true; + const noEndDate = (endDate) ? false : true; + const noChart = (chart) ? false : true; + const noDistrictOneSet = set1.district || set1.list.length === 0; + const noDistrictTwoSet = set2.district || set2.list.length === 0; + const noRequestTypes = !(Object.values(requestTypes).includes(true)); + + if(!noStartDate && !noEndDate && !noChart && !noDistrictOneSet && !noDistrictTwoSet && !noRequestTypes) { + return true; + } + setComparisonErrors({ + missingStartDate: noStartDate, + missingEndDate: noEndDate, + missingChart: noChart, + missingDistrictOne: noDistrictOneSet, + missingDistrictTwo: noDistrictTwoSet, + missingRequestTypes: noRequestTypes + }) + return false; + } + + const handleSubmit = () => { + switch (pathname) { + case '/data': + if (validateDataForm()) { + console.log('Validate data form came back true'); + return getData(); + } + break; + case '/comparison': + if(validateComparisonForm()){ + console.log('Validate comparison form came back true'); + return getComparisonData(); } break; - } - case '/comparison': return getComparisonData(); default: return null; } }; @@ -55,15 +115,6 @@ const Submit = ({ councils, requestTypes, } = filters; - - if (startDate - && endDate - && councils.length > 0 - && Object.values(requestTypes).includes(true)) { - setDisableSubmit(false); - } else { - setDisableSubmit(true); - } break; } case '/comparison': { @@ -77,26 +128,13 @@ const Submit = ({ }, requestTypes, } = comparisonFilters; - - if (startDate - && endDate - && chart - && set1.district - && set1.list.length > 0 - && set2.district - && set2.list.length > 0 - && Object.values(requestTypes).includes(true)) { - setDisableSubmit(false); - } else { - setDisableSubmit(true); - } break; } default: return undefined; } return () => {}; - }, [disableSubmit, filters, comparisonFilters, pathname]); + }, [filters, comparisonFilters, pathname]); return (
@@ -105,7 +143,6 @@ const Submit = ({ id="sidebar-submit-button" label="Submit" handleClick={handleSubmit} - disabled={disableSubmit} />
From 0c80fca72700193408a447c17f35ac12ec6d59d9 Mon Sep 17 00:00:00 2001 From: Hannah Livnat Date: Sat, 15 Aug 2020 17:21:16 -0700 Subject: [PATCH 04/18] deleted useEffect for disabled button in submit.jsx --- client/components/main/menu/Submit.jsx | 40 +++++--------------------- 1 file changed, 7 insertions(+), 33 deletions(-) diff --git a/client/components/main/menu/Submit.jsx b/client/components/main/menu/Submit.jsx index 14c14084e..635687788 100644 --- a/client/components/main/menu/Submit.jsx +++ b/client/components/main/menu/Submit.jsx @@ -40,7 +40,9 @@ const Submit = ({ const noEndDate = (endDate) ? false : true; const noCouncils = councils.length <= 0; const noRequestTypes = !(Object.values(requestTypes).includes(true)); - console.log(`noStartDate is ${noStartDate}, noEndDate is ${noEndDate}, noCouncils is ${noCouncils}, noRequestTypes is ${noRequestTypes}`); + + console.log(`noStartDate is ${noStartDate}, noEndDate is ${noEndDate}, + noCouncils is ${noCouncils}, noRequestTypes is ${noRequestTypes}`); if(!noStartDate && !noEndDate && !noCouncils && !noRequestTypes){ return true; @@ -90,52 +92,24 @@ const Submit = ({ const handleSubmit = () => { switch (pathname) { - case '/data': + case '/data': { if (validateDataForm()) { console.log('Validate data form came back true'); return getData(); } break; - case '/comparison': + } + case '/comparison': { if(validateComparisonForm()){ console.log('Validate comparison form came back true'); return getComparisonData(); } break; + } default: return null; } }; - useEffect(() => { - switch (pathname) { - case '/data': { - const { - startDate, - endDate, - councils, - requestTypes, - } = filters; - break; - } - case '/comparison': { - const { - startDate, - endDate, - comparison: { - chart, - set1, - set2, - }, - requestTypes, - } = comparisonFilters; - break; - } - default: return undefined; - } - - return () => {}; - }, [filters, comparisonFilters, pathname]); - return (
From 4bcc8be4ed83ae9ed5465b0bc197eeecfbbc291a Mon Sep 17 00:00:00 2001 From: Hannah Livnat Date: Sat, 15 Aug 2020 17:59:19 -0700 Subject: [PATCH 05/18] deleted extra spaces --- client/components/main/menu/Submit.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/components/main/menu/Submit.jsx b/client/components/main/menu/Submit.jsx index 635687788..130fa483a 100644 --- a/client/components/main/menu/Submit.jsx +++ b/client/components/main/menu/Submit.jsx @@ -1,4 +1,4 @@ -import React, { useState, useEffect } from 'react'; +import React, { useState } from 'react'; import { connect } from 'react-redux'; import propTypes from 'proptypes'; import { useLocation } from 'react-router-dom'; From 6127e2bc6a8fa16b2a1f153290b6522e08cff432 Mon Sep 17 00:00:00 2001 From: Hannah Livnat Date: Sat, 15 Aug 2020 19:45:08 -0700 Subject: [PATCH 06/18] trying to pass down error messaging from menu to submit, learning more about react redux connect tomorrow --- client/components/main/menu/Menu.jsx | 38 +++++++++++++++++++++++++- client/components/main/menu/Submit.jsx | 33 ++++++++++++---------- 2 files changed, 56 insertions(+), 15 deletions(-) diff --git a/client/components/main/menu/Menu.jsx b/client/components/main/menu/Menu.jsx index b36a215ce..716ea6eb1 100644 --- a/client/components/main/menu/Menu.jsx +++ b/client/components/main/menu/Menu.jsx @@ -1,7 +1,7 @@ /* eslint-disable jsx-a11y/anchor-is-valid */ /* eslint-disable jsx-a11y/no-static-element-interactions */ /* eslint-disable jsx-a11y/click-events-have-key-events */ -import React from 'react'; +import React, { useState } from 'react'; import PropTypes from 'proptypes'; import { connect } from 'react-redux'; import clx from 'classnames'; @@ -33,6 +33,42 @@ const Menu = ({ MENU_TABS.MAP, MENU_TABS.VISUALIZATIONS, ]; + const [dataErrors, setDataErrors] = useState({ + missingStartDate: false, + missingEndDate: false, + missingCouncils: false, + missingRequestTypes: false + }); + + const [comparisonErrors, setComparisonErrors] = useState({ + missingStartDate: false, + missingEndDate: false, + missingChart: false, + missingDistrictOne: false, + missingDistrictTwo: false, + missingRequestTypes: false + }) + const setDErrors = (startDate, endDate, councils, requestTypes) => { + console.log('This worked!'); + setDataErrors({ + missingStartDate: startDate, + missingEndDate: endDate, + missingCouncils: councils, + missingRequestTypes: requestTypes, + }); + } + const setCErrors = (startDate, endDate, chart, districtOne, districtTwo, requestTypes) => { + console.log("This worked!") + setComparisonErrors({ + missingStartDate: startDate, + missingEndDate: endDate, + missingChart: chart, + missingDistrictOne: districtOne, + missingDistrictTwo: districtTwo, + missingRequestTypes: requestTypes + }) + } + return (
diff --git a/client/components/main/menu/Submit.jsx b/client/components/main/menu/Submit.jsx index 130fa483a..da54477bd 100644 --- a/client/components/main/menu/Submit.jsx +++ b/client/components/main/menu/Submit.jsx @@ -48,12 +48,14 @@ const Submit = ({ return true; } - setDataErrors({ - missingStartDate: noStartDate, - missingEndDate: noEndDate, - missingCouncils: noCouncils, - missingRequestTypes: noRequestTypes, - }); + props.setDError(noStartDate, noEndDate, noCouncils, noRequestTypes); + + //setDataErrors({ + // missingStartDate: noStartDate, + // missingEndDate: noEndDate, + // missingCouncils: noCouncils, + // missingRequestTypes: noRequestTypes, + //}); return false; } @@ -79,14 +81,17 @@ const Submit = ({ if(!noStartDate && !noEndDate && !noChart && !noDistrictOneSet && !noDistrictTwoSet && !noRequestTypes) { return true; } - setComparisonErrors({ - missingStartDate: noStartDate, - missingEndDate: noEndDate, - missingChart: noChart, - missingDistrictOne: noDistrictOneSet, - missingDistrictTwo: noDistrictTwoSet, - missingRequestTypes: noRequestTypes - }) + + setCError(noStartDate, noEndDate, noChart, noDistrictOneSet, noDistrictTwoSet, noRequestTypes); + + //setComparisonErrors({ + // missingStartDate: noStartDate, + // missingEndDate: noEndDate, + // missingChart: noChart, + // missingDistrictOne: noDistrictOneSet, + // missingDistrictTwo: noDistrictTwoSet, + // missingRequestTypes: noRequestTypes + //}) return false; } From 554fa085a89857d5ab8fe910e4eaafc99f270692 Mon Sep 17 00:00:00 2001 From: Hannah Livnat Date: Sun, 16 Aug 2020 16:32:56 -0700 Subject: [PATCH 07/18] succesfully passing errors from submit component to menu component through props --- client/components/main/menu/Menu.jsx | 6 ++-- client/components/main/menu/Submit.jsx | 39 ++++---------------------- node_modules_non_es5 | 1 + 3 files changed, 8 insertions(+), 38 deletions(-) create mode 100644 node_modules_non_es5 diff --git a/client/components/main/menu/Menu.jsx b/client/components/main/menu/Menu.jsx index 716ea6eb1..6531d831f 100644 --- a/client/components/main/menu/Menu.jsx +++ b/client/components/main/menu/Menu.jsx @@ -49,7 +49,6 @@ const Menu = ({ missingRequestTypes: false }) const setDErrors = (startDate, endDate, councils, requestTypes) => { - console.log('This worked!'); setDataErrors({ missingStartDate: startDate, missingEndDate: endDate, @@ -58,7 +57,6 @@ const Menu = ({ }); } const setCErrors = (startDate, endDate, chart, districtOne, districtTwo, requestTypes) => { - console.log("This worked!") setComparisonErrors({ missingStartDate: startDate, missingEndDate: endDate, @@ -145,7 +143,7 @@ const Menu = ({ ]} /> - +
@@ -180,7 +178,7 @@ const Menu = ({ ]} /> - +
diff --git a/client/components/main/menu/Submit.jsx b/client/components/main/menu/Submit.jsx index da54477bd..ccf14cf3b 100644 --- a/client/components/main/menu/Submit.jsx +++ b/client/components/main/menu/Submit.jsx @@ -1,4 +1,4 @@ -import React, { useState } from 'react'; +import React from 'react'; import { connect } from 'react-redux'; import propTypes from 'proptypes'; import { useLocation } from 'react-router-dom'; @@ -7,27 +7,14 @@ import { getComparisonDataRequest } from '@reducers/comparisonData'; import Button from '@components/common/Button'; const Submit = ({ + setCErrors, + setDErrors, getData, getComparisonData, filters, comparisonFilters, }) => { const { pathname } = useLocation(); - const [dataErrors, setDataErrors] = useState({ - missingStartDate: false, - missingEndDate: false, - missingCouncils: false, - missingRequestTypes: false - }); - const [comparisonErrors, setComparisonErrors] = useState({ - missingStartDate: false, - missingEndDate: false, - missingChart: false, - missingDistrictOne: false, - missingDistrictTwo: false, - missingRequestTypes: false - }) - const validateDataForm = () => { const { startDate, @@ -48,14 +35,7 @@ const Submit = ({ return true; } - props.setDError(noStartDate, noEndDate, noCouncils, noRequestTypes); - - //setDataErrors({ - // missingStartDate: noStartDate, - // missingEndDate: noEndDate, - // missingCouncils: noCouncils, - // missingRequestTypes: noRequestTypes, - //}); + setDErrors(noStartDate, noEndDate, noCouncils, noRequestTypes); return false; } @@ -82,16 +62,7 @@ const Submit = ({ return true; } - setCError(noStartDate, noEndDate, noChart, noDistrictOneSet, noDistrictTwoSet, noRequestTypes); - - //setComparisonErrors({ - // missingStartDate: noStartDate, - // missingEndDate: noEndDate, - // missingChart: noChart, - // missingDistrictOne: noDistrictOneSet, - // missingDistrictTwo: noDistrictTwoSet, - // missingRequestTypes: noRequestTypes - //}) + setCErrors(noStartDate, noEndDate, noChart, noDistrictOneSet, noDistrictTwoSet, noRequestTypes); return false; } diff --git a/node_modules_non_es5 b/node_modules_non_es5 new file mode 100644 index 000000000..1b48245c4 --- /dev/null +++ b/node_modules_non_es5 @@ -0,0 +1 @@ +/[\\/]node_modules[\\/](?!(@react-pdf\/renderer|bulma|bulma-checkradio|bulma-switch|dotenv|gh-pages|jest)[\\/])/ From aeeeb654265dec9bce4eab4873e288ce5d8e84dd Mon Sep 17 00:00:00 2001 From: Hannah Livnat Date: Wed, 19 Aug 2020 14:51:40 -0700 Subject: [PATCH 08/18] error message stating to choose at least one selection displayed on submit --- client/components/common/InfoTitle.jsx | 2 +- client/components/main/menu/Menu.jsx | 50 ++++++++++++++++++++++++++ client/components/main/menu/Submit.jsx | 9 +++-- 3 files changed, 58 insertions(+), 3 deletions(-) diff --git a/client/components/common/InfoTitle.jsx b/client/components/common/InfoTitle.jsx index b5f234355..7466692e7 100644 --- a/client/components/common/InfoTitle.jsx +++ b/client/components/common/InfoTitle.jsx @@ -14,7 +14,7 @@ const InfoTitle = ({ { style: { display: 'inline-block', - marginRight: 6, + margin: '15px 5px 5px 0' }, }, title, diff --git a/client/components/main/menu/Menu.jsx b/client/components/main/menu/Menu.jsx index 6531d831f..0f6fcb06c 100644 --- a/client/components/main/menu/Menu.jsx +++ b/client/components/main/menu/Menu.jsx @@ -67,6 +67,14 @@ const Menu = ({ }) } + const missingSelectorWarning = React.createElement('p', { + style: { + color: 'red', + margin: '0 0 10px 0', + fontSize: '0.75rem' + }, + }, '* Please choose at least one selection') + return (
@@ -115,6 +123,12 @@ const Menu = ({ '* Please click to make a selection.', ]} /> + { + (comparisonErrors.missingEndDate) ? + missingSelectorWarning + : + null + } + { + (comparisonErrors.missingDistrictOne || comparisonErrors.missingDistrictTwo) ? + missingSelectorWarning + : + null + } + { + (comparisonErrors.missingChart) ? + missingSelectorWarning + : + null + } + { + (comparisonErrors.missingRequestTypes) ? + missingSelectorWarning + : + null + }
@@ -158,6 +190,12 @@ const Menu = ({ '* Please click to make a selection.', ]} /> + { + (dataErrors.missingEndDate) ? +

* Please Choose at least one selection

+ : + null + } + { + (dataErrors.missingCouncils) ? + missingSelectorWarning + : + null + } + { + (dataErrors.missingRequestTypes) ? + missingSelectorWarning + : + null + }
diff --git a/client/components/main/menu/Submit.jsx b/client/components/main/menu/Submit.jsx index ccf14cf3b..e70c1a55d 100644 --- a/client/components/main/menu/Submit.jsx +++ b/client/components/main/menu/Submit.jsx @@ -32,6 +32,7 @@ const Submit = ({ noCouncils is ${noCouncils}, noRequestTypes is ${noRequestTypes}`); if(!noStartDate && !noEndDate && !noCouncils && !noRequestTypes){ + setDErrors(noStartDate, noEndDate, noCouncils, noRequestTypes); return true; } @@ -54,11 +55,15 @@ const Submit = ({ const noStartDate = (startDate) ? false : true; const noEndDate = (endDate) ? false : true; const noChart = (chart) ? false : true; - const noDistrictOneSet = set1.district || set1.list.length === 0; - const noDistrictTwoSet = set2.district || set2.list.length === 0; + const noDistrictOneSet = (set1.list.length === 0) ? true : false; + const noDistrictTwoSet = (set2.list.length === 0) ? true : false; const noRequestTypes = !(Object.values(requestTypes).includes(true)); + + console.log(`startdate and enddate is ${noStartDate}, chart is ${noChart}, district set one is ${noDistrictOneSet}, district set + two is ${noDistrictTwoSet}, norequesttype is ${noRequestTypes}.`); if(!noStartDate && !noEndDate && !noChart && !noDistrictOneSet && !noDistrictTwoSet && !noRequestTypes) { + setCErrors(noStartDate, noEndDate, noChart, noDistrictOneSet, noDistrictTwoSet, noRequestTypes); return true; } From f77f500680f2aa33f3b597d6022d66514c8012a6 Mon Sep 17 00:00:00 2001 From: Hannah Livnat Date: Wed, 19 Aug 2020 14:55:25 -0700 Subject: [PATCH 09/18] missed one hardcoded selector warning in menu --- client/components/main/menu/Menu.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/components/main/menu/Menu.jsx b/client/components/main/menu/Menu.jsx index 0f6fcb06c..cc5cb49e2 100644 --- a/client/components/main/menu/Menu.jsx +++ b/client/components/main/menu/Menu.jsx @@ -192,7 +192,7 @@ const Menu = ({ /> { (dataErrors.missingEndDate) ? -

* Please Choose at least one selection

+ missingSelectorWarning : null } From 47ee4c3e5b5497c53c0b9a482da40e07750c5277 Mon Sep 17 00:00:00 2001 From: Hannah Livnat Date: Wed, 19 Aug 2020 14:58:27 -0700 Subject: [PATCH 10/18] deleted console.logs used for testing --- client/components/main/menu/Submit.jsx | 8 -------- 1 file changed, 8 deletions(-) diff --git a/client/components/main/menu/Submit.jsx b/client/components/main/menu/Submit.jsx index e70c1a55d..58f9b3b63 100644 --- a/client/components/main/menu/Submit.jsx +++ b/client/components/main/menu/Submit.jsx @@ -27,9 +27,6 @@ const Submit = ({ const noEndDate = (endDate) ? false : true; const noCouncils = councils.length <= 0; const noRequestTypes = !(Object.values(requestTypes).includes(true)); - - console.log(`noStartDate is ${noStartDate}, noEndDate is ${noEndDate}, - noCouncils is ${noCouncils}, noRequestTypes is ${noRequestTypes}`); if(!noStartDate && !noEndDate && !noCouncils && !noRequestTypes){ setDErrors(noStartDate, noEndDate, noCouncils, noRequestTypes); @@ -58,9 +55,6 @@ const Submit = ({ const noDistrictOneSet = (set1.list.length === 0) ? true : false; const noDistrictTwoSet = (set2.list.length === 0) ? true : false; const noRequestTypes = !(Object.values(requestTypes).includes(true)); - - console.log(`startdate and enddate is ${noStartDate}, chart is ${noChart}, district set one is ${noDistrictOneSet}, district set - two is ${noDistrictTwoSet}, norequesttype is ${noRequestTypes}.`); if(!noStartDate && !noEndDate && !noChart && !noDistrictOneSet && !noDistrictTwoSet && !noRequestTypes) { setCErrors(noStartDate, noEndDate, noChart, noDistrictOneSet, noDistrictTwoSet, noRequestTypes); @@ -75,14 +69,12 @@ const Submit = ({ switch (pathname) { case '/data': { if (validateDataForm()) { - console.log('Validate data form came back true'); return getData(); } break; } case '/comparison': { if(validateComparisonForm()){ - console.log('Validate comparison form came back true'); return getComparisonData(); } break; From 453fc795810dffa7e76d31ecd61a9464a2b32cc9 Mon Sep 17 00:00:00 2001 From: Hannah Livnat Date: Wed, 19 Aug 2020 15:00:49 -0700 Subject: [PATCH 11/18] combined repeated code for updated error messages --- client/components/main/menu/Submit.jsx | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/client/components/main/menu/Submit.jsx b/client/components/main/menu/Submit.jsx index 58f9b3b63..50fd590b8 100644 --- a/client/components/main/menu/Submit.jsx +++ b/client/components/main/menu/Submit.jsx @@ -27,13 +27,11 @@ const Submit = ({ const noEndDate = (endDate) ? false : true; const noCouncils = councils.length <= 0; const noRequestTypes = !(Object.values(requestTypes).includes(true)); - + setDErrors(noStartDate, noEndDate, noCouncils, noRequestTypes); + if(!noStartDate && !noEndDate && !noCouncils && !noRequestTypes){ - setDErrors(noStartDate, noEndDate, noCouncils, noRequestTypes); return true; } - - setDErrors(noStartDate, noEndDate, noCouncils, noRequestTypes); return false; } @@ -55,13 +53,13 @@ const Submit = ({ const noDistrictOneSet = (set1.list.length === 0) ? true : false; const noDistrictTwoSet = (set2.list.length === 0) ? true : false; const noRequestTypes = !(Object.values(requestTypes).includes(true)); + setCErrors(noStartDate, noEndDate, noChart, noDistrictOneSet, noDistrictTwoSet, noRequestTypes); + if(!noStartDate && !noEndDate && !noChart && !noDistrictOneSet && !noDistrictTwoSet && !noRequestTypes) { - setCErrors(noStartDate, noEndDate, noChart, noDistrictOneSet, noDistrictTwoSet, noRequestTypes); return true; } - setCErrors(noStartDate, noEndDate, noChart, noDistrictOneSet, noDistrictTwoSet, noRequestTypes); return false; } From d7ed7400ada2789ab4400f9be9d4705e5a878681 Mon Sep 17 00:00:00 2001 From: Hannah Livnat Date: Wed, 19 Aug 2020 15:13:48 -0700 Subject: [PATCH 12/18] changes to fix portion of lint errors --- client/components/main/menu/Menu.jsx | 54 ++++++++------------------ client/components/main/menu/Submit.jsx | 12 +++--- 2 files changed, 23 insertions(+), 43 deletions(-) diff --git a/client/components/main/menu/Menu.jsx b/client/components/main/menu/Menu.jsx index cc5cb49e2..10f097be3 100644 --- a/client/components/main/menu/Menu.jsx +++ b/client/components/main/menu/Menu.jsx @@ -37,7 +37,7 @@ const Menu = ({ missingStartDate: false, missingEndDate: false, missingCouncils: false, - missingRequestTypes: false + missingRequestTypes: false, }); const [comparisonErrors, setComparisonErrors] = useState({ @@ -46,8 +46,8 @@ const Menu = ({ missingChart: false, missingDistrictOne: false, missingDistrictTwo: false, - missingRequestTypes: false - }) + missingRequestTypes: false, + }); const setDErrors = (startDate, endDate, councils, requestTypes) => { setDataErrors({ missingStartDate: startDate, @@ -55,7 +55,7 @@ const Menu = ({ missingCouncils: councils, missingRequestTypes: requestTypes, }); - } + }; const setCErrors = (startDate, endDate, chart, districtOne, districtTwo, requestTypes) => { setComparisonErrors({ missingStartDate: startDate, @@ -63,18 +63,17 @@ const Menu = ({ missingChart: chart, missingDistrictOne: districtOne, missingDistrictTwo: districtTwo, - missingRequestTypes: requestTypes - }) - } + missingRequestTypes: requestTypes, + }); + }; const missingSelectorWarning = React.createElement('p', { style: { color: 'red', margin: '0 0 10px 0', - fontSize: '0.75rem' + fontSize: '0.75rem', }, - }, '* Please choose at least one selection') - + }, '* Please choose at least one selection'); return (
@@ -124,10 +123,7 @@ const Menu = ({ ]} /> { - (comparisonErrors.missingEndDate) ? - missingSelectorWarning - : - null + (comparisonErrors.missingEndDate) ? missingSelectorWarning: null } { - (comparisonErrors.missingDistrictOne || comparisonErrors.missingDistrictTwo) ? - missingSelectorWarning - : - null + (comparisonErrors.missingDistrictOne || comparisonErrors.missingDistrictTwo) ? missingSelectorWarning : null } { - (comparisonErrors.missingChart) ? - missingSelectorWarning - : - null + (comparisonErrors.missingChart) ? missingSelectorWarning : null } { - (comparisonErrors.missingRequestTypes) ? - missingSelectorWarning - : - null + (comparisonErrors.missingRequestTypes) ? missingSelectorWarning : null } @@ -191,10 +178,7 @@ const Menu = ({ ]} /> { - (dataErrors.missingEndDate) ? - missingSelectorWarning - : - null + (dataErrors.missingEndDate) ? missingSelectorWarning : null } { - (dataErrors.missingCouncils) ? - missingSelectorWarning - : - null + (dataErrors.missingCouncils) ? missingSelectorWarning : null } { - (dataErrors.missingRequestTypes) ? - missingSelectorWarning - : - null + (dataErrors.missingRequestTypes) ? missingSelectorWarning : null } diff --git a/client/components/main/menu/Submit.jsx b/client/components/main/menu/Submit.jsx index 50fd590b8..2a5abe1a2 100644 --- a/client/components/main/menu/Submit.jsx +++ b/client/components/main/menu/Submit.jsx @@ -7,7 +7,7 @@ import { getComparisonDataRequest } from '@reducers/comparisonData'; import Button from '@components/common/Button'; const Submit = ({ - setCErrors, + setCErrors, setDErrors, getData, getComparisonData, @@ -29,11 +29,11 @@ const Submit = ({ const noRequestTypes = !(Object.values(requestTypes).includes(true)); setDErrors(noStartDate, noEndDate, noCouncils, noRequestTypes); - if(!noStartDate && !noEndDate && !noCouncils && !noRequestTypes){ + if (!noStartDate && !noEndDate && !noCouncils && !noRequestTypes) { return true; } return false; - } + }; const validateComparisonForm = () => { const { @@ -55,8 +55,8 @@ const Submit = ({ const noRequestTypes = !(Object.values(requestTypes).includes(true)); setCErrors(noStartDate, noEndDate, noChart, noDistrictOneSet, noDistrictTwoSet, noRequestTypes); - - if(!noStartDate && !noEndDate && !noChart && !noDistrictOneSet && !noDistrictTwoSet && !noRequestTypes) { + if (!noStartDate && !noEndDate && !noChart && + !noDistrictOneSet && !noDistrictTwoSet && !noRequestTypes) { return true; } @@ -105,6 +105,8 @@ const mapDispatchToProps = dispatch => ({ }); Submit.propTypes = { + setCErrors: propTypes.func, + setDErrors: propTypes.func, getData: propTypes.func, getComparisonData: propTypes.func, filters: propTypes.shape({ From bffb7e0edea8e881e054b0cd92d8caac7a44d47f Mon Sep 17 00:00:00 2001 From: Hannah Livnat Date: Wed, 19 Aug 2020 15:25:49 -0700 Subject: [PATCH 13/18] more fixes for lint --- client/components/common/InfoTitle.jsx | 2 +- client/components/main/menu/Menu.jsx | 9 +++++---- client/components/main/menu/Submit.jsx | 12 +++++++----- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/client/components/common/InfoTitle.jsx b/client/components/common/InfoTitle.jsx index 7466692e7..1ef88bc7d 100644 --- a/client/components/common/InfoTitle.jsx +++ b/client/components/common/InfoTitle.jsx @@ -14,7 +14,7 @@ const InfoTitle = ({ { style: { display: 'inline-block', - margin: '15px 5px 5px 0' + margin: '15px 5px 5px 0', }, }, title, diff --git a/client/components/main/menu/Menu.jsx b/client/components/main/menu/Menu.jsx index 10f097be3..0d4b7ff12 100644 --- a/client/components/main/menu/Menu.jsx +++ b/client/components/main/menu/Menu.jsx @@ -123,7 +123,7 @@ const Menu = ({ ]} /> { - (comparisonErrors.missingEndDate) ? missingSelectorWarning: null + (comparisonErrors.missingEndDate) ? missingSelectorWarning : null } { - (comparisonErrors.missingDistrictOne || comparisonErrors.missingDistrictTwo) ? missingSelectorWarning : null + (comparisonErrors.missingDistrictOne || comparisonErrors.missingDistrictTwo) + ? missingSelectorWarning : null } - +
@@ -206,7 +207,7 @@ const Menu = ({ (dataErrors.missingRequestTypes) ? missingSelectorWarning : null } - +
diff --git a/client/components/main/menu/Submit.jsx b/client/components/main/menu/Submit.jsx index 2a5abe1a2..ee13ce057 100644 --- a/client/components/main/menu/Submit.jsx +++ b/client/components/main/menu/Submit.jsx @@ -55,13 +55,13 @@ const Submit = ({ const noRequestTypes = !(Object.values(requestTypes).includes(true)); setCErrors(noStartDate, noEndDate, noChart, noDistrictOneSet, noDistrictTwoSet, noRequestTypes); - if (!noStartDate && !noEndDate && !noChart && - !noDistrictOneSet && !noDistrictTwoSet && !noRequestTypes) { + if (!noStartDate && !noEndDate && !noChart + && !noDistrictOneSet && !noDistrictTwoSet && !noRequestTypes) { return true; } return false; - } + }; const handleSubmit = () => { switch (pathname) { @@ -72,7 +72,7 @@ const Submit = ({ break; } case '/comparison': { - if(validateComparisonForm()){ + if (validateComparisonForm()) { return getComparisonData(); } break; @@ -105,7 +105,7 @@ const mapDispatchToProps = dispatch => ({ }); Submit.propTypes = { - setCErrors: propTypes.func, + setCErrors: propTypes.func, setDErrors: propTypes.func, getData: propTypes.func, getComparisonData: propTypes.func, @@ -136,6 +136,8 @@ Submit.propTypes = { Submit.defaultProps = { getData: () => null, getComparisonData: () => null, + setCErrors: () => null, + setDErrors: () => null, }; export default connect(mapStateToProps, mapDispatchToProps)(Submit); From 7f3647b94b97cceec5f5519447b6ab768ab15e61 Mon Sep 17 00:00:00 2001 From: Hannah Livnat Date: Wed, 19 Aug 2020 15:35:38 -0700 Subject: [PATCH 14/18] lint --- client/components/main/menu/Menu.jsx | 4 ++-- client/components/main/menu/Submit.jsx | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/client/components/main/menu/Menu.jsx b/client/components/main/menu/Menu.jsx index 0d4b7ff12..89da5829d 100644 --- a/client/components/main/menu/Menu.jsx +++ b/client/components/main/menu/Menu.jsx @@ -135,8 +135,8 @@ const Menu = ({ ]} /> { - (comparisonErrors.missingDistrictOne || comparisonErrors.missingDistrictTwo) - ? missingSelectorWarning : null + (comparisonErrors.missingDistrictOne || comparisonErrors.missingDistrictTwo) + ? missingSelectorWarning : null } Date: Wed, 19 Aug 2020 15:42:10 -0700 Subject: [PATCH 15/18] fixed unnecessary ternary --- client/components/main/menu/Submit.jsx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/client/components/main/menu/Submit.jsx b/client/components/main/menu/Submit.jsx index 3de072b74..2831b46f9 100644 --- a/client/components/main/menu/Submit.jsx +++ b/client/components/main/menu/Submit.jsx @@ -23,8 +23,8 @@ const Submit = ({ requestTypes, } = filters; - const noStartDate = (startDate) ? false : true; - const noEndDate = (endDate) ? false : true; + const noStartDate = !startDate; + const noEndDate = !endDate; const noCouncils = councils.length <= 0; const noRequestTypes = !(Object.values(requestTypes).includes(true)); setDErrors(noStartDate, noEndDate, noCouncils, noRequestTypes); @@ -47,11 +47,11 @@ const Submit = ({ requestTypes, } = comparisonFilters; - const noStartDate = (startDate) ? false : true; - const noEndDate = (endDate) ? false : true; - const noChart = (chart) ? false : true; - const noDistrictOneSet = (set1.list.length === 0) ? true : false; - const noDistrictTwoSet = (set2.list.length === 0) ? true : false; + const noStartDate = !startDate; + const noEndDate = !endDate; + const noChart = !chart; + const noDistrictOneSet = set1.list.length === 0; + const noDistrictTwoSet = set2.list.length === 0; const noRequestTypes = !(Object.values(requestTypes).includes(true)); setCErrors(noStartDate, noEndDate, noChart, noDistrictOneSet, noDistrictTwoSet, noRequestTypes); From 651c1d0c62aa839571012f6adc1bcdf06033db98 Mon Sep 17 00:00:00 2001 From: Hannah Livnat Date: Wed, 19 Aug 2020 15:53:48 -0700 Subject: [PATCH 16/18] more lint --- client/components/main/menu/Submit.jsx | 1 + 1 file changed, 1 insertion(+) diff --git a/client/components/main/menu/Submit.jsx b/client/components/main/menu/Submit.jsx index 2831b46f9..3380314cd 100644 --- a/client/components/main/menu/Submit.jsx +++ b/client/components/main/menu/Submit.jsx @@ -79,6 +79,7 @@ const Submit = ({ } default: return false; } + return null; }; return ( From 72dbcd4c71e1829f248190b9e57f175c13f416a2 Mon Sep 17 00:00:00 2001 From: Hannah Livnat Date: Thu, 20 Aug 2020 20:34:46 -0700 Subject: [PATCH 17/18] created errormessage component for form validation --- client/components/main/menu/ErrorMessage.jsx | 43 ++++++++++++++++++++ client/components/main/menu/Menu.jsx | 23 ++++------- 2 files changed, 51 insertions(+), 15 deletions(-) create mode 100644 client/components/main/menu/ErrorMessage.jsx diff --git a/client/components/main/menu/ErrorMessage.jsx b/client/components/main/menu/ErrorMessage.jsx new file mode 100644 index 000000000..9ba328452 --- /dev/null +++ b/client/components/main/menu/ErrorMessage.jsx @@ -0,0 +1,43 @@ +import React from 'react'; +import propTypes from 'proptypes'; + +const ErrorMessage = ({ + errorType +}) => { + + const setErrorMessage = () => { + switch (errorType) { + case 'selectone': { + return '* Please choose at least one selection'; + } + case 'data': { + return '* Please select a date range'; + } + case 'districtset': { + return '* Please choose two districts'; + } + default: return null; + } + return null; + }; + + const errorMessage = setErrorMessage(); + + const missingSelectorWarning = React.createElement('p', { + style: { + color: 'red', + margin: '0 0 10px 0', + fontSize: '0.75rem', + }, + }, errorMessage); + + return ( + missingSelectorWarning + ); +}; + +export default ErrorMessage; + +ErrorMessage.propTypes = { + errorType: propTypes.string.isRequired, +} \ No newline at end of file diff --git a/client/components/main/menu/Menu.jsx b/client/components/main/menu/Menu.jsx index 89da5829d..32c21b975 100644 --- a/client/components/main/menu/Menu.jsx +++ b/client/components/main/menu/Menu.jsx @@ -17,6 +17,7 @@ import Button from '@components/common/Button'; import InfoTitle from '@components/common/InfoTitle'; import HoverOverInfo from '@components/common/HoverOverInfo'; import Submit from './Submit'; +import ErrorMessage from './ErrorMessage'; import DateSelector from './DateSelector/DateSelector'; import NCSelector from './NCSelector'; import RequestTypeSelector from './RequestTypeSelector'; @@ -67,14 +68,6 @@ const Menu = ({ }); }; - const missingSelectorWarning = React.createElement('p', { - style: { - color: 'red', - margin: '0 0 10px 0', - fontSize: '0.75rem', - }, - }, '* Please choose at least one selection'); - return (
@@ -123,7 +116,7 @@ const Menu = ({ ]} /> { - (comparisonErrors.missingEndDate) ? missingSelectorWarning : null + comparisonErrors.missingEndDate && } { (comparisonErrors.missingDistrictOne || comparisonErrors.missingDistrictTwo) - ? missingSelectorWarning : null + && } { - (comparisonErrors.missingChart) ? missingSelectorWarning : null + comparisonErrors.missingChart && } { - (comparisonErrors.missingRequestTypes) ? missingSelectorWarning : null + comparisonErrors.missingRequestTypes && } @@ -179,7 +172,7 @@ const Menu = ({ ]} /> { - (dataErrors.missingEndDate) ? missingSelectorWarning : null + dataErrors.missingEndDate && } { - (dataErrors.missingCouncils) ? missingSelectorWarning : null + dataErrors.missingCouncils && } { - (dataErrors.missingRequestTypes) ? missingSelectorWarning : null + dataErrors.missingRequestTypes && } From 466227f458d70f130d5042536837a7f7d2662e9d Mon Sep 17 00:00:00 2001 From: Hannah Livnat Date: Thu, 20 Aug 2020 20:37:31 -0700 Subject: [PATCH 18/18] lint --- client/components/main/menu/ErrorMessage.jsx | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/client/components/main/menu/ErrorMessage.jsx b/client/components/main/menu/ErrorMessage.jsx index 9ba328452..96ce4ec6a 100644 --- a/client/components/main/menu/ErrorMessage.jsx +++ b/client/components/main/menu/ErrorMessage.jsx @@ -2,9 +2,8 @@ import React from 'react'; import propTypes from 'proptypes'; const ErrorMessage = ({ - errorType + errorType, }) => { - const setErrorMessage = () => { switch (errorType) { case 'selectone': { @@ -18,7 +17,6 @@ const ErrorMessage = ({ } default: return null; } - return null; }; const errorMessage = setErrorMessage(); @@ -40,4 +38,4 @@ export default ErrorMessage; ErrorMessage.propTypes = { errorType: propTypes.string.isRequired, -} \ No newline at end of file +};