mirror of
https://github.com/supabase/supabase.git
synced 2026-12-06 00:19:08 +00:00
Part of DOCS-1737 ## Problem People who tried the Option 1 navigation reported labels that wrap onto two lines, such as "Architecture, limits and pricing". The old 35-character limit let that label through at 32 characters. They also reported labels that aren't in sentence case, such as "Framework Quickstarts" and "ORM Quickstarts". The docs style guide asks for sentence case. ## Solution - **28-character limit, enforced.** A new test in `option1.test.ts` fails on any Option 1 sidebar label over 28 characters. 97 labels were over the limit. They're shortened. - **Sentence case.** About 120 more labels are recased. Proper nouns and product feature names keep their capitals, such as Edge Functions, Row Level Security and Auth Hooks. "Self-Hosting" becomes "Self-hosting" in the top nav and the sidebar title. - **Parallel Start labels.** "Web app demos" becomes "Web app tutorials", to match "Mobile tutorials". - **Build becomes Products.** The tree test ran each candidate label against the shipped Option 1 tree, with 93 tasks and 3 runs each. Products raised direct success from 51% to 59%, and first clicks on the right section from 78% to 88%. - **Test fixtures.** `DocsSidebarNav.test.tsx` and the level-size allowlist reference labels by name, so they change too. ## Manual testing 1. Open [Getting started with Option 1 on the preview](https://docs-git-docs-nav-label-casing-supabase.vercel.app/docs/guides/getting-started?docs-ia-mvp-v1=option-1). The sidebar shows "Framework quickstarts" and "Web app tutorials". 2. Run `pnpm run -F docs test:local:unwatch features/IaNav components/Navigation`. Expect all tests to pass.
98 lines
3.3 KiB
TypeScript
98 lines
3.3 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
|
|
import type { GlobalMenuItems } from '../Navigation.types'
|
|
import * as currentNavItems from './NavigationMenu.constants'
|
|
import * as option1NavItems from '@/features/IaNav/option1.constants'
|
|
|
|
const MAX_ITEMS = 9
|
|
|
|
// key is the group's id when it has one, so copy edits don't break allowlist entries
|
|
type Level = { key: string; size: number }
|
|
type NavNode = { id?: string; name?: string; enabled?: boolean; items?: NavNode[] }
|
|
|
|
// count only what renders: disabled items and their subtrees are hidden
|
|
const isRendered = (item: { enabled?: boolean }) => item.enabled !== false
|
|
|
|
function sidebarLevels(path: string, allItems: NavNode[], id?: string): Level[] {
|
|
const items = allItems.filter((item) => isRendered(item))
|
|
|
|
return [
|
|
{ key: id ?? path, size: items.length },
|
|
...items.flatMap((item) =>
|
|
item.items?.length ? sidebarLevels(`${path} > ${item.name}`, item.items, item.id) : []
|
|
),
|
|
]
|
|
}
|
|
|
|
function topNavLevels(allSections: GlobalMenuItems): Level[] {
|
|
const menu = allSections.filter(([item]) => isRendered(item))
|
|
|
|
return [
|
|
{ key: 'Top nav', size: menu.length },
|
|
...menu.flatMap(([item]) =>
|
|
(item.menuItems ?? []).map((column, index) => ({
|
|
key: `Top nav > ${item.label} > column ${index + 1}`,
|
|
size: column.filter((columnItem) => isRendered(columnItem)).length,
|
|
}))
|
|
),
|
|
]
|
|
}
|
|
|
|
function oversizedLevels(navItems: Record<string, unknown>): string[] {
|
|
// A sidebar shared by several URL prefixes is exported under each name.
|
|
const sidebars = new Set(
|
|
Object.values(navItems).filter(
|
|
(value): value is { title: string; items: NavNode[] } =>
|
|
typeof value === 'object' &&
|
|
value !== null &&
|
|
'title' in value &&
|
|
Array.isArray((value as { items?: unknown }).items)
|
|
)
|
|
)
|
|
|
|
return [
|
|
...topNavLevels(navItems.GLOBAL_MENU_ITEMS as GlobalMenuItems),
|
|
...[...sidebars].flatMap((sidebar) => sidebarLevels(sidebar.title, sidebar.items)),
|
|
]
|
|
.filter((level) => level.size > MAX_ITEMS)
|
|
.map((level) => level.key)
|
|
}
|
|
|
|
// Levels allowed 10 or more items, such as a list of peers like quickstarts or providers.
|
|
const ALLOWLIST = [
|
|
'Auth',
|
|
'Auth > Flows (How-tos)',
|
|
'Auth > Flows (How-tos) > Social Sign-in (OAuth)',
|
|
'Database',
|
|
'Database > Extensions',
|
|
'Database > Foreign Data Wrappers > Sources',
|
|
'Database > Working with your database (intermediate)',
|
|
'Edge Functions',
|
|
'Edge Functions > Examples',
|
|
'Edge Functions > Third-Party Tools',
|
|
'Local Dev / CLI > Guides',
|
|
'Platform > Billing > Manage your usage',
|
|
'Platform > Platform Configuration',
|
|
'Self-Hosting',
|
|
'Self-Hosting > How-to Guides',
|
|
'Start with Supabase > Framework Quickstarts',
|
|
'Start with Supabase > Web app demos',
|
|
'Storage > File Buckets',
|
|
]
|
|
const OPTION_1_ALLOWLIST = [
|
|
'auth-social-sign-in',
|
|
'fdw-apps-and-apis',
|
|
'fdw-databases-and-warehouses',
|
|
'start-javascript-and-typescript',
|
|
'start-web-app-tutorials',
|
|
]
|
|
|
|
describe('navigation level size', () => {
|
|
it.each([
|
|
["today's navigation", currentNavItems, ALLOWLIST],
|
|
['Option 1', option1NavItems, OPTION_1_ALLOWLIST],
|
|
])('%s has no level with 10 or more items outside the allowlist', (_, navItems, allowlist) => {
|
|
expect(oversizedLevels(navItems).sort()).toEqual([...allowlist].sort())
|
|
})
|
|
})
|