diff --git a/.gitignore b/.gitignore index 5df88a31..6e8dbbbc 100644 --- a/.gitignore +++ b/.gitignore @@ -30,9 +30,10 @@ __pycache__ *.patch Vagrantfile -### vscode ### +### vscode / inteliJ ### .vscode/ *.code-workspace +.idea/ ## act secrets .secrets/ diff --git a/application/frontend/src/providers/DataProvider.tsx b/application/frontend/src/providers/DataProvider.tsx index a14060e5..12664b55 100644 --- a/application/frontend/src/providers/DataProvider.tsx +++ b/application/frontend/src/providers/DataProvider.tsx @@ -42,15 +42,11 @@ export const DataProvider = ({ children }: { children: React.ReactNode }) => { const initialLinks = storedDoc.links; let creLinks = initialLinks.filter( - (x) => x.document && !keyPath.includes(getStoreKey(x.document)) && getStoreKey(x.document) in dataStore + (x) => + !!x.document && !keyPath.includes(getStoreKey(x.document)) && getStoreKey(x.document) in dataStore ); - if (!creLinks.length) { - // leaves of the tree can be links that are included in the keyPath. - // If we don't add this here, the leaves are filtered out above (see ticket #514 on OpenCRE) - storedDoc.links = initialLinks.filter((x) => x.ltype === 'Contains' && !!x.document); - return storedDoc; - } + creLinks = creLinks.filter((x) => x.ltype === 'Contains'); //continue traversing the tree creLinks = creLinks.map((x) => ({ ltype: x.ltype, document: buildTree(x.document, keyPath) })); @@ -91,25 +87,20 @@ export const DataProvider = ({ children }: { children: React.ReactNode }) => { async () => { if (!Object.keys(dataStore).length) { try { - const result = await axios.get(`${apiUrl}/all_cres`); + const result = await axios.get(`${apiUrl}/all_cres?page=1&per_page=1000`); let data = result.data.data; - const page = result.data.page; - const total_pages = result.data.total_pages; let store = {}; - if (data.length && total_pages && page) { - for (let p = page; p < total_pages; p++) { - data.forEach((x) => { - store[getStoreKey(x)] = { - links: x.links, - displayName: getDocumentDisplayName(x), - url: getInternalUrl(x), - ...x, - }; - }); - const result = await axios.get(`${apiUrl}/all_cres?page=${p}`); - data = result.data.data; - } + if (data.length) { + data.forEach((x) => { + store[getStoreKey(x)] = { + links: x.links, + displayName: getDocumentDisplayName(x), + url: getInternalUrl(x), + ...x, + }; + }); + setLocalStorageObject(DATA_STORE_KEY, store, TWO_DAYS_MILLISECONDS); setDataStore(store); console.log('retrieved all cres'); diff --git a/application/web/web_main.py b/application/web/web_main.py index f928290a..0b5cc483 100644 --- a/application/web/web_main.py +++ b/application/web/web_main.py @@ -653,17 +653,15 @@ def all_cres() -> Any: page = 1 per_page = ITEMS_PER_PAGE if request.args.get("page") is not None and int(request.args.get("page")) > 0: - page = request.args.get("page") + page = int(request.args.get("page")) if ( request.args.get("per_page") is not None and int(request.args.get("per_page")) > 0 ): - per_page = request.args.get("per_page") + per_page = int(request.args.get("per_page")) - documents, page, total_pages = database.all_cres_with_pagination( - page, per_page=per_page - ) + documents, page, total_pages = database.all_cres_with_pagination(page, per_page) if documents: res = [doc.todict() for doc in documents] return jsonify({"data": res, "page": page, "total_pages": total_pages})