Skip to content

Commit

Permalink
wip: Pickup work from old branch
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed Sep 10, 2024
1 parent a8f9c7c commit ee223e2
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { capitalize, get } from "lodash";
import { SLUGS } from "pages/FlowEditor/data/types";
import { useStore } from "pages/FlowEditor/lib/store";
import React from "react";
import { useNavigation } from "react-navi";
import { FONT_WEIGHT_SEMI_BOLD } from "theme";

import { Headline } from "./Headline";
Expand Down Expand Up @@ -55,12 +56,12 @@ export const SearchResultCard: React.FC<{
const { Icon, componentType, title, key, headline } =
getDisplayDetailsForResult(result); // TODO - display portal wrapper

const getURLForNode = useStore((state) => state.getURLForNode);
const { navigate } = useNavigation();

Check failure on line 60 in editor.planx.uk/src/pages/FlowEditor/components/Sidebar/Search/SearchResultCard.tsx

View workflow job for this annotation

GitHub Actions / Run React Tests

Unhandled error

TypeError: Cannot destructure property 'navigate' of 'useNavigation(...)' as it is undefined. ❯ SearchResultCard src/pages/FlowEditor/components/Sidebar/Search/SearchResultCard.tsx:60:11 ❯ renderWithHooks node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:16305:18 ❯ mountIndeterminateComponent node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:20074:13 ❯ beginWork node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:21587:16 ❯ beginWork$1 node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:27426:14 ❯ performUnitOfWork node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:26560:12 ❯ workLoopSync node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:26466:5 ❯ renderRootSync node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:26434:7 ❯ recoverFromConcurrentError node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:25850:20 ❯ performConcurrentWorkOnRoot node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:25750:22 This error originated in "src/pages/FlowEditor/components/Sidebar/Search/index.test.tsx" test file. It doesn't mean the error was thrown inside the file itself, but while it was running. The latest test that might've caused the error is "entering a search term displays a series of cards". It might mean one of the following: - The error was thrown, while Vitest was running this test. - If the error occurred after the test had been completed, this was the last documented test before it was thrown.

Check failure on line 60 in editor.planx.uk/src/pages/FlowEditor/components/Sidebar/Search/SearchResultCard.tsx

View workflow job for this annotation

GitHub Actions / Run React Tests

Unhandled error

TypeError: Cannot destructure property 'navigate' of 'useNavigation(...)' as it is undefined. ❯ SearchResultCard src/pages/FlowEditor/components/Sidebar/Search/SearchResultCard.tsx:60:11 ❯ renderWithHooks node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:16305:18 ❯ mountIndeterminateComponent node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:20074:13 ❯ beginWork node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:21587:16 ❯ beginWork$1 node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:27426:14 ❯ performUnitOfWork node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:26560:12 ❯ workLoopSync node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:26466:5 ❯ renderRootSync node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:26434:7 ❯ recoverFromConcurrentError node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:25850:20 ❯ performConcurrentWorkOnRoot node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:25750:22 This error originated in "src/pages/FlowEditor/components/Sidebar/Search/index.test.tsx" test file. It doesn't mean the error was thrown inside the file itself, but while it was running. The latest test that might've caused the error is "setOrderedFlow is only called once on initial render". It might mean one of the following: - The error was thrown, while Vitest was running this test. - If the error occurred after the test had been completed, this was the last documented test before it was thrown.

Check failure on line 60 in editor.planx.uk/src/pages/FlowEditor/components/Sidebar/Search/SearchResultCard.tsx

View workflow job for this annotation

GitHub Actions / Run React Tests

src/pages/FlowEditor/components/Sidebar/Search/NodeSearchResults.test.tsx > Displays the count for a single result

TypeError: Cannot destructure property 'navigate' of 'useNavigation(...)' as it is undefined. ❯ SearchResultCard src/pages/FlowEditor/components/Sidebar/Search/SearchResultCard.tsx:60:11 ❯ renderWithHooks node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:16305:18 ❯ mountIndeterminateComponent node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:20074:13 ❯ beginWork node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:21587:16 ❯ beginWork$1 node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:27426:14 ❯ performUnitOfWork node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:26560:12 ❯ workLoopSync node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:26466:5 ❯ renderRootSync node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:26434:7 ❯ recoverFromConcurrentError node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:25850:20 ❯ performConcurrentWorkOnRoot node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:25750:22

Check failure on line 60 in editor.planx.uk/src/pages/FlowEditor/components/Sidebar/Search/SearchResultCard.tsx

View workflow job for this annotation

GitHub Actions / Run React Tests

src/pages/FlowEditor/components/Sidebar/Search/NodeSearchResults.test.tsx > Displays the count for multiple results

TypeError: Cannot destructure property 'navigate' of 'useNavigation(...)' as it is undefined. ❯ SearchResultCard src/pages/FlowEditor/components/Sidebar/Search/SearchResultCard.tsx:60:11 ❯ renderWithHooks node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:16305:18 ❯ mountIndeterminateComponent node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:20074:13 ❯ beginWork node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:21587:16 ❯ beginWork$1 node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:27426:14 ❯ performUnitOfWork node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:26560:12 ❯ workLoopSync node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:26466:5 ❯ renderRootSync node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:26434:7 ❯ recoverFromConcurrentError node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:25850:20 ❯ performConcurrentWorkOnRoot node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:25750:22

Check failure on line 60 in editor.planx.uk/src/pages/FlowEditor/components/Sidebar/Search/SearchResultCard.tsx

View workflow job for this annotation

GitHub Actions / Run React Tests

src/pages/FlowEditor/components/Sidebar/Search/NodeSearchResults.test.tsx > should not have any accessibility violations on initial load

TypeError: Cannot destructure property 'navigate' of 'useNavigation(...)' as it is undefined. ❯ SearchResultCard src/pages/FlowEditor/components/Sidebar/Search/SearchResultCard.tsx:60:11 ❯ renderWithHooks node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:16305:18 ❯ mountIndeterminateComponent node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:20074:13 ❯ beginWork node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:21587:16 ❯ beginWork$1 node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:27426:14 ❯ performUnitOfWork node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:26560:12 ❯ workLoopSync node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:26466:5 ❯ renderRootSync node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:26434:7 ❯ recoverFromConcurrentError node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:25850:20 ❯ performConcurrentWorkOnRoot node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:25750:22

const handleClick = () => {
console.log("todo!");
console.log({ nodeId: result.item.id });
// get path for node
// generate url from path
// navigate to url
const url = getURLForNode(result.item.id);
navigate(url);
};

return (
Expand Down
41 changes: 39 additions & 2 deletions editor.planx.uk/src/pages/FlowEditor/lib/store/editor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { gql } from "@apollo/client";
import { sortFlow } from "@opensystemslab/planx-core";
import { FlowGraph, OrderedFlow } from "@opensystemslab/planx-core/types";
import { getPathForNode, sortFlow } from "@opensystemslab/planx-core";
import {
ComponentType,
FlowGraph,
OrderedFlow,
} from "@opensystemslab/planx-core/types";
import {
add,
clone,
Expand Down Expand Up @@ -107,6 +111,7 @@ export interface EditorStore extends Store.Store {
name: string;
href: string;
}) => void;
getURLForNode: (nodeId: string) => string;
}

export const editorStore: StateCreator<
Expand Down Expand Up @@ -487,4 +492,36 @@ export const editorStore: StateCreator<
externalPortals[id] = { name, href };
set({ externalPortals });
},

getURLForNode: (nodeId) => {
const { orderedFlow: flow, flowSlug, teamSlug } = get();
if (!flow) throw Error("Missing ordered flow!");

const [node, parent, grandparent, ...rest] = getPathForNode({
nodeId,
flow,
});
console.log({ node, parent, grandparent, rest });
const internalPortals = rest.filter(
({ type }) => type === ComponentType.InternalPortal,
);
console.log({ internalPortals });

// based on node type, construct URL
// Answer nodes use parent and grandparent
let urlPath = `/${teamSlug}/${flowSlug}`;
if (internalPortals.length) {
const portalPath = internalPortals.map(({ id }) => id).join(",");
urlPath += `/${portalPath}`;
}

if (node.type === ComponentType.Answer) {
urlPath += `/nodes/${grandparent.id}/nodes/${parent.id}/edit`;
} else {
urlPath += `/nodes/${parent.id}/nodes/${node.id}/edit`;
}

console.log(urlPath);
return urlPath;
},
});

0 comments on commit ee223e2

Please sign in to comment.