Skip to content

Commit

Permalink
CORE: remove temp track
Browse files Browse the repository at this point in the history
  • Loading branch information
ekachxaidze98 committed Nov 22, 2024
1 parent 271bd5c commit 963c11f
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 83 deletions.
10 changes: 2 additions & 8 deletions api/data-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,8 @@ const API_V3_URL = process.env.API_URL.replace('/internal', '/v3')

const requestV3 = (url, ...args) => request(`${API_V3_URL}${url}`, ...args)

// eslint-disable-next-line camelcase
const fetchMetadata = async (id, search_id) => {
const split = search_id?.split('-')
const isUndefined = split?.some((item) => item === undefined)
const { data } = await requestV3(
// eslint-disable-next-line camelcase
`/data-providers/${id}${!isUndefined || search_id ? `?t=${search_id}` : ''}`
)
const fetchMetadata = async (id) => {
const { data } = await requestV3(`/data-providers/${id}`)
return data
}

Expand Down
11 changes: 2 additions & 9 deletions api/works.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
import apiRequest from './index'

// eslint-disable-next-line camelcase
const fetchWork = async (id, search_id) => {
const split = search_id?.split('-')
const isUndefined = split?.some((item) => item === undefined)
const url = new URL(
// eslint-disable-next-line camelcase
`/v3/works/${id}${!isUndefined || search_id ? `?t=${search_id}` : ''}`,
process.env.API_URL
).href
const fetchWork = async (id) => {
const url = new URL(`/v3/works/${id}`, process.env.API_URL).href

const { data } = await apiRequest(url)
return data
Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions pages/data-providers/[id].jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ export async function getServerSideProps({
query: searchParams,
}) {
const { id } = routeParams
const { q = '', offset = 0, limit = 10, sort = 'recency', t } = searchParams
const { q = '', offset = 0, limit = 10, sort = 'recency' } = searchParams

const data = {}
try {
const dataProvider = await fetchMetadata(id, t)
const dataProvider = await fetchMetadata(id)
const dataProviderStats = await fetchStats(id)

Object.assign(data, {
Expand Down
9 changes: 2 additions & 7 deletions pages/works/[id].jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,13 @@ import { checkLogo, checkMembership } from 'utils/data-providers-transform'
const LOCALE = 'en-GB'
const CITATION_STYLES = ['apa', 'bibtex']

export async function getServerSideProps({
params: routeParams,
query: searchParams,
req,
}) {
export async function getServerSideProps({ params: routeParams, req }) {
const { id } = routeParams
const { t } = searchParams

const data = {}

try {
const rawWork = await fetchWork(id, t)
const rawWork = await fetchWork(id)
const { fullText: _, ...work } = rawWork
const outputs = await fetchWorkOutputs(id)

Expand Down
2 changes: 1 addition & 1 deletion templates/search/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ const SearchTemplate = observe(({ data }) => {
/>
)}
</div>
<Results works={data.results} searchId={data.searchId} />
<Results works={data.results} />
{data.currentPage === 1000 && (
<div className={styles.more}>
Our search interface allows you to see only the first 10.000
Expand Down
54 changes: 4 additions & 50 deletions templates/search/results.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { checkType } from '../../utils/data-providers-transform'

import { formatDate } from 'utils/helpers'

const Results = ({ works, searchId }) =>
const Results = ({ works }) =>
works.map(
({
id,
Expand Down Expand Up @@ -35,68 +35,22 @@ const Results = ({ works, searchId }) =>
memberType?.billing_type === 'supporting' ||
memberType?.billing_type === 'sustaining'

const generateMetadataLink = (baseLink, propSearchId, propId) =>
`${baseLink}/?t=${propSearchId}-${propId}`

const modifiedReaderLink = readerLink
?.replace(/(https:\/\/)(core\.ac\.uk)/, '$1api.$2')
.replace('/reader/', '/reader-ui/')

const renderFullTextLink = ({
fullTextLink: innerFullTextLink,
downloadLink: innerDownloadLink,
modifiedReaderLink: innerModifiedReaderLink,
searchId: innerSearchId,
id: innerId,
}) => {
if (
innerFullTextLink == null &&
innerDownloadLink == null &&
innerModifiedReaderLink == null
)
return null
if (
(innerFullTextLink && innerFullTextLink.includes('core')) ||
(innerDownloadLink && innerDownloadLink.includes('core')) ||
(innerModifiedReaderLink &&
innerModifiedReaderLink.includes('api.core'))
) {
return generateMetadataLink(
innerModifiedReaderLink,
innerSearchId,
innerId
)
}
if (innerDownloadLink) return innerDownloadLink
return innerFullTextLink
}

return (
<SearchResult
id={`search-output-${id}`}
key={`search-result-${id}`}
variant="outlined"
className={styles.searchResults}
useLogo={!!checkBillingType()}
searchId={searchId}
renderRedirectLink
data={{
workId: id,
id,
title,
author: authors,
publicationVenue: publicationVenue || null,
publicationDate: publicationDate || null,
thumbnailUrl: thumbnailLink || `//core.ac.uk/image/${id}/medium`,
metadataLink:
generateMetadataLink(metadataLink, searchId, id) ||
generateMetadataLink(displayLink, searchId, id),
fullTextLink: renderFullTextLink({
fullTextLink,
downloadLink,
modifiedReaderLink,
searchId,
id,
}),
metadataLink: metadataLink || displayLink,
fullTextLink: fullTextLink || readerLink || downloadLink,
dataProviders: dataProviders || [],
isRecommended: memberType?.billing_type === 'sustaining',
}}
Expand Down

0 comments on commit 963c11f

Please sign in to comment.