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

Reinstate Breadcrumbs #2023

Merged
merged 4 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
7 changes: 6 additions & 1 deletion src/layout/MobileCalculatorPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ function MobileBottomMenu(props) {
function MobileTreeNavigationHolder(props) {
const { metadata, type, buttonHeight } = props;
// Try to find the current focus in the tree.
const [searchParams] = useSearchParams();
const [searchParams, setSearchParams] = useSearchParams();

const focus = searchParams.get("focus");

Expand Down Expand Up @@ -354,6 +354,11 @@ function MobileTreeNavigationHolder(props) {
margin: 0,
fontWeight: i === breadcrumbs.length - 1 ? "normal" : "lighter",
}}
onClick={() => {
let newSearch = new URLSearchParams(searchParams);
newSearch.set("focus", breadcrumb.name);
setSearchParams(newSearch);
}}
>
{breadcrumb.label}
{i < breadcrumbs.length - 1 && (
Expand Down
80 changes: 76 additions & 4 deletions src/pages/PolicyPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { Helmet } from "react-helmet";
import SearchParamNavButton from "../controls/SearchParamNavButton";
import style from "../style";
import DeprecationModal from "../modals/DeprecationModal";
import { impactKeys } from "../pages/policy/output/ImpactTypes.jsx";

export function ParameterSearch(props) {
const { metadata, callback } = props;
Expand Down Expand Up @@ -155,17 +156,88 @@ export default function PolicyPage(props) {
</FolderPage>
);
} else if (isOutput) {
middle = (
<>
// eslint-disable-next-line no-console
console.log("focus:" + focus);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remove this and the below console statements?

const POLICY_OUTPUT_TREE = getPolicyOutputTree(metadata.countryId);
const validFocusValues = impactKeys;
const stripped_focus = focus.replace("policyOutput.", "");
// eslint-disable-next-line no-console
console.log("stripped_focus:" + stripped_focus);
// eslint-disable-next-line no-console
console.log("valid values:" + validFocusValues);

// Check if the current focus is within validFocusValues
if (
focus === "policyOutput.policyBreakdown" ||
focus === "policyOutput.codeReproducibility" ||
validFocusValues.includes(stripped_focus)
) {
middle = (
<PolicyOutput
metadata={metadata}
policy={policy}
userProfile={userProfile}
/>
</>
);
);
} else {
// Find the node in the tree where the name matches the focus
const findNodeByName = (node, name) => {
if (node.name === name) {
return node;
}
if (node.children) {
for (let child of node.children) {
const result = findNodeByName(child, name);
if (result) {
return result;
}
}
}
return null;
};

const node = findNodeByName(POLICY_OUTPUT_TREE[0], focus);

// Render FolderPage with its children if the node is found
if (node) {
middle = (
<FolderPage label={node.label} metadata={metadata}>
{node.children}
</FolderPage>
);
} else {
// eslint-disable-next-line no-console
console.log("no node");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remove this console log, as well?

middle = <div>No matching node found.</div>;
}
}
}

// This code works
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit unclear as to what this commented code block is for

// else if (isOutput && focus === "policyOutput") {
// const POLICY_OUTPUT_TREE = getPolicyOutputTree(metadata.countryId);
// // eslint-disable-next-line no-console
// console.log('POLICY_OUTPUT_TREE:', POLICY_OUTPUT_TREE);

// middle = (
// <FolderPage label="Policy output results" metadata={metadata}>
// {POLICY_OUTPUT_TREE[0].children}
// </FolderPage>
// );
// }

// else if (isOutput && focus !== "policyOutput") {
// middle = (
// <>
// <PolicyOutput
// metadata={metadata}
// policy={policy}
// userProfile={userProfile}
// />
// </>
// );
// }

if (mobile) {
return (
<>
Expand Down
Loading