Skip to content

Commit

Permalink
fix: make it so smaller trust boundaries can be selected while inside…
Browse files Browse the repository at this point in the history
… another. Fixes #109
  • Loading branch information
Tethik committed Aug 13, 2024
1 parent b2652f9 commit 27f900a
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions app/src/components/model/board/Board.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,24 @@ function pointerCursor() {
document.body.style.cursor = "pointer";
}

function componentSort(a, b) {
// Order should be based on component size. This determines which component is selected when overlapped components are
// clicked in the diagram.
//
// 1. Non-trust boundary components
// 2. Smaller Trust Boundary by Area
// 3. Larger Trust Boundary by Area
//

if (a.type === COMPONENT_TYPE.TRUST_BOUNDARY && b.type === COMPONENT_TYPE.TRUST_BOUNDARY) {
let areaA = a.height * a.width;
let areaB = b.height * b.width;
return areaB - areaA;
}

return (a.type === COMPONENT_TYPE.TRUST_BOUNDARY ? -1 : 1) - (b.type === COMPONENT_TYPE.TRUST_BOUNDARY ? -1 : 1)
}

export default function Board() {
const dispatch = useDispatch();
const diagramContainerRef = useRef();
Expand Down Expand Up @@ -598,6 +616,9 @@ export default function Board() {
setClipboard([]);
}




return (
<div
id="diagram-container"
Expand Down Expand Up @@ -682,11 +703,7 @@ export default function Board() {
components
.slice()
.map((c) => ({ ...c, selected: c.id in selected }))
.sort(
(a, b) =>
(a.type === COMPONENT_TYPE.TRUST_BOUNDARY ? -1 : 1) -
(b.type === COMPONENT_TYPE.TRUST_BOUNDARY ? -1 : 1)
)
.sort(componentSort)
.map((c) => {
const ComponentType = componentTypes[c.type];
return (
Expand Down

0 comments on commit 27f900a

Please sign in to comment.