From 7a5a4ba3761e1e122a52bf4ef190b13035ea728c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Wed, 9 Oct 2024 07:40:48 +0100 Subject: [PATCH] fix: Correctly construct URL by re-ordering portals (#3773) --- .../pages/FlowEditor/lib/__tests__/getURLForNode.test.ts | 4 ++-- editor.planx.uk/src/pages/FlowEditor/lib/store/editor.ts | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/editor.planx.uk/src/pages/FlowEditor/lib/__tests__/getURLForNode.test.ts b/editor.planx.uk/src/pages/FlowEditor/lib/__tests__/getURLForNode.test.ts index 3f84238b77..40e126f2b2 100644 --- a/editor.planx.uk/src/pages/FlowEditor/lib/__tests__/getURLForNode.test.ts +++ b/editor.planx.uk/src/pages/FlowEditor/lib/__tests__/getURLForNode.test.ts @@ -54,14 +54,14 @@ describe("constructing URLs for nodes", () => { test("a question node, deeply within internal portals", () => { const url = getURLForNode("tarantinoMovieQuestion"); expect(url).toEqual( - "/testTeam/testFlow,tarantinoPortal,moviesPortal/nodes/tarantinoPortal/nodes/tarantinoMovieQuestion/edit", + "/testTeam/testFlow,moviesPortal,tarantinoPortal/nodes/tarantinoPortal/nodes/tarantinoMovieQuestion/edit", ); }); test("an answer node, deeply within internal portals", () => { const url = getURLForNode("reservoirDogsAnswer"); expect(url).toEqual( - "/testTeam/testFlow,tarantinoPortal,moviesPortal/nodes/tarantinoPortal/nodes/tarantinoMovieQuestion/edit", + "/testTeam/testFlow,moviesPortal,tarantinoPortal/nodes/tarantinoPortal/nodes/tarantinoMovieQuestion/edit", ); }); diff --git a/editor.planx.uk/src/pages/FlowEditor/lib/store/editor.ts b/editor.planx.uk/src/pages/FlowEditor/lib/store/editor.ts index e44a33e504..02db9a6b77 100644 --- a/editor.planx.uk/src/pages/FlowEditor/lib/store/editor.ts +++ b/editor.planx.uk/src/pages/FlowEditor/lib/store/editor.ts @@ -3,6 +3,7 @@ import { getPathForNode, sortFlow } from "@opensystemslab/planx-core"; import { ComponentType, FlowGraph, + IndexedNode, NodeId, OrderedFlow, } from "@opensystemslab/planx-core/types"; @@ -521,8 +522,14 @@ export const editorStore: StateCreator< const [node, parent, grandparent] = path; // Construct the internal portal path if applicable + const mapPortalsToURLPath = (portals: ReturnType) => + portals + .reverse() + .map(({ id }) => id) + .join(","); + const portalPath = internalPortals.length - ? "," + internalPortals.map(({ id }) => id).join(",") + ? "," + mapPortalsToURLPath(internalPortals) : ""; // Determine node path based on the node type