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

fix: Correctly construct URL by re-ordering portals #3773

Merged
merged 1 commit into from
Oct 9, 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
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
Loading