Skip to content
Snippets Groups Projects
Commit 653c2814 authored by Matthias Konitzny's avatar Matthias Konitzny :fire:
Browse files

The searchbar now correctly displays node colors.

parent 76e424a7
No related branches found
No related tags found
1 merge request!3Master into new editor
Pipeline #56828 passed
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
position: absolute; position: absolute;
left: 10px; left: 10px;
top: 65px; top: 65px;
border-radius: 10px; border-radius: 15px;
} }
.searchbar-results-circle { .searchbar-results-circle {
...@@ -58,7 +58,7 @@ ...@@ -58,7 +58,7 @@
flex-direction: row; flex-direction: row;
margin-top: -1px ; margin-top: -1px ;
padding-left: 10px; padding-left: 10px;
padding-right: 10px; padding-right: 15px;
align-items: center; align-items: center;
} }
......
...@@ -7,9 +7,15 @@ interface SearchBarProps { ...@@ -7,9 +7,15 @@ interface SearchBarProps {
minified: boolean; minified: boolean;
nodeSet: NodeData[]; nodeSet: NodeData[];
onSearch?: (node: NodeData) => void; onSearch?: (node: NodeData) => void;
nodeColors: Map<string, string>;
} }
function SearchBar({ minified, nodeSet, onSearch }: SearchBarProps) { function SearchBar({
minified,
nodeSet,
onSearch,
nodeColors,
}: SearchBarProps) {
const [isMinified, setMinified] = useState(minified); const [isMinified, setMinified] = useState(minified);
const [width, setWidth] = useState<number>(minified ? 0 : 100); const [width, setWidth] = useState<number>(minified ? 0 : 100);
const [inputText, setInputText] = useState(""); const [inputText, setInputText] = useState("");
...@@ -34,21 +40,17 @@ function SearchBar({ minified, nodeSet, onSearch }: SearchBarProps) { ...@@ -34,21 +40,17 @@ function SearchBar({ minified, nodeSet, onSearch }: SearchBarProps) {
setInputText(e.target.value.toLowerCase()); setInputText(e.target.value.toLowerCase());
}; };
const labels = nodeSet.map((node) => node.name); const filtered = nodeSet
const nodeLoopup = new Map<string, NodeData>();
labels.forEach((label, i) => nodeLoopup.set(label, nodeSet[i]));
const filtered = labels
.filter((el) => { .filter((el) => {
if (inputText !== "") { if (inputText !== "") {
return el.toLowerCase().includes(inputText); return el.name.toLowerCase().includes(inputText);
} }
}) })
.slice(0, 3); .slice(0, 3);
const handleNodeClick = (node: string) => { const handleNodeClick = (node: NodeData) => {
if (onSearch !== undefined) { if (onSearch !== undefined) {
onSearch(nodeLoopup.get(node)); onSearch(node);
} }
}; };
...@@ -84,15 +86,15 @@ function SearchBar({ minified, nodeSet, onSearch }: SearchBarProps) { ...@@ -84,15 +86,15 @@ function SearchBar({ minified, nodeSet, onSearch }: SearchBarProps) {
<div className={"searchbar-results"}> <div className={"searchbar-results"}>
{filtered.map((el) => ( {filtered.map((el) => (
<div <div
key={el} key={el.name}
className={"searchbar-result"} className={"searchbar-result"}
onMouseDown={() => handleNodeClick(el)} onMouseDown={() => handleNodeClick(el)}
> >
<div <div
className={"searchbar-results-circle"} className={"searchbar-results-circle"}
style={{ backgroundColor: "red" }} style={{ backgroundColor: nodeColors.get(el.type) }}
></div> ></div>
<div>{el}</div> <div>{el.name}</div>
</div> </div>
))} ))}
</div> </div>
......
...@@ -128,6 +128,7 @@ class Display extends React.Component< ...@@ -128,6 +128,7 @@ class Display extends React.Component<
minified={true} minified={true}
nodeSet={this.state.graph.nodes} nodeSet={this.state.graph.nodes}
onSearch={this.handleNodeChangeRequest} onSearch={this.handleNodeChangeRequest}
nodeColors={this.state.graph.nodeColors}
/> />
)} )}
</div> </div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment