Skip to content

Commit

Permalink
Merge pull request #2343 from anth-volk/fix/2342-no-order
Browse files Browse the repository at this point in the history
Sort parameters
  • Loading branch information
MaxGhenis authored Feb 6, 2025
2 parents 46e81d2 + 7545a3c commit 057753a
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/pages/PolicyPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,42 @@ function PolicyLeftSidebar(props) {
const [searchParams, setSearchParams] = useSearchParams();
const POLICY_OUTPUT_TREE = getPolicyOutputTree(metadata.countryId);
const selected = searchParams.get("focus") || "";

function recursiveAlphaSort(tree) {
if (!tree) {
return [];
}

let sorted = tree.sort((a, b) => {
// JS sorts by ASCII value - Z comes before a
if (a.label.toLowerCase() < b.label.toLowerCase()) {
return -1;
}
if (a.label.toLowerCase() > b.label.toLowerCase()) {
return 1;
}
return 0;
});

for (let i = 0; i < sorted.length; i++) {
sorted[i].children = recursiveAlphaSort(sorted[i].children);
}

return sorted;
}

const firstTree = recursiveAlphaSort(metadata.parameterTree.children);

const onSelect = (name) => {
let newSearch = copySearchParams(searchParams);
newSearch.set("focus", name);
setSearchParams(newSearch);
};

const isOnOutput =
window.location.search.includes("focus=policyOutput") ||
window.location.search.includes("focus=householdOutput");

// The menu, then the search bar anchored to the bottom
return (
<div style={{ backgroundColor: style.colors.LIGHT_GRAY }}>
Expand All @@ -73,7 +101,8 @@ function PolicyLeftSidebar(props) {
</div>
)}
<StackedMenu
firstTree={metadata.parameterTree.children}
// firstTree={metadata.parameterTree.children}
firstTree={firstTree}
selected={selected}
onSelect={onSelect}
secondTree={POLICY_OUTPUT_TREE[0].children}
Expand Down

0 comments on commit 057753a

Please sign in to comment.