From 0aa42d3af29e0ec520709248bed9f168a8b188ab Mon Sep 17 00:00:00 2001 From: "Erin E. Sullivan" Date: Wed, 4 Dec 2024 10:37:36 -0500 Subject: [PATCH] Simplifying lists and citations. --- .../lists/components/ActionsList/index.js | 2 + .../lists/components/CitationAction/index.js | 40 +++++++++---------- src/modules/lists/components/List/index.js | 28 ++++--------- 3 files changed, 30 insertions(+), 40 deletions(-) diff --git a/src/modules/lists/components/ActionsList/index.js b/src/modules/lists/components/ActionsList/index.js index 2059e56b..ff909f89 100644 --- a/src/modules/lists/components/ActionsList/index.js +++ b/src/modules/lists/components/ActionsList/index.js @@ -114,6 +114,7 @@ const ActionsList = (props) => { {...data} action={props.active} setAlert={setAlert} + datastoreUid={props.datastore.uid} {...props} /> )} @@ -138,6 +139,7 @@ ActionsList.propTypes = { PropTypes.string, PropTypes.object ]), + datastore: PropTypes.object, setActive: PropTypes.func }; diff --git a/src/modules/lists/components/CitationAction/index.js b/src/modules/lists/components/CitationAction/index.js index 55c12e2a..91fb90dc 100644 --- a/src/modules/lists/components/CitationAction/index.js +++ b/src/modules/lists/components/CitationAction/index.js @@ -3,6 +3,7 @@ import { Anchor, Tab, TabPanel, Tabs } from '../../../reusable'; import React, { useEffect, useState } from 'react'; import { cite } from '../../../citations'; import PropTypes from 'prop-types'; +import { useSelector } from 'react-redux'; const citationOptions = [ { @@ -31,7 +32,10 @@ const citationOptions = [ } ]; -const CitationAction = ({ datastore, list, record, setActive, setAlert, viewType }) => { +const CitationAction = ({ datastoreUid, record, setActive, setAlert, viewType }) => { + const { [datastoreUid]: list = [] } = useSelector((state) => { + return state.lists || {}; + }); const [citations, setCitations] = useState({}); const [loading, setLoading] = useState(true); @@ -42,11 +46,11 @@ const CitationAction = ({ datastore, list, record, setActive, setAlert, viewType let records = []; if (viewType === 'Full') { - records = [{ datastoreUid: datastore.uid, recordUid: record.uid }]; + records = [{ datastoreUid, recordUid: record.uid }]; } if (viewType === 'List' && list.length > 0) { records = list.map((item) => { - return { datastoreUid: datastore.uid, recordUid: item.uid }; + return { datastoreUid, recordUid: item.uid }; }); } @@ -69,7 +73,7 @@ const CitationAction = ({ datastore, list, record, setActive, setAlert, viewType setLoading(false); }; fetchCitations(); - }, [viewType, record, datastore, list]); + }, [viewType, record, datastoreUid, list]); const handleCopy = (citationId) => { navigator.clipboard.writeText(document.getElementById(`citation-text-${citationId}`).innerText); @@ -93,31 +97,32 @@ const CitationAction = ({ datastore, list, record, setActive, setAlert, viewType })} {citationOptions.map((citationOption) => { - const citation = citations[citationOption.id]; + const { id, name } = citationOption; + const citation = citations[id]; return ( - + {citation ? ( <>

These citations are generated from a variety of data sources. Remember to check citation format and content for accuracy before including them in your work. @@ -134,7 +139,7 @@ const CitationAction = ({ datastore, list, record, setActive, setAlert, viewType