From 2b81dd0036c2b5676d003fbc5993551909b615be Mon Sep 17 00:00:00 2001
From: ekachxaidze98 <65679299+ekachxaidze98@users.noreply.github.com>
Date: Mon, 25 Nov 2024 18:23:09 +0400
Subject: [PATCH] CORE: bring back tracking (#364)
---
api/data-provider.js | 10 +++++--
api/search.js | 8 +++++-
api/works.js | 11 +++++--
package-lock.json | 12 ++++----
pages/data-providers/[id].jsx | 5 ++--
pages/search/index.jsx | 3 +-
pages/works/[id].jsx | 9 ++++--
templates/search/index.jsx | 2 +-
templates/search/results.jsx | 54 ++++++++++++++++++++++++++++++++---
9 files changed, 92 insertions(+), 22 deletions(-)
diff --git a/api/data-provider.js b/api/data-provider.js
index 76e0c48e..d0f7e5c0 100644
--- a/api/data-provider.js
+++ b/api/data-provider.js
@@ -5,8 +5,14 @@ const API_V3_URL = process.env.API_URL.replace('/internal', '/v3')
const requestV3 = (url, ...args) => request(`${API_V3_URL}${url}`, ...args)
-const fetchMetadata = async (id) => {
- const { data } = await requestV3(`/data-providers/${id}`)
+// 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}` : ''}`
+ )
return data
}
diff --git a/api/search.js b/api/search.js
index 611f1f56..229619b9 100644
--- a/api/search.js
+++ b/api/search.js
@@ -3,7 +3,13 @@ import apiRequest from './index'
const FileDownload = require('js-file-download')
export const fetchWorks = async (body) => {
- const url = new URL(`/v3/search/works`, process.env.API_URL).href
+ const { t } = body
+ const split = t?.split('-')
+ const isUndefined = split?.some((item) => item === undefined)
+ const url = new URL(
+ `/v3/search/works${!isUndefined || t ? `?t=${t}` : ''}`,
+ process.env.API_URL
+ ).href
const { data: dataWorks } = await apiRequest(url, {
body,
method: 'POST',
diff --git a/api/works.js b/api/works.js
index dac82ae3..ef819489 100644
--- a/api/works.js
+++ b/api/works.js
@@ -1,7 +1,14 @@
import apiRequest from './index'
-const fetchWork = async (id) => {
- const url = new URL(`/v3/works/${id}`, process.env.API_URL).href
+// 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 { data } = await apiRequest(url)
return data
diff --git a/package-lock.json b/package-lock.json
index 1de866a8..cb30fdba 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -3109,9 +3109,9 @@
}
},
"node_modules/@oacore/design": {
- "version": "5.0.22",
- "resolved": "https://npm.pkg.github.com/download/@oacore/design/5.0.22/ed15a0f4fc51555a93a0f9f727e0de28915dee0c",
- "integrity": "sha512-ea+3KL837xLSnsGlWMAH0Ndcx58hBBky1kOXBS3dkpHYLnac0Me8i56TEkd4QoDntJzoMochhgr0bnFDLvsL6w==",
+ "version": "5.0.23",
+ "resolved": "https://npm.pkg.github.com/download/@oacore/design/5.0.23/38ad2c969481b8b5712e31857bba71e45fe23949",
+ "integrity": "sha512-rraU0Txug6EKuF8A7V9nmWbh2ZH1Up5sgsLmAdriO1dHQbbZOdbwZiy7BBKptmw9BBzbCWDaaV7qdnSJFBMfUw==",
"hasInstallScript": true,
"license": "UNLICENSED",
"dependencies": {
@@ -21669,9 +21669,9 @@
}
},
"@oacore/design": {
- "version": "5.0.22",
- "resolved": "https://npm.pkg.github.com/download/@oacore/design/5.0.22/ed15a0f4fc51555a93a0f9f727e0de28915dee0c",
- "integrity": "sha512-ea+3KL837xLSnsGlWMAH0Ndcx58hBBky1kOXBS3dkpHYLnac0Me8i56TEkd4QoDntJzoMochhgr0bnFDLvsL6w==",
+ "version": "5.0.23",
+ "resolved": "https://npm.pkg.github.com/download/@oacore/design/5.0.23/38ad2c969481b8b5712e31857bba71e45fe23949",
+ "integrity": "sha512-rraU0Txug6EKuF8A7V9nmWbh2ZH1Up5sgsLmAdriO1dHQbbZOdbwZiy7BBKptmw9BBzbCWDaaV7qdnSJFBMfUw==",
"requires": {
"@babel/runtime": "^7.12.1",
"@mdi/svg": "^5.8.55",
diff --git a/pages/data-providers/[id].jsx b/pages/data-providers/[id].jsx
index bc0a0f49..3156206a 100644
--- a/pages/data-providers/[id].jsx
+++ b/pages/data-providers/[id].jsx
@@ -30,11 +30,10 @@ export async function getServerSideProps({
query: searchParams,
}) {
const { id } = routeParams
- const { q = '', offset = 0, limit = 10, sort = 'recency' } = searchParams
-
+ const { q = '', offset = 0, limit = 10, sort = 'recency', t } = searchParams
const data = {}
try {
- const dataProvider = await fetchMetadata(id)
+ const dataProvider = await fetchMetadata(id, t)
const dataProviderStats = await fetchStats(id)
Object.assign(data, {
diff --git a/pages/search/index.jsx b/pages/search/index.jsx
index 184ae390..53906fda 100644
--- a/pages/search/index.jsx
+++ b/pages/search/index.jsx
@@ -25,7 +25,7 @@ export const getServerSideProps = async ({ query: searchParams }) => {
}
// TODO for nice response
// const { q, page = 1, limit = 10, sort = 'recency' } = searchParams
- const { q, page = 1, limit = 10, sort = 'relevance' } = searchParams
+ const { q, page = 1, limit = 10, sort = 'relevance', t } = searchParams
const data = {
currentPage: +page,
@@ -40,6 +40,7 @@ export const getServerSideProps = async ({ query: searchParams }) => {
q,
offset,
limit,
+ t,
exclude: ['fullText'],
sort: sort === 'recent' ? 'recency' : sort,
}
diff --git a/pages/works/[id].jsx b/pages/works/[id].jsx
index 38172e12..5d892f90 100644
--- a/pages/works/[id].jsx
+++ b/pages/works/[id].jsx
@@ -16,13 +16,18 @@ import { checkLogo, checkMembership } from 'utils/data-providers-transform'
const LOCALE = 'en-GB'
const CITATION_STYLES = ['apa', 'bibtex']
-export async function getServerSideProps({ params: routeParams, req }) {
+export async function getServerSideProps({
+ params: routeParams,
+ query: searchParams,
+ req,
+}) {
const { id } = routeParams
+ const { t } = searchParams
const data = {}
try {
- const rawWork = await fetchWork(id)
+ const rawWork = await fetchWork(id, t)
const { fullText: _, ...work } = rawWork
const outputs = await fetchWorkOutputs(id)
diff --git a/templates/search/index.jsx b/templates/search/index.jsx
index 79643032..90b4d61c 100644
--- a/templates/search/index.jsx
+++ b/templates/search/index.jsx
@@ -110,7 +110,7 @@ const SearchTemplate = observe(({ data }) => {
/>
)}
-