Skip to content

Commit

Permalink
Merge pull request #394 from tilfischer/main
Browse files Browse the repository at this point in the history
feat: lbe details open by default
  • Loading branch information
jliermann authored Sep 6, 2024
2 parents 4845986 + 29c962e commit 75a22e0
Show file tree
Hide file tree
Showing 7 changed files with 385 additions and 149 deletions.
43 changes: 43 additions & 0 deletions src/components/commons/ShortenDesc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import React, { useState } from "react";

// shorten the description of the experiment up to the next blank, comma or period after 100 characters

function ShortenDesc({ desc, length }) {
const [collapsed, setCollapsed] = useState(true);

if (desc.length <= length) {
return <React.Fragment>{desc}</React.Fragment>;
}

return (
<React.Fragment>
{collapsed ? (
<span
title={desc}
onClick={() => setCollapsed(!collapsed)}
style={{ cursor: "pointer" }}
>
{desc.slice(0, length) +
desc.slice(length).split(/[\s,\.]/)[0] +
" ..."}

<button className="lbe__block__author-trigger">
expand &#9660;
</button>
</span>
) : (
<span
onClick={() => setCollapsed(!collapsed)}
style={{ cursor: "pointer" }}
>
{desc}
<button className="lbe__block__author-trigger">
collapse &#9650;
</button>
</span>
)}
</React.Fragment>
);
}

export default ShortenDesc;
87 changes: 66 additions & 21 deletions src/components/lbe/FilterSection.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,78 @@
import React from "react";


// Custom functions

import { TextSearch, FilterButton } from "./LbeElements.js";


// Assemble buttons for filtering section

function LbeButtons( {repos, subdiscs, journals, lbeState, setLbeState} ) {
return(
<React.Fragment>
<div className="lbe__searchfilter__section"><h4>Filter by repositories</h4><p>{repos.map((props, idx) => <FilterButton key={idx} name={props} type="repo" numbered={true} {...{lbeState, setLbeState}} />)}</p></div>
<div className="lbe__searchfilter__section"><h4>Filter by subdisciplines</h4><p>{subdiscs.map((props, idx) => <FilterButton key={idx} name={props} type="subd" numbered={true} {...{lbeState, setLbeState}} />)}</p></div>
<div className="lbe__searchfilter__section"><h4>Filter by journals</h4><p>{journals.map((props, idx) => <FilterButton key={idx} name={props} type="journal" numbered={true} {...{lbeState, setLbeState}} />)}</p></div>
</React.Fragment>
)
function LbeButtons({ repos, subdiscs, journals, lbeState, setLbeState }) {
return (
<React.Fragment>
<div className="lbe__searchfilter__section">
<h4>Filter by repositories</h4>
<p>
{repos.map((props, idx) => (
<FilterButton
key={idx}
name={props}
type="repo"
numbered={true}
{...{ lbeState, setLbeState }}
/>
))}
</p>
</div>
<div className="lbe__searchfilter__section">
<h4>Filter by subdisciplines</h4>
<p>
{subdiscs.map((props, idx) => (
<FilterButton
key={idx}
name={props}
type="subd"
numbered={true}
{...{ lbeState, setLbeState }}
/>
))}
</p>
</div>
<div className="lbe__searchfilter__section">
<h4>Filter by journals</h4>
<p>
{journals.map((props, idx) => (
<FilterButton
key={idx}
name={props}
type="journal"
numbered={true}
{...{ lbeState, setLbeState }}
/>
))}
</p>
</div>
</React.Fragment>
);
}

function FilterSection( {repos, subdiscs, journals, lbeState, setLbeState, resultOutput} ) {

return(
<div className="lbe__searchfilter">
<div className="lbe__searchfilter__container">
<TextSearch {...{lbeState,setLbeState,resultOutput}} />
<LbeButtons {...{repos, subdiscs, journals, lbeState, setLbeState}} />
</div>
</div>
)
function FilterSection({
repos,
subdiscs,
journals,
lbeState,
setLbeState,
resultOutput,
}) {
return (
<div className="lbe__searchfilter">
<div className="lbe__searchfilter__container">
<TextSearch {...{ lbeState, setLbeState, resultOutput }} />
<LbeButtons
{...{ repos, subdiscs, journals, lbeState, setLbeState }}
/>
</div>
</div>
);
}

export default FilterSection;
export default FilterSection;
111 changes: 76 additions & 35 deletions src/components/lbe/LbeBody.js
Original file line number Diff line number Diff line change
@@ -1,66 +1,107 @@
import React from "react";


// Custom functions

import { RepoButton, FilterButton } from "./LbeElements.js";
import Authors from "./Authors.js";

import ShortenDesc from "../commons/ShortenDesc.js";
import ShortenButtons from "./ShortenButtons.js";

// Function for single lbe dataset block

function LbeBlock( { title, authors, journal, pubyear, linkpub, linkdata, linkcomment, description, lbeState, setLbeState } ) {

function LbeBlock({
title,
authors,
journal,
pubyear,
linkpub,
linkdata,
linkcomment,
description,
lbeState,
setLbeState,
}) {
// Extract DOI from link by cutting right of "doi.org"
var doi = linkpub.slice(linkpub.indexOf("doi.org")+8);
var doi = linkpub.slice(linkpub.indexOf("doi.org") + 8);

// Define set of repos in this dataset
var myRepos = Array.from(new Set(linkdata.map(obj => obj.name))).flat().sort((a, b) => a.localeCompare(b, undefined, {sensitivity: 'base'}));
var myRepos = Array.from(new Set(linkdata.map((obj) => obj.name)))
.flat()
.sort((a, b) => a.localeCompare(b, undefined, { sensitivity: "base" }));

return (
return (
<div className="lbe__block">
<div className="lbe__block__header">
<div className="lbe__block__header__title"><h3>{title}</h3></div>
<div className="lbe__block__header__link"><RepoButton name="Permalink" url={"./?doi=".concat(doi)} /></div>
<div className="lbe__block__header__title">
<h3>{title}</h3>
</div>
<div className="lbe__block__header__link">
<RepoButton name="Permalink" url={"./?doi=".concat(doi)} />
</div>
</div>

<p><em><Authors {...{authors}} length={10} /></em></p>
<p>
<em>
<Authors {...{ authors }} length={10} />
</em>
</p>

<p><em>{journal}</em> <strong>{pubyear}</strong>, DOI: <a href={linkpub} target="_blank">{doi}</a>.</p>
<p>
<em>{journal}</em> <strong>{pubyear}</strong>, DOI:{" "}
<a href={linkpub} target="_blank">
{doi}
</a>
.
</p>

<p>{myRepos.map((m,idx) =>
<FilterButton key={idx} name={m} type="repo" numbered={false} {...{lbeState, setLbeState}} />
)}
<p>
{myRepos.map((m, idx) => (
<FilterButton
key={idx}
name={m}
type="repo"
numbered={false}
funnel
title={"Filter datasets from " + m}
{...{ lbeState, setLbeState }}
/>
))}
</p>

<details className="lbe__details">
<summary>Details</summary>
<div className="lbe__details--collapsible">
<h4>Description</h4>
<p>{description}</p>
<hr className="lbe__block__hr" />

<h4>Links to datasets</h4>
<p>{linkdata.map((props, idx) => (
<details className="lbe__details" open={description.length <= 100}>
<summary>Description</summary>
<p>{description}</p>
</details>

<hr className="lbe__block__hr" />

<details className="lbe__details" open={linkdata.length <= 3}>
<summary>Links to datasets</summary>
<p>
{linkdata.map((props, idx) => (
<RepoButton key={idx} {...props} />
))}</p>
<p><em>{linkcomment}</em></p>
</div>
))}
</p>
<p>
<em>{linkcomment}</em>
</p>
</details>
</div>
);
);
}


// Render LBE entry list

function LbeBody( { list, lbeState, setLbeState } ) {
return(
<div className="lbe__body">
{list.map((props, idx) => (
<LbeBlock key={idx} {...props} {...{lbeState, setLbeState}} />
))}
</div>
)
function LbeBody({ list, lbeState, setLbeState }) {
return (
<div className="lbe__body">
{list.map((props, idx) => (
<LbeBlock key={idx} {...props} {...{ lbeState, setLbeState }} />
))}
</div>
);
}

export default LbeBody;
export default LbeBody;
Loading

0 comments on commit 75a22e0

Please sign in to comment.