Skip to content

Commit

Permalink
fix: Correctly construct URL by re-ordering portals (#3773)
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr authored Oct 9, 2024
1 parent 313dbaf commit 7a5a4ba
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
);
});

Expand Down
9 changes: 8 additions & 1 deletion editor.planx.uk/src/pages/FlowEditor/lib/store/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { getPathForNode, sortFlow } from "@opensystemslab/planx-core";
import {
ComponentType,
FlowGraph,
IndexedNode,
NodeId,
OrderedFlow,
} from "@opensystemslab/planx-core/types";
Expand Down Expand Up @@ -521,8 +522,14 @@ export const editorStore: StateCreator<
const [node, parent, grandparent] = path;

// Construct the internal portal path if applicable
const mapPortalsToURLPath = (portals: ReturnType<typeof getPathForNode>) =>
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
Expand Down

0 comments on commit 7a5a4ba

Please sign in to comment.