Skip to content

Commit f8cdd7e

Browse files
authored
Merge pull request #215 from CBIIT/develop_3.0.1
Develop 3.0.1
2 parents f281945 + 98dd23f commit f8cdd7e

File tree

6 files changed

+66
-41
lines changed

6 files changed

+66
-41
lines changed

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "evs-sip",
3-
"version": "v3.0.0",
3+
"version": "v3.0.1",
44
"private": true,
55
"homepage": "/evssip/",
66
"dependencies": {

server/service/esapi/esapicontroller.js

+15-9
Original file line numberDiff line numberDiff line change
@@ -374,18 +374,18 @@ const getGraphicalPCDCDictionary = (project = null, node, prop) => {
374374
};
375375
let result;
376376

377-
// TODO - fix result being empty after making same request for 2nd time
378-
// if (project) {
379-
// result = cache.getValue(`pcdc_dict_${project}`);
380-
// } else {
381-
// result = cache.getValue("pcdc_dict");
382-
// }
377+
// Read from cache
378+
if (project) {
379+
result = cache.getValue(`public_pcdc_dict_${project}`);
380+
} else {
381+
result = cache.getValue("public_pcdc_dict");
382+
}
383383

384384
if (true || result === undefined) {
385385
let jsonData = shared.readPCDCMapping();
386386
result = generatePCDCData(jsonData, {});
387387
//result = generatePCDCData(jsonData, {Relationships: {}});
388-
cache.setValue("pcdc_dict", result, config.item_ttl);
388+
cache.setValue("public_pcdc_dict", result, config.item_ttl);
389389
}
390390

391391
// Obtain nodes from specified project
@@ -417,7 +417,13 @@ const getGraphicalPCDCDictionary = (project = null, node, prop) => {
417417
project_result[n].links.push(linkItem);
418418
}
419419
});
420-
cache.setValue("pcdc_dict_" + project, project_result, config.item_ttl);
420+
421+
// Cache the results
422+
if (project) {
423+
cache.setValue(`public_pcdc_dict_${project}`, project_result, config.item_ttl);
424+
} else {
425+
cache.setValue("public_pcdc_dict", project_result, config.item_ttl);
426+
}
421427

422428
// Handle empty results
423429
if (project_result.results.length === 0 ) {
@@ -442,7 +448,7 @@ const getPcdcNodes = (nodes, desiredNode, desiredProp) => {
442448
const desiredNodes = [];
443449

444450
// Gather desired nodes into an array
445-
for(const nodeName in nodes) {
451+
for (const nodeName in nodes) {
446452
const node = nodes[nodeName];
447453
const isCorrectNode = node.node_name?.toLowerCase() === desiredNode?.toLowerCase();
448454

server/service/search/controller.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ const getGraphicalCTDCDictionary = (req, res) => {
468468
};
469469

470470
const getGraphicalPCDCDictionary = (req, res) => {
471-
let project = req.query.project == "" ? "AML" : req.query.project;
471+
let project = (req.query.project !== undefined && req.query.project !== '') ? req.query.project : 'AML';
472472
let jsonData = shared.getGraphicalPCDCDictionary(project);
473473
res.json(jsonData);
474474
};

server/service/search/shared.js

+34-27
Original file line numberDiff line numberDiff line change
@@ -1284,35 +1284,42 @@ const getCompareResult_conflict = async function(searchText, from , limit) {
12841284

12851285
const getGraphicalPCDCDictionary = (project) => {
12861286
let project_result = cache.getValue("pcdc_dict_" + project);
1287-
if (project_result == undefined) {
1288-
let result = cache.getValue("pcdc_dict");
1289-
if (result == undefined) {
1290-
let jsonData = readPCDCMapping();
1291-
result = generatePCDCData(jsonData, {});
1292-
//result = generatePCDCData(jsonData, {Relationships: {}});
1293-
cache.setValue("pcdc_dict", result, config.item_ttl);
1287+
1288+
// Early return for successful cache retrieval
1289+
if (project_result !== undefined) {
1290+
return project_result;
1291+
}
1292+
1293+
let result = cache.getValue("pcdc_dict");
1294+
1295+
if (result === undefined) {
1296+
let jsonData = readPCDCMapping();
1297+
result = generatePCDCData(jsonData, {});
1298+
//result = generatePCDCData(jsonData, {Relationships: {}});
1299+
cache.setValue("pcdc_dict", result, config.item_ttl);
1300+
}
1301+
1302+
project_result = result[project];
1303+
let nodes = Object.keys(project_result);
1304+
//create fake relationship for graphical display purpose
1305+
nodes.forEach((n, i) => {
1306+
if (i - 4 >= 0) {
1307+
let linkItem = {};
1308+
linkItem["name"] = nodes[i - 4];
1309+
linkItem["backref"] = n;
1310+
linkItem["label"] = "of_pcdc";
1311+
linkItem["target_type"] = nodes[i - 4];
1312+
linkItem["required"] = false;
1313+
1314+
project_result[n].links.push(linkItem);
12941315
}
1316+
});
12951317

1296-
project_result = result[project];
1297-
let nodes = Object.keys(project_result);
1298-
//create fake relationship for graphical display purpose
1299-
1300-
nodes.forEach((n, i) => {
1301-
if (i - 4 >= 0) {
1302-
let linkItem = {};
1303-
linkItem["name"] = nodes[i - 4];
1304-
linkItem["backref"] = n;
1305-
linkItem["label"] = "of_pcdc";
1306-
linkItem["target_type"] = nodes[i - 4];
1307-
linkItem["required"] = false;
1308-
1309-
// TODO - find out why linkItem is sometimes undefined
1310-
if (linkItem) {
1311-
project_result[n].links.push(linkItem);
1312-
}
1313-
}
1314-
});
1315-
cache.setValue("pcdc_dict_" + project, project_result, config.item_ttl);
1318+
// Cache the results
1319+
if (project) {
1320+
cache.setValue(`pcdc_dict_${project}`, project_result, config.item_ttl);
1321+
} else {
1322+
cache.setValue("pcdc_dict", project_result, config.item_ttl);
13161323
}
13171324

13181325
return project_result;

src/pages/Search/SearchBox.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, { useState, useRef } from 'react';
22
import styled from 'styled-components';
3+
import debounce from 'lodash.debounce';
34
import { apiSuggest } from '../../api';
45
import { InputGroup, FormControl, Button } from 'react-bootstrap';
56
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
@@ -321,9 +322,20 @@ const SearchBox = (props) => {
321322
setSelectIndexState(-1);
322323
};
323324

325+
const suggestHandlerDebounce = useRef(
326+
debounce((value) => {
327+
apiSuggest(value)
328+
.then(result => setSuggestState(result))
329+
.catch(error => {
330+
console.log(error);
331+
});
332+
}, 300)
333+
).current;
334+
324335
const suggestHandler = event => {
325-
setSearchState(event.target.value);
326-
apiSuggest(event.target.value).then(result => setSuggestState(result));
336+
let value = event.target.value;
337+
setSearchState(value);
338+
suggestHandlerDebounce(value);
327339
};
328340

329341
const matchOptionsHandler = event => {

0 commit comments

Comments
 (0)