From f672511caf20ee8b7eefd342d5b0bace3f71d211 Mon Sep 17 00:00:00 2001 From: Gemma Date: Wed, 10 Jan 2024 12:13:52 +0100 Subject: [PATCH] options cohorts visible --- frontend/src/components/Cohorts/Cohorts.js | 180 +++++++++++++++--- .../src/components/Cohorts/CohortsModule.js | 44 +++-- frontend/src/components/Layout/Layout.js | 6 +- 3 files changed, 188 insertions(+), 42 deletions(-) diff --git a/frontend/src/components/Cohorts/Cohorts.js b/frontend/src/components/Cohorts/Cohorts.js index 8f27fbc..794bfc9 100644 --- a/frontend/src/components/Cohorts/Cohorts.js +++ b/frontend/src/components/Cohorts/Cohorts.js @@ -5,6 +5,7 @@ import { useState, useEffect } from 'react' import Layout from '../Layout/Layout' import { NavLink, useNavigate } from 'react-router-dom' import configData from '../../config.json' +import CohortsModule from './CohortsModule' function Cohorts (props) { const API_ENDPOINT = configData.API_URL + '/cohorts' @@ -58,8 +59,11 @@ function Cohorts (props) { const [trigger, setTrigger] = useState(false) + const [trigger2, setTrigger2] = useState(false) const [noCollectionEvents, setNoCollectionEvents] = useState(false) + const [alreadySelectedCohort, setAlreadySelectedCohort] = useState(true) + //const handleSelectedFilter = e => { //setSelectedFilter(e.target.value) //} @@ -69,29 +73,33 @@ function Cohorts (props) { } useEffect(() => { - const fetchDataCohorts = async () => { - try { - let res = await axios.get(configData.API_URL + '/cohorts') - console.log(res) - res.data.response.collections.forEach(element => { - let obj = { - value: element.id, - label: element.id - } - optionsCohorts.push(obj) - arrayCohorts.push(element) - const timer = setTimeout(() => { - setTriggerLayout(true) - }, 2000) - return () => clearTimeout(timer) - }) - } catch (error) { - setTimeOut(true) - console.log(error) - setError('Unexpected error. Please retry') + if (!props.newSearch) { + const fetchDataCohorts = async () => { + try { + let res = await axios.get(configData.API_URL + '/cohorts') + console.log(res) + res.data.response.collections.forEach(element => { + let obj = { + value: element.id, + label: element.id + } + optionsCohorts.push(obj) + arrayCohorts.push(element) + const timer = setTimeout(() => { + setTriggerLayout(true) + }, 2000) + return () => clearTimeout(timer) + }) + } catch (error) { + setTimeOut(true) + console.log(error) + setError('Unexpected error. Please retry') + } } + fetchDataCohorts().catch(console.error) + } else { + setTimeOut(true) } - fetchDataCohorts().catch(console.error) }, []) useEffect(() => { @@ -528,7 +536,7 @@ function Cohorts (props) { if (selectedCohorts) { apiCall() } - }, [showGraphs, trigger]) + }, [showGraphs, trigger, trigger2]) return (
@@ -566,8 +574,132 @@ function Cohorts (props) { {error !== '' && {error}} - {trigger && !noCollectionEvents && ( + {trigger && trigger2 && !noCollectionEvents && showGraphs && ( + <> + + {nameCohort !== '' &&

{nameCohort}

} + {showGraphs === true && ( +
+
+
+
+
+ {/*
+ + + + + + +
*/} + + {/* {showEthFiltered && ( +
+
+
+ )} + {showEthFiltered2 && ( +
+
+
+ )} */} +
+
+
+
+ {/*
+ + + + + +
+ + {showDisFiltered && ( +
+
+
+ )} + {showDisFiltered2 && ( +
+
+
+ )} */} +
+
+
+ )} + + )} + {trigger && !trigger2 && !noCollectionEvents && showGraphs && ( <> + {nameCohort !== '' &&

{nameCohort}

} {showGraphs === true && (
@@ -669,7 +801,7 @@ function Cohorts (props) { )} - {trigger && noCollectionEvents && ( + {trigger && noCollectionEvents && showGraphs && ( NO GRAPHICS AVAILABLE FOR THE SELECTED COHORTS )} {showGraphs === true && dataAvailable === false && timeOut === true && ( diff --git a/frontend/src/components/Cohorts/CohortsModule.js b/frontend/src/components/Cohorts/CohortsModule.js index 2dbe074..46fe51d 100644 --- a/frontend/src/components/Cohorts/CohortsModule.js +++ b/frontend/src/components/Cohorts/CohortsModule.js @@ -3,24 +3,33 @@ import './Cohorts.css' import React, { useState, useEffect } from 'react' import Select from 'react-select' import makeAnimated from 'react-select/animated' +import Cohorts from './Cohorts' function CohortsModule (props) { const [results, setResults] = useState(null) const animatedComponents = makeAnimated() const [selected, setSelected] = useState(null) + + const [trigger, setTrigger] = useState(false) + const [newSearch, setNewSearch] = useState(true) + const onSubmitCohorts = () => { setResults('Cohorts') - props.setShowGraphs(true) } const handleChangeCohorts = selectedOption => { console.log(selectedOption) setSelected(selectedOption) - props.setSelectedCohorts(selectedOption) } + const handleSearchAgain = () => { + setTrigger(true) + props.setResponse('') + props.setTrigger2(!props.trigger2) + } + return (