Skip to content

Commit

Permalink
add css class and code in utils to highlight nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
nbarlowATI committed May 24, 2022
1 parent 5d88a3b commit 41c4fa3
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 5 deletions.
33 changes: 30 additions & 3 deletions frontend/src/components/CaseContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ import EditableText from "./EditableText.js";
import ItemViewer from "./ItemViewer.js";
import ItemEditor from "./ItemEditor.js";
import ItemCreator from "./ItemCreator.js";
import { getBaseURL, jsonToMermaid } from "./utils.js";
import {
getBaseURL,
jsonToMermaid,
highlightNode,
removeHighlight,
} from "./utils.js";
import configData from "../config.json";
import "./CaseContainer.css";

Expand Down Expand Up @@ -190,7 +195,17 @@ class CaseContainer extends Component {
let itemType = chunks[0];
let itemId = chunks[1];
this.setState({ itemType: itemType, itemId: itemId });
console.log("in showViewOrEditLayer, just set state");
this.setState({ loading: true });

this.setState({
mermaid_md: highlightNode(
this.state.mermaid_md,
this.state.itemType,
this.state.itemId
),
});
console.log("setting highlight?");
this.setState({ loading: false });
if (this.inEditMode()) {
this.showEditLayer(itemType, itemId);
} else {
Expand All @@ -217,7 +232,7 @@ class CaseContainer extends Component {
// this should be redundant, as the itemId and itemType should already
// be set when showViewLayer is called, but they can't do any harm..
this.setState({ itemType: itemType, itemId: itemId });
this.hideViewLayer();
// this.hideViewLayer();
this.setState({ showEditLayer: true });
}

Expand All @@ -241,11 +256,23 @@ class CaseContainer extends Component {
this.setState({ showCasePermissionLayer: true });
}

resetHighlight() {
this.setState({ loading: true });
this.setState({
mermaid_md: removeHighlight(this.state.mermaid_md),
});
setTimeout(() => {
this.setState({ loading: false });
}, 100);
}

hideViewLayer() {
this.resetHighlight();
this.setState({ showViewLayer: false });
}

hideEditLayer() {
// this.resetHighlight();
this.setState({ showEditLayer: false, itemType: null, itemId: null });
}

Expand Down
29 changes: 28 additions & 1 deletion frontend/src/components/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ function jsonToMermaid(in_json) {
if (obj.level !== undefined) {
outputmd += "\nclass " + node + " classLevel" + obj.level + ";\n";
}

return outputmd;
}

Expand Down Expand Up @@ -110,6 +111,7 @@ function jsonToMermaid(in_json) {
}
}
}
console.log("outputmd is ", outputmd);
return outputmd;
}

Expand All @@ -126,4 +128,29 @@ function jsonToMermaid(in_json) {
return outputmd;
}

export { getBaseURL, jsonToMermaid, sanitizeForMermaid };
function highlightNode(inputMarkdown, nodeType, nodeId) {
// add a classDef to the bottom of the markdown highlighting a node
inputMarkdown = removeHighlight(inputMarkdown);
inputMarkdown +=
"\nclass " + nodeType + "_" + nodeId + " classHighlighted;\n";
return inputMarkdown;
}

function removeHighlight(inputMarkdown) {
// remove last line of markdown if it contains highlight
let lines = inputMarkdown.split("\n");
let numLines = lines.length;
if (lines[numLines - 2].includes("classHighlighted")) {
lines.splice(numLines - 2, numLines - 1);
inputMarkdown = lines.join("\n");
}
return inputMarkdown;
}

export {
getBaseURL,
jsonToMermaid,
sanitizeForMermaid,
highlightNode,
removeHighlight,
};
3 changes: 2 additions & 1 deletion frontend/src/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"classProjectClaimLevel3": "fill:#9db4e6,color:#FFF",
"classSystemClaimLevel1": "fill:#009249,color:#FFF",
"classSystemClaimLevel2": "fill:#24995e,color:#FFF",
"classSystemClaimLevel3": "fill:#3ea572,color:#FFF"
"classSystemClaimLevel3": "fill:#3ea572,color:#FFF",
"classHighlighted": "stroke:#FF0,stroke-width:4,fill:#7700bb,color:#FF0"
},
"navigation": {
"AssuranceCase": {
Expand Down

0 comments on commit 41c4fa3

Please sign in to comment.