Skip to content

Commit

Permalink
#SDSV-31 - Store dataset ids on local storage
Browse files Browse the repository at this point in the history
  • Loading branch information
jrmartin committed May 10, 2024
1 parent d2b6161 commit 098b4ce
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ const App = () => {
if ( version !== undefined && localStorage.getItem(config.datasetsStorage)?.version !== version[0] ) {
let parsedDatasets = []
datasets.forEach( node => {
parsedDatasets.push({name : node.name , doi : node.attributes?.hasDoi?.[0]});
parsedDatasets.push({ name : node.name , doi : node.attributes?.hasDoi?.[0], label : node.attributes ? node.attributes?.label?.[0]?.toLowerCase() : null});
});
datasetStorage = {
version : version[0],
Expand Down
32 changes: 28 additions & 4 deletions src/components/DatasetsListViewer/DatasetsListDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,24 @@ const DatasetsListDialog = (props) => {
let datasets = graph.nodes.filter((node) => node?.attributes?.hasUriApi);
datasets.forEach( node => node.attributes ? node.attributes.lowerCaseLabel = node.attributes?.label?.[0]?.toLowerCase() : null );
datasets = datasets.filter( node => node?.attributes?.statusOnPlatform?.[0]?.includes(PUBLISHED) );
dispatch(setDatasetsList(datasets));
setFilteredDatasets(datasets);


let version = graph.nodes.find( node => node?.attributes?.versionInfo)?.attributes?.versionInfo
let datasetStorage = {};
if ( version !== undefined && localStorage.getItem(config.datasetsStorage)?.version !== version[0] ) {
let parsedDatasets = []
datasets.forEach( node => {
parsedDatasets.push({ name : node.name , doi : node.attributes?.hasDoi?.[0], label : node.attributes ? node.attributes.lowerCaseLabel : null});
});
datasetStorage = {
version : version[0],
datasets : parsedDatasets
}

localStorage.setItem(config.datasetsStorage, JSON.stringify(datasetStorage));
dispatch(setDatasetsList(datasetStorage.datasets));
setFilteredDatasets(datasetStorage.datasets);
}
};
const summaryURL = config.repository_url + config.available_datasets;
fileHandler.get_remote_file(summaryURL, callback);
Expand Down Expand Up @@ -139,7 +155,15 @@ const DatasetsListDialog = (props) => {
}

useEffect(() => {
open && datasets.length === 0 && loadDatasets();
if ( open && datasets.length === 0 ) {
if ( localStorage.getItem(config.datasetsStorage) ) {
let storedDatasetsInfo = JSON.parse(localStorage.getItem(config.datasetsStorage));
dispatch(setDatasetsList(storedDatasetsInfo.datasets));
setFilteredDatasets(storedDatasetsInfo.datasets);
} else {
loadDatasets();
}
}
});

return (
Expand Down Expand Up @@ -202,7 +226,7 @@ const DatasetsListDialog = (props) => {
className="dataset_list_text"
dangerouslySetInnerHTML={{
__html:
getFormattedListTex(dataset.attributes?.label[0])
getFormattedListTex(dataset.label)
}}
/>
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/GraphViewerHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ export const getPrunedTree = (graph_id, layout) => {
*/
const updateConflictedNodes = (nodes, conflictNode, positionsMap, level, index, layout) => {
let matchIndex = index;
for ( let i = 0; i < index ; i++ ) {
for ( let i = 0; i <= index ; i++ ) {
let conflict = nodes.find ( n => !n.collapsed && n?.parent?.id === nodes[i]?.parent?.id)
if ( conflict === undefined ){
conflict = nodes.find ( n => !n.collapsed )
Expand Down
12 changes: 10 additions & 2 deletions src/utils/graphModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ export const rdfTypes = {
"key": "hasUriHuman",
"property": "hasUriHuman",
"label": "To be filled"
},
{
"type" : "owl",
"key" : "versionInfo",
"property" : "versionInfo",
"label" : "Version"
}
]
},
Expand Down Expand Up @@ -122,7 +128,8 @@ export const rdfTypes = {
"label": "Title",
"visible" : true,
"link" : {
"property" : "hasUriPublished"
"property" : "hasUriPublished",
"asText" : true
}
},
{
Expand Down Expand Up @@ -202,7 +209,8 @@ export const rdfTypes = {
"label": "DOI",
"visible" : true,
"link" : {
"property" : "hasUriPublished"
"property" : "hasUriPublished",
"asText" : true
}
},
{
Expand Down

0 comments on commit 098b4ce

Please sign in to comment.