Skip to content
Open
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
14 changes: 1 addition & 13 deletions sidebars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,15 +450,9 @@ const baseSidebars: SidebarsConfig = {
},
{
type: 'category' as const,
// Original label when `platform-api` is off/unset; renamed to
// 'API Overview' when the flag is enabled (since the guides become
// shared across Client + Platform APIs).
label: 'Client API',
label: 'API Overview',
collapsible: false,
collapsed: false,
customProps: {
flagLabel: { flag: 'platform-api', label: 'API Overview' },
},
items: [
{
type: 'category',
Expand Down Expand Up @@ -514,12 +508,6 @@ const baseSidebars: SidebarsConfig = {
label: 'Platform API Reference',
collapsible: false,
collapsed: false,
// Gated behind the `platform-api` feature flag: when the flag is false or
// unset the section is omitted (original sidebar); when enabled (Edge
// Config or `?ff_platform-api=true`) it renders.
customProps: {
flag: 'platform-api',
},
items: [
{
type: 'category',
Expand Down
19 changes: 3 additions & 16 deletions src/theme/DocSidebarItem/Category/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,26 +157,13 @@ export default function DocSidebarItemCategory({
}
}, [collapsible, expandedItem, index, setCollapsed, autoCollapseCategories]);

// Feature-flag gating: hide a category (and its children) when it declares a
// `customProps.flag` that isn't enabled. Evaluated at the end so all hooks
// above always run in a stable order (see rules of hooks). Enable via Edge
// Config or the runtime query param, e.g. `?ff_platform-api=true`.
// Feature-flag gating is evaluated after all hooks to preserve hook order.
const { isEnabled } = React.useContext(FeatureFlagsContext);
const flag = (item as any).customProps?.flag as string | undefined;
if (flag && !isEnabled(flag)) {
return null;
}

// Feature-flag-aware label: when a category declares `customProps.flagLabel`
// ({ flag, label }) and that flag is enabled, render the alternate label
// instead of the default. Lets the same static config show the original
// label when the flag is off and a new label when it's on.
const flagLabel = (item as any).customProps?.flagLabel as
| { flag: string; label: string }
| undefined;
const label =
flagLabel && isEnabled(flagLabel.flag) ? flagLabel.label : item.label;

return (
<li
className={clsx(
Expand Down Expand Up @@ -237,12 +224,12 @@ export default function DocSidebarItemCategory({
className="sidebar-category-icon"
/>
)}
{label}
{item.label}
</Link>
{href && collapsible && (
<CollapseButton
collapsed={collapsed}
categoryLabel={label}
categoryLabel={item.label}
onClick={(e) => {
e.preventDefault();
updateCollapsed();
Expand Down
3 changes: 1 addition & 2 deletions src/theme/DocSidebarItem/Link/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ export default function DocSidebarItemLink({
const isActive = isActiveSidebarItem(item, activePath);
const isExperimental = isExperimentalItem((item as any).docId);
const isInternalLink = isInternalUrl(href);
// Feature-flag gating: hide a link when it declares a `customProps.flag`
// that isn't enabled (e.g. reveal via `?ff_platform-api=true`).
// Hide links whose declared feature flag is disabled.
const { isEnabled } = React.useContext(FeatureFlagsContext);
const flag = (item as any).customProps?.flag as string | undefined;
if (flag && !isEnabled(flag)) {
Expand Down
Loading