Skip to content
This repository has been archived by the owner on Apr 29, 2022. It is now read-only.

Commit

Permalink
Merge pull request #156 from PREreview/dashboard-pages
Browse files Browse the repository at this point in the history
Updated ddoc-index + Dashboard filter functionality to reflect design changes
  • Loading branch information
jheretic authored Aug 3, 2020
2 parents 09a1266 + d853caa commit 99405da
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 107 deletions.
170 changes: 68 additions & 102 deletions src/components/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,95 +58,9 @@ export default function Dashboard() {
}, [apiQs]);

const [preprints, fetchResultsProgress] = usePreprintSearchResults(apiQs);

const [hoveredSortOption, setHoveredSortOption] = useState(null);

const [filters, setFilters] = useState({
hasCode: false,
hasData: false,
recToOthers: false,
recForPeerReview: false
})

const handleFilterChange = (e) => {
setFilters({
...filters,
[e.target.name]: !filters[e.target.name]
})
}

// calculating tags, following the logic in utils/stats
preprints.rows.length ? preprints.rows.map(preprint => {
let codeCount = 0
let dataCount = 0
let othersCount = 0
let peerCount = 0
let reviewCount = 0

preprint.doc.potentialAction.forEach(action => {
if (!checkIfIsModerated(action) && action.resultReview && action.resultReview.reviewAnswer) {
reviewCount += 1

const answers = action.resultReview.reviewAnswer;

for (let i = 0; i < answers.length; i++) {
const answer = answers[i];
if (answer.parentItem) {
const questionId = getId(answer.parentItem);
if (questionId === 'question:ynAvailableCode' && isYes(answer)) {
// Is the code used in the manuscript available?
codeCount += 1
}
if (questionId === 'question:ynPeerReview' && isYes(answer)) {
// Do you recommend this manuscript for peer review?
peerCount += 1
}
if (questionId === 'question:ynAvailableData' && isYes(answer)) {
// Are the data used in the manuscript available?
dataCount += 1
}
if (questionId === 'question:ynRecommend' && isYes(answer)) {
// Would you recommend this manuscript to others?
othersCount += 1
}
}
}
}
})

// majority rule calculation
const threshold = Math.ceil(reviewCount / 2)

preprint.doc.hasCode = codeCount > 0 && codeCount >= threshold;
preprint.doc.hasData = dataCount > 0 && dataCount >= threshold;
preprint.doc.recToOthers = othersCount > 0 && othersCount >= threshold;
preprint.doc.recForPeerReview = peerCount > 0 && peerCount >= threshold;
}) : null

// filtering preprints to render
const filteredPreprints = () => {

return preprints.rows.filter(preprint => {
if (filters.hasCode && !preprint.doc.hasCode) {
return false
}
if (filters.hasData && !preprint.doc.hasData) {
return false
}
if (filters.recToOthers && !preprint.doc.recToOthers) {
return false
}
if (filters.recForPeerReview && !preprint.doc.recForPeerReview) {
return false
}
return true
})
}

useEffect(() => {
filteredPreprints()
}, [filters])

/**
* builds an array where each item of the array is an object with an 'actions' key,
* the value to which are all of actions from each preprint
Expand Down Expand Up @@ -265,29 +179,55 @@ export default function Dashboard() {
<div className="dashboard__options_item">
<Checkbox
inputId="counts-others"
name="recToOthers"
name="hasOthersRec"
label={
<span className="facets__facet-label">
Recommended to others{' '}
</span>
}
// disabled={!(counts.hasData || {}).true}
checked={filters['recToOthers']}
onChange={e => handleFilterChange(e)}
checked={params.get('others') === 'true'}
onChange={e => {
const search = createPreprintQs(
{
text: 'COVID-19',
hasOthersRec: e.target.checked || null
},
location.search
);

history.push({
pathname: location.pathname,
search,
state: { prevSearch: location.search }
});
}}
/>
</div>
<div className="dashboard__options_item">
<Checkbox
inputId="counts-peer"
name="recForPeerReview"
name="hasPeerRec"
label={
<span className="facets__facet-label">
Recommended for peer review{' '}
</span>
}
// disabled={!(counts.hasData || {}).true}
checked={filters['recForPeerReview']}
onChange={e => handleFilterChange(e)}
checked={params.get('peer') === 'true'}
onChange={e => {
const search = createPreprintQs(
{
text: 'COVID-19',
hasPeerRec: e.target.checked || null
},
location.search
);

history.push({
pathname: location.pathname,
search,
state: { prevSearch: location.search }
});
}}
/>
</div>
<div className="dashboard__options_item">
Expand All @@ -299,9 +239,22 @@ export default function Dashboard() {
With reported data{' '}
</span>
}
// disabled={!(counts.hasData || {}).true}
checked={filters['hasData']}
onChange={e => handleFilterChange(e)}
checked={params.get('data') === 'true'}
onChange={e => {
const search = createPreprintQs(
{
text: 'COVID-19',
hasData: e.target.checked || null
},
location.search
);

history.push({
pathname: location.pathname,
search,
state: { prevSearch: location.search }
});
}}
/>
</div>
<div className="dashboard__options_item">
Expand All @@ -313,9 +266,22 @@ export default function Dashboard() {
With reported code{' '}
</span>
}
// disabled={!(counts.hasCode || {}).true}
checked={filters['hasCode']}
onChange={e=>handleFilterChange(e)}
checked={params.get('code') === 'true'}
onChange={e => {
const search = createPreprintQs(
{
text: 'COVID-19',
hasCode: e.target.checked || null
},
location.search
);

history.push({
pathname: location.pathname,
search,
state: { prevSearch: location.search }
});
}}
/>
</div>
</div>
Expand Down Expand Up @@ -357,7 +323,7 @@ export default function Dashboard() {
<div>No more preprints.</div>
) : (
<ul className="dashboard__preprint-list">
{filteredPreprints() ? filteredPreprints().map(row => (
{preprints.rows.length ? preprints.rows.map(row => (
<li key={row.id} className="dashboard__preprint-list__item">
<PreprintCard
isNew={false}
Expand Down
54 changes: 53 additions & 1 deletion src/ddocs/ddoc-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ const ddoc = {
hasReviews: 'keyword',
hasRequests: 'keyword',
hasData: 'keyword',
hasCode: 'keyword'
hasCode: 'keyword',
hasOthersRec: 'keyword',
hasPeerRec: 'keyword'
}
},
index: function(doc) {
Expand Down Expand Up @@ -275,6 +277,56 @@ const ddoc = {
facet: true
});

// has recommendations to others
var reviewsWithRecs = reviewActions.filter(function (action) {
if (action.resultReview && action.resultReview.reviewAnswer) {
var answers = action.resultReview.reviewAnswer;

for (var i = 0; i < answers.length; i++) {
var answer = answers[i];
if (answer.parentItem) {
var questionId =
answer.parentItem['@id'] || answer.parentItem;
if (questionId === 'question:ynRecommend') {
return (answer.text || '').toLowerCase().trim() === 'yes';
}
}
}
}
return false;
});

var hasOthersRec =
reviewsWithRecs.length && reviewsWithRecs.length >= threshold;
index('hasOthersRec', hasOthersRec ? 'true' : 'false', {
facet: true
});

// has recommendations for peer review
var reviewsWithPeers = reviewActions.filter(function (action) {
if (action.resultReview && action.resultReview.reviewAnswer) {
var answers = action.resultReview.reviewAnswer;

for (var i = 0; i < answers.length; i++) {
var answer = answers[i];
if (answer.parentItem) {
var questionId =
answer.parentItem['@id'] || answer.parentItem;
if (questionId === 'question:ynPeerReview') {
return (answer.text || '').toLowerCase().trim() === 'yes';
}
}
}
}
return false;
});

var hasPeerRec =
reviewsWithPeers.length && reviewsWithPeers.length >= threshold;
index('hasPeerRec', hasPeerRec ? 'true' : 'false', {
facet: true
});

// subjectName
var subjectCountMap = {};
reviewActions.forEach(function(action) {
Expand Down
6 changes: 2 additions & 4 deletions src/utils/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,10 @@ export function apifyPreprintQs(uiQs = '', bookmark) {
api.set(
'counts',
JSON.stringify([
// 'hasPeerRec',
// 'hasOthersRec',
'hasPeerRec',
'hasOthersRec',
'hasData',
'hasCode',
// 'hasPeerRec',
// 'hasOthersRec',
'hasReviews',
'hasRequests',
'subjectName'
Expand Down

0 comments on commit 99405da

Please sign in to comment.