Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elixir bsc #40

Merged
merged 2 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions frontend/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import SignInForm from './components/SignIn/SignInForm'
import ResultsDatasets from './components/Datasets/ResultsDatasets'
import CrossQueries from './components/CrossQueries/CrossQueries'
import LoggedIn from './components/SignIn/LoggedIn'
import Verifier from './components/Verifier/Verifier'
import Validator from './components/Validator/Validator'
import SignInFormNoLS from './components/SignIn/SignInFormNoLS'
import AboutSection from './components/AboutSection/AboutSection'
import SignInOptions from './components/SignInOptions/SignInOptions'
Expand All @@ -37,8 +37,8 @@ function App () {
<Route path='/sign-in-noLS' element={<SignInFormNoLS />} />
<Route path='/sign-in-options' element={<SignInOptions />} />
<Route path='/loggedOut' element={<LoggedIn />} />
<Route path='/cross-queries/:scope/:id' element={<CrossQueries />} />
<Route path='/verifier' element={<Verifier />} />
<Route path='/:scope/cross-queries/:id' element={<CrossQueries />} />
<Route path='/validator' element={<Validator />} />
<Route path='/about' element={<AboutSection />} />
<Route path='*' element={<ErrorPage />} />
</Routes>
Expand Down
151 changes: 118 additions & 33 deletions frontend/src/components/Biosamples/BiosamplesResults.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
import '../Individuals/Individuals.css'
import '../../App.css'
import TableResultsBiosamples from '../Results/BiosamplesResults/TableResultsBiosamples'
import { useState, useEffect } from 'react'
import axios from 'axios'
import { AuthContext } from '../context/AuthContext'
import { useAuth } from 'oidc-react'
import configData from '../../config.json'
import { useContext } from 'react'
import TableResultsBiosamples from '../Results/BiosamplesResults/TableResultsBiosamples'


function BiosamplesResults (props) {
const [showLayout, setShowLayout] = useState(false)

const [beaconsList, setBeaconsList] = useState([])

const [error, setError] = useState(false)
const [response, setResponse] = useState(null)

const [numberResults, setNumberResults] = useState(0)
const [boolean, setBoolean] = useState(false)
const [results, setResults] = useState([])
const [show1, setShow1] = useState(false)
const [show2, setShow2] = useState(false)
const [show3, setShow3] = useState(false)

const [resultsPerDataset, setResultsDataset] = useState([])
const [resultsNotPerDataset, setResultsNotPerDataset] = useState([])

const [timeOut, setTimeOut] = useState(false)

const [logInRequired, setLoginRequired] = useState(true)
const [messageLoginCount, setMessageLoginCount] = useState('')
const [logInRequired, setLoginRequired] = useState(false)

const [messageLoginFullResp, setMessageLoginFullResp] = useState('')

const [limit, setLimit] = useState(0)
Expand Down Expand Up @@ -57,7 +63,6 @@ function BiosamplesResults (props) {
if (props.query !== null) {
if (props.query.includes(',')) {
queryStringTerm = props.query.split(',')

queryStringTerm.forEach((element, index) => {
element = element.trim()
if (
Expand All @@ -83,7 +88,6 @@ function BiosamplesResults (props) {
queryArray[index] = element.split('%')
queryArray[index].push('%')
}

const alphaNumFilter = {
id: queryArray[index][0],
operator: queryArray[index][2],
Expand Down Expand Up @@ -148,7 +152,7 @@ function BiosamplesResults (props) {
beaconsList.reverse()

if (props.query === null) {
// show all biosamples
// show all individuals

var jsonData1 = {
meta: {
Expand Down Expand Up @@ -188,16 +192,54 @@ function BiosamplesResults (props) {
{ headers: headers }
)
}

setTimeOut(true)

if (res.data.responseSummary.numTotalResults < 1) {
setError('No results. Please check the query and retry')
if (
res.data.responseSummary.numTotalResults < 1 ||
res.data.responseSummary.numTotalResults === undefined
) {
setError('ERROR. Please check the query and retry')
setNumberResults(0)
setBoolean(false)
} else {
res.data.response.resultSets.forEach((element, index) => {
if (res.data.response.resultSets[index].resultsCount > 0) {

if (element.id && element.id !== '') {
if (resultsPerDataset.length > 0) {
console.log(resultsPerDataset)
resultsPerDataset.forEach(element2 => {
if (element2[0] === element.beaconId) {
element2[1].push(element.id)
element2[2].push(element.exists)
element2[3].push(element.resultsCount)
} else {

let arrayResultsPerDataset = [
element.beaconId,
[element.id],
[element.exists],
[element.resultsCount]
]
resultsPerDataset.push(arrayResultsPerDataset)
}
})
} else {
let arrayResultsPerDataset = [
element.beaconId,
[element.id],
[element.exists],
[element.resultsCount]
]
resultsPerDataset.push(arrayResultsPerDataset)
}
}

if (element.id === undefined || element.id === '') {
let arrayResultsNoDatasets = [element.beaconId]
resultsNotPerDataset.push(arrayResultsNoDatasets)
}

if (res.data.response.resultSets[index].results) {
res.data.response.resultSets[index].results.forEach(
(element2, index2) => {
let arrayResult = [
Expand All @@ -209,9 +251,6 @@ function BiosamplesResults (props) {
)
}
})

setNumberResults(res.data.responseSummary.numTotalResults)
setBoolean(res.data.responseSummary.exists)
}
} else {
var jsonData2 = {
Expand All @@ -230,7 +269,6 @@ function BiosamplesResults (props) {
}
}
jsonData2 = JSON.stringify(jsonData2)

let token = null
if (auth.userData === null) {
token = getStoredToken()
Expand Down Expand Up @@ -260,15 +298,63 @@ function BiosamplesResults (props) {
res.data.responseSummary.numTotalResults < 1 ||
res.data.responseSummary.numTotalResults === undefined
) {
setError('No results. Please check the query and retry')
setError('ERROR. Please check the query and retry')
setNumberResults(0)
setBoolean(false)
} else {
setNumberResults(res.data.responseSummary.numTotalResults)
setBoolean(res.data.responseSummary.exists)

res.data.response.resultSets.forEach((element, index) => {
if (res.data.response.resultSets[index].resultsCount > 0) {
console.log(res.data.response)
if (element.id && element.id !== '') {
console.log(resultsPerDataset)
if (resultsPerDataset.length > 0) {
resultsPerDataset.forEach(element2 => {
console.log(element2[0])
console.log(element.beaconId)
if (element2[0] === element.beaconId) {
element2[1].push(element.id)
element2[2].push(element.exists)
element2[3].push(element.resultsCount)
} else {
console.log('hola')

let arrayResultsPerDataset = [
element.beaconId,
[element.id],
[element.exists],
[element.resultsCount]
]
let found = false

console.log(arrayResultsPerDataset)
resultsPerDataset.forEach(element => {
if (element[0] === arrayResultsPerDataset[0]) {
found = true
}
console.log(found)
})
if (found === false) {
resultsPerDataset.push(arrayResultsPerDataset)
}
}
})
} else {
let arrayResultsPerDataset = [
element.beaconId,
[element.id],
[element.exists],
[element.resultsCount]
]
console.log(arrayResultsPerDataset)
resultsPerDataset.push(arrayResultsPerDataset)
}
}

if (element.id === undefined || element.id === '') {
let arrayResultsNoDatasets = [element.beaconId]
resultsNotPerDataset.push(arrayResultsNoDatasets)
}

if (res.data.response.resultSets[index].results) {
res.data.response.resultSets[index].results.forEach(
(element2, index2) => {
let arrayResult = [
Expand All @@ -283,8 +369,8 @@ function BiosamplesResults (props) {
}
}
} catch (error) {
setError('Error. Please retry')
setTimeOut(false)
setError('Connection error. Please retry')
setTimeOut(true)
console.log(error)
}
}
Expand All @@ -308,15 +394,6 @@ function BiosamplesResults (props) {
setShow1(false)
setShow2(false)
}

const handleSkipChanges = e => {
setSkip(Number(e.target.value))
}

const handleLimitChanges = e => {
setLimit(Number(e.target.value))
}

const onSubmit = () => {
setSkipTrigger(skip)
setLimitTrigger(limit)
Expand All @@ -339,7 +416,7 @@ function BiosamplesResults (props) {
<div>
<div>
{' '}
{timeOut && (
{timeOut && error !== 'Connection error. Please retry' && (
<div>
<div className='selectGranularity'>
<h4>Granularity:</h4>
Expand All @@ -355,11 +432,15 @@ function BiosamplesResults (props) {
</div>
</div>
)}
{timeOut && error === 'Connection error. Please retry' && (
<h3>&nbsp; {error} </h3>
)}
{show3 && logInRequired === false && !error && (
<div className='containerTableResults'>
<TableResultsBiosamples
show={'full'}
results={results}
resultsPerDataset={resultsPerDataset}
beaconsList={beaconsList}
></TableResultsBiosamples>
</div>
Expand All @@ -370,6 +451,8 @@ function BiosamplesResults (props) {
<div className='containerTableResults'>
<TableResultsBiosamples
show={'count'}
resultsPerDataset={resultsPerDataset}
resultsNotPerDataset={resultsNotPerDataset}
results={results}
beaconsList={beaconsList}
></TableResultsBiosamples>
Expand All @@ -379,6 +462,8 @@ function BiosamplesResults (props) {
<div className='containerTableResults'>
<TableResultsBiosamples
show={'boolean'}
resultsPerDataset={resultsPerDataset}
resultsNotPerDataset={resultsNotPerDataset}
results={results}
beaconsList={beaconsList}
></TableResultsBiosamples>
Expand All @@ -390,4 +475,4 @@ function BiosamplesResults (props) {
)
}

export default BiosamplesResults
export default BiosamplesResults
Loading