Skip to content

Commit

Permalink
[514] 🐛 Fix explorer incomplete (#542)
Browse files Browse the repository at this point in the history
* fix all_cres "per_page" parameter

* set the data store for all CREs all at once

* ensure only "contains" and linked standards are included in the explorer

* fix lint issues
  • Loading branch information
dlicheva authored Jul 31, 2024
1 parent 6a31c53 commit 39f8723
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 29 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ __pycache__
*.patch
Vagrantfile

### vscode ###
### vscode / inteliJ ###
.vscode/
*.code-workspace
.idea/

## act secrets
.secrets/
Expand Down
37 changes: 14 additions & 23 deletions application/frontend/src/providers/DataProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) }));
Expand Down Expand Up @@ -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');
Expand Down
8 changes: 3 additions & 5 deletions application/web/web_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down

0 comments on commit 39f8723

Please sign in to comment.