From 688da081627ac79d1011d9bab867adc043d82593 Mon Sep 17 00:00:00 2001 From: Gemma Date: Thu, 28 Sep 2023 15:19:56 +0200 Subject: [PATCH] cohorts fixed --- frontend/src/components/Cohorts/Cohorts.css | 56 ++++++++++++ frontend/src/components/Cohorts/Cohorts.js | 87 +++++++++++-------- .../src/components/Cohorts/CohortsModule.js | 50 +++++++++++ .../Individuals/IndividualsResults.js | 7 +- frontend/src/components/Layout/Layout.js | 69 +++------------ 5 files changed, 175 insertions(+), 94 deletions(-) create mode 100644 frontend/src/components/Cohorts/CohortsModule.js diff --git a/frontend/src/components/Cohorts/Cohorts.css b/frontend/src/components/Cohorts/Cohorts.css index 2c005d48..1345cdb8 100644 --- a/frontend/src/components/Cohorts/Cohorts.css +++ b/frontend/src/components/Cohorts/Cohorts.css @@ -217,3 +217,59 @@ h12 { align-items: center; justify-content: center; } + +.middle { + top: 30%; + transform: translate(-50%, -50%); + position: absolute; +} +.bar { + width: 12px; + height: 90px; + background: #fff; + display: inline-block; + transform-origin: bottom center; + border-top-right-radius: 20px; + border-top-left-radius: 20px; + /* box-shadow:5px 10px 20px inset rgba(255,23,25.2); */ + animation: loader 1.2s linear infinite; +} +.bar1 { + animation-delay: 0.1s; +} +.bar2 { + animation-delay: 0.2s; +} +.bar3 { + animation-delay: 0.3s; +} +.bar4 { + animation-delay: 0.4s; +} +.bar5 { + animation-delay: 0.5s; +} +.bar6 { + animation-delay: 0.6s; +} +.bar7 { + animation-delay: 0.7s; +} +.bar8 { + animation-delay: 0.8s; +} + +@keyframes loader { + 0% { + transform: scaleY(0.1); + background: #34495e ; + } + 50% { + transform: scaleY(1); + background:#6ad513; + } + 100% { + transform: scaleY(0.1); + background: transparent; + } +} diff --git a/frontend/src/components/Cohorts/Cohorts.js b/frontend/src/components/Cohorts/Cohorts.js index cb1b9c83..8f7f5186 100644 --- a/frontend/src/components/Cohorts/Cohorts.js +++ b/frontend/src/components/Cohorts/Cohorts.js @@ -4,15 +4,16 @@ import axios from 'axios' import { useState, useEffect } from 'react' import Layout from '../Layout/Layout' import { NavLink, useNavigate } from 'react-router-dom' -import configData from "../../config.json"; +import configData from '../../config.json' +import CohortsModule from './CohortsModule' function Cohorts (props) { - const API_ENDPOINT = configData.API_URL + "/cohorts" + const API_ENDPOINT = configData.API_URL + '/cohorts' const [error, setError] = useState(false) const navigate = useNavigate() - const [options, setOptions] = useState([]) + const [optionsCohorts, setOptionsCohorts] = useState([]) const [selectedCohorts, setSelectedCohorts] = useState([]) @@ -42,6 +43,8 @@ function Cohorts (props) { const [dataAvailable, setDataAvailable] = useState(false) + const [triggerLayout, setTriggerLayout] = useState(false) + const handleSelectedFilter = e => { setSelectedFilter(e.target.value) } @@ -51,6 +54,37 @@ function Cohorts (props) { console.log(e.target.value) } + useEffect(() => { + const fetchDataCohorts = async () => { + try { + let res = await axios.get(configData.API_URL + '/cohorts') + console.log(res) + res.data.response.collections.forEach(element => { + if (element.name === undefined && element.cohortName !== undefined) { + let obj = { + value: element.cohortName, + label: element.cohortName + } + optionsCohorts.push(obj) + } else if (element.name !== undefined) { + let obj = { + value: element.name, + label: element.name + } + optionsCohorts.push(obj) + } + const timer = setTimeout(() => { + setTriggerLayout(true) + }, 2000) + return () => clearTimeout(timer) + }) + } catch (error) { + console.log(error) + } + } + fetchDataCohorts().catch(console.error) + }, []) + useEffect(() => { let values = [] let labels = [] @@ -505,46 +539,27 @@ function Cohorts (props) { } }, [showGraphs]) - useEffect(() => { - const fetchDataCohorts = async () => { - try { - let res = await axios.get( - configData.API_URL + "/cohorts" - ) - - res.data.response.collections.forEach(element => { - if (element.name === undefined && element.cohortName !== undefined) { - let obj = { - value: element.cohortName, - label: element.cohortName - } - options.push(obj) - } else if (element.name !== undefined) { - let obj = { - value: element.name, - label: element.name - } - options.push(obj) - } - - console.log(options) - }) - } catch (error) { - console.log(error) - } - } - fetchDataCohorts().catch(console.error) - }, []) - return (
- {showGraphs === false && ( + {triggerLayout === false && ( +
+
+
+
+
+
+
+
+
+
+ )} + {showGraphs === false && triggerLayout && ( )} diff --git a/frontend/src/components/Cohorts/CohortsModule.js b/frontend/src/components/Cohorts/CohortsModule.js new file mode 100644 index 00000000..43cf4941 --- /dev/null +++ b/frontend/src/components/Cohorts/CohortsModule.js @@ -0,0 +1,50 @@ +import '../../App.css' +import './Cohorts.css' +import React, { useState, useEffect } from 'react' +import Select from 'react-select' +import makeAnimated from 'react-select/animated' + +function CohortsModule (props) { + const [results, setResults] = useState(null) + const [selectedCohortsAux, setSelectedCohortsAux] = useState([]) + const animatedComponents = makeAnimated() + const onSubmitCohorts = () => { + setResults('Cohorts') + + props.setShowGraphs(true) + } + const handleChangeCohorts = selectedOption => { + setSelectedCohortsAux([]) + selectedCohortsAux.push(selectedOption) + props.setSelectedCohorts(selectedCohortsAux) + } + + return ( +
+ - -
- {results !== 'Cohorts' && ( - - )} -
-
- )} + } +
)}