Skip to content

Commit

Permalink
Merge pull request #759 from RockefellerArchiveCenter/issue-757
Browse files Browse the repository at this point in the history
Use citation endpoint instead of hardcoded logic
  • Loading branch information
helrond authored Dec 3, 2024
2 parents 1cb4d2a + dad5a7a commit c5e2200
Show file tree
Hide file tree
Showing 22 changed files with 126 additions and 182 deletions.
13 changes: 13 additions & 0 deletions src/components/PageRecords/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const PageRecords = ({ isDesktop, isMobile, myListCount, toggleInList }) => {
const [backendError, setBackendError] = useState({})
const [children, setChildren] = useState([])
const [childrenUri, setChildrenUri] = useState('')
const [citation, setCitation] = useState('')
const [downloadSize, setDownloadSize] = useState('')
const [found, setFound] = useState(true)
const [hasSeenMinimapIntro, setHasSeenMinimapIntro] = useState(true)
Expand Down Expand Up @@ -129,6 +130,17 @@ const PageRecords = ({ isDesktop, isMobile, myListCount, toggleInList }) => {
}
}, [itemUri])

/** Fetches citation when itemUri changes */
useEffect(() => {
if (itemUri) {
axios
.get(`${itemUri}/citation`)
.then(res => {
setCitation(res.data)
})
}
}, [itemUri])

/** Fetches ancestors when itemUri changes */
useEffect(() => {
if (itemUri) {
Expand Down Expand Up @@ -215,6 +227,7 @@ const PageRecords = ({ isDesktop, isMobile, myListCount, toggleInList }) => {
toggleIsContentShown={toggleIsContentShown} />
<RecordsDetail
ancestors={ancestors}
citation={citation}
downloadSize={downloadSize}
isAncestorsLoading={isAncestorsLoading}
isContentShown={isContentShown}
Expand Down
21 changes: 1 addition & 20 deletions src/components/RecordsDetail/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,6 @@ import { appendParams, dateString, hasAccessOrUse, noteText, noteTextByType } fr
import { isItemSaved } from '../MyListHelpers'
import './styles.scss'

const flattenObject = (obj, flattened = []) => {
flattened.push(obj.title);
if (obj.child) {
flattenObject(obj.child, flattened)
}
return flattened
}

const FoundInItem = ({ className, item, params, topLevel }) => (
<>
<li className={className}>
Expand Down Expand Up @@ -161,17 +153,6 @@ const RecordsDetail = props => {
props.item.uri && props.item.uri.split('/')[props.item.uri.split('/').length - 1]
)

/** Returns a citation string */
const dates = props.item.dates && props.item.dates.map(d => d.expression).join(', ')
const citation = (
[...new Set([props.item.title, dates])]
.concat(flattenObject(props.ancestors))
.concat(t({ comment: 'Institution name for citation', message: 'Rockefeller Archive Center' }))
.concat(window.location.origin + window.location.pathname)
.filter(n => n)
.join('; ')
)

const handleCitationButtonClick = () => {
setCitationCopied(true)
setTimeout(() => {setCitationCopied(false)}, '6000')
Expand Down Expand Up @@ -214,7 +195,7 @@ const RecordsDetail = props => {
null }
<Trans comment='Button to copy citation text'>
<button className='btn btn--sm btn--orange btn--detail mr-10 mb-10 p-8'
onClick={() => {navigator.clipboard.writeText(citation); handleCitationButtonClick()}}>
onClick={() => {navigator.clipboard.writeText(props.citation); handleCitationButtonClick()}}>
Cite<MaterialIcon icon='edit' className='material-icon--space-before'/>
</button>
</Trans>
Expand Down
2 changes: 1 addition & 1 deletion src/locales/de/messages.js

Large diffs are not rendered by default.

25 changes: 10 additions & 15 deletions src/locales/de/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ msgid "{source, select, null {Source: Rockefeller Archive Center} other {Source:
msgstr "{source, select, null {Quelle: Rockefeller Archive Center} other {Quelle: {source}}}"

#. Message to go back to previous search
#: src/components/RecordsDetail/index.js:193
#: src/components/RecordsDetail/index.js:174
msgid "<0/>Back to Search"
msgstr "<0/>Zurück zur Suche"

Expand Down Expand Up @@ -164,12 +164,12 @@ msgid "<0><1>Search Results</1></0>"
msgstr "<0><1>Suchergebnisse</1></0>"

#. Confirmation message when citation copied
#: src/components/RecordsDetail/index.js:209
#: src/components/RecordsDetail/index.js:190
msgid "<0>Citation information copied to clipboard.</0>"
msgstr "<0>Zitatinformationen in die Zwischenablage kopiert.</0>"

#. Button to copy citation text
#: src/components/RecordsDetail/index.js:215
#: src/components/RecordsDetail/index.js:196
msgid "<0>Cite<1/></0>"
msgstr "<0>Zitieren<1/></0>"

Expand Down Expand Up @@ -264,7 +264,7 @@ msgid "<0>View Online<1/></0>"
msgstr "<0>Online ansehen<1/></0>"

#. Buttons for online records
#: src/components/RecordsDetail/index.js:223
#: src/components/RecordsDetail/index.js:204
msgid "<0>View Online<1/></0><2>Download <3/></2>{0}"
msgstr "<0>Online ansehen<1/></0><2>Herunterladen <3/></2>{0}"

Expand All @@ -284,7 +284,7 @@ msgid "255 characters maximum"
msgstr "Maximal 255 Zeichen"

#. About minimap message
#: src/components/RecordsDetail/index.js:188
#: src/components/RecordsDetail/index.js:169
msgid "about minimap"
msgstr "über minimap"

Expand Down Expand Up @@ -435,7 +435,7 @@ msgid "Deselect all items"
msgstr "Alle Elemente abwählen"

#. Update message for selected record
#: src/components/PageRecords/index.js:118
#: src/components/PageRecords/index.js:119
msgid "Details under heading 1 have been updated to describe the selected records titled {0}"
msgstr "Die Angaben in Rubrik 1 wurden aktualisiert, um die ausgewählten Datensätze mit dem Titel {0} zu beschreiben"

Expand Down Expand Up @@ -514,12 +514,12 @@ msgid "Format"
msgstr "Medientyp"

#. Panel Format message
#: src/components/RecordsDetail/index.js:72
#: src/components/RecordsDetail/index.js:64
msgid "Formats"
msgstr "Medientyp"

#. Panel Found In message
#: src/components/RecordsDetail/index.js:89
#: src/components/RecordsDetail/index.js:81
msgid "Found In"
msgstr "Gefunden in"

Expand Down Expand Up @@ -742,7 +742,7 @@ msgstr "öffnet E-Mail"
#: src/components/ModalMyList/index.js:520
#: src/components/ModalMyList/index.js:583
#: src/components/PageDigitalObject/index.js:112
#: src/components/RecordsDetail/index.js:229
#: src/components/RecordsDetail/index.js:210
msgid "opens in a new window"
msgstr "öffnet sich in einem neuen Fenster"

Expand Down Expand Up @@ -888,11 +888,6 @@ msgstr "Reproduktionen anfordern"
msgid "Request in Reading Room"
msgstr "In den Lesesaal Anfordern"

#. Institution name for citation
#: src/components/RecordsDetail/index.js:169
msgid "Rockefeller Archive Center"
msgstr "Rockefeller Archive Center"

#. Primary Title
#: src/components/Footer/index.js:14
msgid "Rockefeller<0/>Archive Center"
Expand Down Expand Up @@ -1013,7 +1008,7 @@ msgid "Sign in to RACcess"
msgstr "Bei RACcess anmelden"

#. Panel Extent Size message
#: src/components/RecordsDetail/index.js:50
#: src/components/RecordsDetail/index.js:42
msgid "Size"
msgstr "Umfang"

Expand Down
2 changes: 1 addition & 1 deletion src/locales/en/messages.js

Large diffs are not rendered by default.

25 changes: 10 additions & 15 deletions src/locales/en/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ msgid "{source, select, null {Source: Rockefeller Archive Center} other {Source:
msgstr "{source, select, null {Source: Rockefeller Archive Center} other {Source: {source}}}"

#. Message to go back to previous search
#: src/components/RecordsDetail/index.js:193
#: src/components/RecordsDetail/index.js:174
msgid "<0/>Back to Search"
msgstr "<0/>Back to Search"

Expand Down Expand Up @@ -164,12 +164,12 @@ msgid "<0><1>Search Results</1></0>"
msgstr "<0><1>Search Results</1></0>"

#. Confirmation message when citation copied
#: src/components/RecordsDetail/index.js:209
#: src/components/RecordsDetail/index.js:190
msgid "<0>Citation information copied to clipboard.</0>"
msgstr "<0>Citation information copied to clipboard.</0>"

#. Button to copy citation text
#: src/components/RecordsDetail/index.js:215
#: src/components/RecordsDetail/index.js:196
msgid "<0>Cite<1/></0>"
msgstr "<0>Cite<1/></0>"

Expand Down Expand Up @@ -264,7 +264,7 @@ msgid "<0>View Online<1/></0>"
msgstr "<0>View Online<1/></0>"

#. Buttons for online records
#: src/components/RecordsDetail/index.js:223
#: src/components/RecordsDetail/index.js:204
msgid "<0>View Online<1/></0><2>Download <3/></2>{0}"
msgstr "<0>View Online<1/></0><2>Download <3/></2>{0}"

Expand All @@ -284,7 +284,7 @@ msgid "255 characters maximum"
msgstr "255 characters maximum"

#. About minimap message
#: src/components/RecordsDetail/index.js:188
#: src/components/RecordsDetail/index.js:169
msgid "about minimap"
msgstr "about minimap"

Expand Down Expand Up @@ -435,7 +435,7 @@ msgid "Deselect all items"
msgstr "Deselect all items"

#. Update message for selected record
#: src/components/PageRecords/index.js:118
#: src/components/PageRecords/index.js:119
msgid "Details under heading 1 have been updated to describe the selected records titled {0}"
msgstr "Details under heading 1 have been updated to describe the selected records titled {0}"

Expand Down Expand Up @@ -514,12 +514,12 @@ msgid "Format"
msgstr "Format"

#. Panel Format message
#: src/components/RecordsDetail/index.js:72
#: src/components/RecordsDetail/index.js:64
msgid "Formats"
msgstr "Formats"

#. Panel Found In message
#: src/components/RecordsDetail/index.js:89
#: src/components/RecordsDetail/index.js:81
msgid "Found In"
msgstr "Found In"

Expand Down Expand Up @@ -742,7 +742,7 @@ msgstr "opens email"
#: src/components/ModalMyList/index.js:520
#: src/components/ModalMyList/index.js:583
#: src/components/PageDigitalObject/index.js:112
#: src/components/RecordsDetail/index.js:229
#: src/components/RecordsDetail/index.js:210
msgid "opens in a new window"
msgstr "opens in a new window"

Expand Down Expand Up @@ -888,11 +888,6 @@ msgstr "Request Copies"
msgid "Request in Reading Room"
msgstr "Request in Reading Room"

#. Institution name for citation
#: src/components/RecordsDetail/index.js:169
msgid "Rockefeller Archive Center"
msgstr "Rockefeller Archive Center"

#. Primary Title
#: src/components/Footer/index.js:14
msgid "Rockefeller<0/>Archive Center"
Expand Down Expand Up @@ -1013,7 +1008,7 @@ msgid "Sign in to RACcess"
msgstr "Sign in to RACcess"

#. Panel Extent Size message
#: src/components/RecordsDetail/index.js:50
#: src/components/RecordsDetail/index.js:42
msgid "Size"
msgstr "Size"

Expand Down
Loading

0 comments on commit c5e2200

Please sign in to comment.