Page MenuHomec4science

ResultCard.js
No OneTemporary

File Metadata

Created
Mon, Jun 10, 19:59

ResultCard.js

/*
This is the Open Access Check Tool (OACT).
The publication of scientific articles as Open Access (OA), usually in the variants "Green OA" and "Gold OA", allows free access to scientific research results and their largely unhindered dissemination. Often, however, the multitude of available publication conditions makes the decision in favor of a particular journal difficult: requirements of the funding agencies and publication guidelines of the universities and colleges must be carefully compared with the offers of the publishing houses, and separately concluded publication agreements can also offer additional benefits. The "OA Compliance Check Tool" provides a comprehensive overview of the possible publication conditions for a large number of journals, especially for the Swiss university landscape, and thus supports the decision-making process.
© All rights reserved. ECOLE POLYTECHNIQUE FEDERALE DE LAUSANNE, Switzerland, Scientific Information and Libraries, 2022
See LICENSE.TXT for more details.
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with this program. If not, see
<https://www.gnu.org/licenses/>.
*/
import React from "react"
import "./ResultCard.css"
import TermCard from "../components/TermCard"
import Accordion from '@mui/material/Accordion';
import AccordionSummary from '@mui/material/AccordionSummary';
import AccordionDetails from '@mui/material/AccordionDetails';
import Typography from '@mui/material/Typography';
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
import Badge from '@mui/material/Badge';
import { HiOutlineDocumentDuplicate } from "react-icons/hi";
import { HiOutlineDocument } from "react-icons/hi";
import Grid from '@mui/material/Grid'
import Box from '@mui/material/Box'
import Container from '@mui/material/Container';
export default function ResultCard({result}) {
const termresult = []
const termArray = result?.map(i=>(
// get condition details
i.term?.map(j =>(
// termresult.push([j, i.id, i.comment, i.condition_type])
termresult.push([j, [i.id, i.comment, i.condition_type, i.source]])
))
))
//groupyBy array
function groupBy(objectArray, property) {
// console.log(objectArray)
return objectArray.reduce((acc, obj) => {
// console.log(obj[0])
// Modified from original version as we use it to group by a property that is part of an array
for (const repeatable_property of obj[0][property]) {
const key = repeatable_property.description;
if (!acc[key]) {
acc[key] = [];
}
// Add object to list for given key's value
acc[key].push(obj);
}
return acc;
}, {});
}
const groupedTerm = groupBy(termresult, 'version')
//first version
// console.log(groupedTerm[1])
//convert object into array
const termItem = Object.entries(groupedTerm)
//manage the display order
function orderVersion (version) {
if (version[0] ==="Submitted version") {
version.unshift(3)
}
else if (version[0] === "Published version") {
version.unshift(1)
}
else if (version[0] === "Accepted version") {
version.unshift(2)
}
}
//apply the function for each version
termItem?.map(i=>(
orderVersion(i)
))
termItem.sort()
console.log(termItem)
const displayVersion =
termItem?.map(item =>(
<div sx={{ flexGrow: 1 }} >
<Accordion className="term-version">
<AccordionSummary
expandIcon={<ExpandMoreIcon />}
aria-controls="panel1a-content"
id="panel1a-header"
>
<Typography className={classes.heading}>
{item?.map(i => (
<Badge anchorOrigin={{
vertical: 'top',
horizontal: 'right',
}}
style={{
padding: "0.1rem",
color: "black",
}}
badgeContent={typeof i === "object" && i.length} >{typeof i === "string" && i} {typeof i === "object" && i.length > 1 ? <HiOutlineDocumentDuplicate />: typeof i === "object" && <HiOutlineDocument/>}</Badge>
))
}
</Typography>
</AccordionSummary>
<AccordionDetails>
<Typography>
<Container maxWidth="xl" >
<Grid container spacing={0.5} direction="row">
{item?.map(j => (
typeof j === "object" &&
j?.map(k => (
<TermCard term={k}/>
))
))
}
</Grid>
</Container>
</Typography>
</AccordionDetails>
</Accordion>
</div>
))
return (
//level 0
<div className={classes.root} >
{displayVersion}
</div>
)
}

Event Timeline