Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#476] - db click navigation #489

Merged
merged 3 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 0 additions & 25 deletions src/components/editor/faultTree/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,30 +204,6 @@ const Editor = () => {
refreshTree();
};

const redirectToInstance = (navigateFrom: string) => {
if (faultTree?.manifestingEvent?.children) {
let map: { [name: string]: string } = {};
let children = faultTree?.manifestingEvent?.children;
if (faultTree?.manifestingEvent?.children.length > 0) {
faultTree?.manifestingEvent?.children.map((child) => {
if (child.children) {
children = [...children, ...child.children];
}
});
}
for (let i = 0; i < children.length; i++) {
const node = children[i];
const nodeKey = node.iri;
const nodeValue = node?.references?.isPartOf;
if (nodeKey && nodeValue) {
map[nodeKey] = nodeValue;
}
}
const redirectTo = map[navigateFrom].split("/").pop();
history(`/fta/${redirectTo}`);
}
};

return (
<div onContextMenu={handleOnContextMenu}>
{faultTree && (
Expand All @@ -249,7 +225,6 @@ const Editor = () => {
showPath={showPath}
showTable={showTable}
onScenarioSelect={(scenario: FaultEventScenario) => handleOnScenarioSelect(scenario)}
redirectToInstance={redirectToInstance}
/>
)}

Expand Down
16 changes: 9 additions & 7 deletions src/components/editor/faultTree/canvas/EditorCanvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { useCurrentFaultTree } from "@hooks/useCurrentFaultTree";
import { useFaultTrees } from "@hooks/useFaultTrees";
import { calculateCutSets } from "@services/faultTreeService";
import { SnackbarType, useSnackbar } from "@hooks/useSnackbar";
import { useNavigate } from "react-router-dom";

enum MOVE_NODE {
DRAGGING = 0,
Expand All @@ -49,7 +50,6 @@ interface Props {
showTable: boolean;
possibleFaultEventScenarios: FaultEventScenario[];
onScenarioSelect: (scenario: FaultEventScenario) => void;
redirectToInstance: (navigateFrom: string) => void;
}

const EditorCanvas = ({
Expand All @@ -70,10 +70,10 @@ const EditorCanvas = ({
showTable,
possibleFaultEventScenarios,
onScenarioSelect,
redirectToInstance,
}: Props) => {
const { classes } = useStyles();
const theme = useTheme();
const history = useNavigate();
const { t } = useTranslation();

const containerRef = useRef(null);
Expand Down Expand Up @@ -150,11 +150,13 @@ const EditorCanvas = ({
handleNodeMove(MOVE_NODE.RELEASING, elementView, evt, x, y);
},
"element:pointerdblclick": (elementView: joint.dia.ElementView) => {
const navigateFrom = elementView?.model.attributes["custom/faultEventIri"];
redirectToInstance(navigateFrom);
setTimeout(() => {
diagramZoom.reset();
}, 100);
if (elementView?.model.attributes[JOINTJS_NODE_MODEL.redirectTo]) {
const redirectTo = elementView?.model.attributes[JOINTJS_NODE_MODEL.redirectTo];
history(`/fta/${redirectTo}`);
setTimeout(() => {
diagramZoom.reset();
}, 100);
}
},
"blank:pointerclick": () => onBlankPointerClick(),
"blank:pointerdown": () => diagramZoom.enablePan(),
Expand Down
7 changes: 7 additions & 0 deletions src/components/editor/faultTree/shapes/RenderTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ const renderTree = async (container, node, parentShape = null, pathsToHighlight,
}
// @ts-ignore
nodeShape.set(JOINTJS_NODE_MODEL.faultEventIri, node.iri);

if (node?.references?.isPartOf) {
const iriOfReference = node.references.isPartOf.split("/").pop();
// @ts-ignore
nodeShape.set(JOINTJS_NODE_MODEL.redirectTo, iriOfReference);
}

const r = node.rectangle;
if (r && r.x && r.y && r.width && r.height) {
nodeShape.position(node.rectangle.x, node.rectangle.y);
Expand Down
1 change: 1 addition & 0 deletions src/components/editor/faultTree/shapes/constants.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export const JOINTJS_NODE_MODEL = {
faultEventIri: "custom/faultEventIri",
hasPersistentPosition: "custom/has-persistent-position",
redirectTo: "custom/redirectTo",
};

export const ERROR_PATH_COLOR = "#ff7f50";
Expand Down