From ca0009c18042424af96c92611142cfa7ba642c57 Mon Sep 17 00:00:00 2001 From: Harum Helmy Date: Thu, 30 Jul 2020 17:09:01 -0400 Subject: [PATCH] updated ddocs to include new filters, and updated dashboard functions to reflect new ddoc design --- src/components/dashboard.js | 170 ++++++++++++++---------------------- src/ddocs/ddoc-index.js | 54 +++++++++++- src/utils/search.js | 6 +- 3 files changed, 121 insertions(+), 109 deletions(-) diff --git a/src/components/dashboard.js b/src/components/dashboard.js index 2f08c95..08e720e 100644 --- a/src/components/dashboard.js +++ b/src/components/dashboard.js @@ -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 @@ -265,29 +179,53 @@ export default function Dashboard() {
Recommended to others{' '} } - // disabled={!(counts.hasData || {}).true} - checked={filters['recToOthers']} - onChange={e => handleFilterChange(e)} + checked={params.get('others') === 'true'} + onChange={e => { + const search = createPreprintQs( + { + hasOthersRec: e.target.checked || null + }, + location.search + ); + + history.push({ + pathname: location.pathname, + search, + state: { prevSearch: location.search } + }); + }} />
Recommended for peer review{' '} } - // disabled={!(counts.hasData || {}).true} - checked={filters['recForPeerReview']} - onChange={e => handleFilterChange(e)} + checked={params.get('peer') === 'true'} + onChange={e => { + const search = createPreprintQs( + { + hasPeerRec: e.target.checked || null + }, + location.search + ); + + history.push({ + pathname: location.pathname, + search, + state: { prevSearch: location.search } + }); + }} />
@@ -296,12 +234,24 @@ export default function Dashboard() { name="hasData" label={ - With reported data{' '} + With Reported Data{' '} } - // disabled={!(counts.hasData || {}).true} - checked={filters['hasData']} - onChange={e => handleFilterChange(e)} + checked={params.get('data') === 'true'} + onChange={e => { + const search = createPreprintQs( + { + hasData: e.target.checked || null + }, + location.search + ); + + history.push({ + pathname: location.pathname, + search, + state: { prevSearch: location.search } + }); + }} />
@@ -310,12 +260,24 @@ export default function Dashboard() { name="hasCode" label={ - With reported code{' '} + With Reported Code{' '} } - // disabled={!(counts.hasCode || {}).true} - checked={filters['hasCode']} - onChange={e=>handleFilterChange(e)} + checked={params.get('code') === 'true'} + onChange={e => { + const search = createPreprintQs( + { + hasCode: e.target.checked || null + }, + location.search + ); + + history.push({ + pathname: location.pathname, + search, + state: { prevSearch: location.search } + }); + }} />
@@ -357,7 +319,7 @@ export default function Dashboard() {
No more preprints.
) : (