Skip to content

Commit 80f1472

Browse files
ntottenclaude
andcommitted
Fix guides page sidebar sticky position and strip underscore properties
- Fix sidebar getting cut off by header when scrolling by using CSS variable --header-height instead of fixed top-4 value - Add preventScrollReset to setSearchParams to prevent scroll jumping - Add stripUnderscoreProperties helper to recursively remove underscore prefixed properties from policy examples Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 2a86008 commit 80f1472

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

scripts/generate-policies.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,27 @@ function invariant(condition: unknown, message: string): asserts condition {
7777
throw new Error(message);
7878
}
7979

80+
/**
81+
* Recursively removes all properties that start with an underscore from an object
82+
*/
83+
function stripUnderscoreProperties<T>(obj: T): T {
84+
if (obj === null || typeof obj !== "object") {
85+
return obj;
86+
}
87+
88+
if (Array.isArray(obj)) {
89+
return obj.map((item) => stripUnderscoreProperties(item)) as T;
90+
}
91+
92+
const result: Record<string, unknown> = {};
93+
for (const [key, value] of Object.entries(obj)) {
94+
if (!key.startsWith("_")) {
95+
result[key] = stripUnderscoreProperties(value);
96+
}
97+
}
98+
return result as T;
99+
}
100+
80101
type PolicyProduct = "ai-gateway" | "api-gateway" | "mcp-gateway";
81102
type PolicySchema = JSONSchema7 & {
82103
isBeta?: boolean;
@@ -253,9 +274,7 @@ for (const schemaPath of policySchemas) {
253274
module: `$import(./modules/${policyId})`,
254275
};
255276
} else if (examples && examples.length > 0) {
256-
const example = { ...examples[0] };
257-
delete (example as any)._name;
258-
meta.defaultHandler = example;
277+
meta.defaultHandler = stripUnderscoreProperties(examples[0]);
259278
} else {
260279
meta.defaultHandler = {
261280
export: (handler.properties.export as JSONSchema7).const,
@@ -282,7 +301,7 @@ for (const schemaPath of policySchemas) {
282301
code = {
283302
name: `my-${policyId}-policy`,
284303
policyType: policyId,
285-
handler: examples[0],
304+
handler: stripUnderscoreProperties(examples[0]),
286305
};
287306
} else if (schema.isCustom) {
288307
code = {

src/pages/GuidesPage.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ export const GuidesPage = () => {
2323
if (newCategories.length > 0) {
2424
setSearchParams(
2525
{ categories: newCategories.join(",") },
26-
{ replace: true },
26+
{ replace: true, preventScrollReset: true },
2727
);
2828
} else {
29-
setSearchParams({}, { replace: true });
29+
setSearchParams({}, { replace: true, preventScrollReset: true });
3030
}
3131
};
3232

@@ -72,7 +72,7 @@ export const GuidesPage = () => {
7272
<div className="grid grid-cols-1 lg:grid-cols-4 gap-8 my-5">
7373
{/* Sidebar */}
7474
<aside className="lg:col-span-1">
75-
<div className="sticky top-4">
75+
<div className="sticky top-[calc(var(--header-height)+1rem)]">
7676
<h2 className="text-xl font-semibold mb-4">Filter Guides</h2>
7777
<div className="space-y-3">
7878
{categories.map((category) => (

0 commit comments

Comments
 (0)