Skip to content

feat(settings): leave a person's hidden sections off the left menu (menu access, part 2) - #1703

Merged
gkhngyk merged 9 commits into
ansvisor:mainfrom
cihan-gyk:feature/menu-access-sidebar
Oct 28, 2026
Merged

gkhngyk merged 9 commits into
ansvisor:mainfrom
cihan-gyk:feature/menu-access-sidebar

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Menu access, part 2: the left menu follows the data from part 1. Stacked on #1702; review that first.

  • (dashboard)/layout.tsx reads the menu columns in its own profiles select, and the role's row (readRoleHidden, skipped for admins) in the same Promise.all as the organization and brands; the pure menuOfProfile builds the menu and a new MenuAccessProvider hands it down. No extra round trip for admins, one parallel read for everyone else. If the role's row can't be read, it's logged and the whole menu shows.
  • Deploy order: the layout's profile read now selects the 00374 columns, so 00374 (feat(settings): store who sees which menu sections, by role, person and work area (menu access, part 1) #1702) must be on the database before this web build.
  • shouldShowDashboardNavItem takes the hidden sections. A section is the route segment under /dashboard, e.g. content or audit.
  • Sidebar: filters its items through it, and drops a group whose sections are all hidden, heading and all.
  • Mobile menu: the same filter. The active brand's Prompts link goes with the Prompts section.
  • With Prompts hidden, the sidebar doesn't read the tracked-prompt count.
  • Hide only: a hidden section's pages still open from a link, and roles and data access don't change. Admins see every section (only their own work areas, set in a later part, narrow it). Action Center is always on.

Related issue

None.

Type of change

  • feat — New feature

How to test

Needs migration 00374 from #1702 on your dev database. Demo user 11111111-1111-1111-1111-111111111111, demo org 22222222-2222-2222-2222-222222222222. Run the SQL as the database owner (psql or the SQL editor).

  1. cd web && yarn dev, then sign in as [email protected] / demo123 (admin). The menu is unchanged.
  2. update profiles set work_areas = '{brand}' where id = '11111111-1111-1111-1111-111111111111'; Reload. The sidebar shows Action Center, Chat, Brand Visibility, Mentions, Citations and Reports; Content, Audit, Prompts and AI Referral Traffic are gone. Open /dashboard/content by its address: the page still opens.
  3. At a phone width (under 768 px), open the menu. It shows the same items, with no brand Prompts link at the top.
  4. As a non-admin: update profiles set role = 'manager', work_areas = '{}' where id = '1111…'; then insert into organization_menu_roles (organization_id, role, hidden_sections) values ('2222…', 'manager', '{insights,prompts,mentions,citations,shopping,traffic}'); Reload. The whole Analytics group, heading included, is gone; Execution and Reports stay.
  5. Put it back: update profiles set role = 'admin', work_areas = '{}' where id = '1111…'; delete from organization_menu_roles where organization_id = '2222…';

Checklist

  • Branch follows the naming convention
  • Commits follow Conventional Commits
  • yarn lint passes (0 errors; 7 warnings in files this PR doesn't touch)
  • yarn typecheck passes
  • yarn format leaves no changes
  • Changes are focused — one concern per PR
  • yarn test and yarn build pass, run on part 6's tip, which includes this PR: 465 files, 4,561 tests; build OK (on part 6's tip 8c2e172).
  • Tests added (dashboard-navigation.test.ts, sidebar.test.tsx, mobile-nav.test.tsx, menu-access.test.ts)
  • npm run version:check (fails on main too: docker-compose images 0.2.0)

🤖 Generated with Claude Code

cihan-gyk and others added 8 commits October 28, 2026 14:02
… part 1)

Menu access, part 1 of 7: the data and the rule, with no UI yet.

- 00374 adds organization_menu_roles, the sections a role (not admin)
  doesn't see. Members of the organization read it and the server
  writes it.
- On profiles it adds menu_shown, menu_hidden and can_manage_menus,
  which only the server sets (00228's guard is extended), and
  work_areas and work_areas_asked_at, which the person sets.
- lib/menu-access.ts holds the rule: the role's sections, then the
  person's exceptions, narrowed to their work areas.
  - Action Center is always on.
  - Nobody takes a section off an admin's menu; only their own work
    areas narrow it.
  - A section is named by its route, so a new one shows by default.
- lib/actions/menu-access.ts covers getMyMenu, the Settings data, the
  role table, per-person exceptions and menu managers (admin only).
  It also writes the person's own work areas.

Hide only: pages still open from a link, roles and data access don't
change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…enu access, part 2)

The dashboard layout reads the viewer's menu once (getMyMenu, part 1) and
hands the sections it leaves out to a MenuAccessProvider. Both menus filter
by them through shouldShowDashboardNavItem:

- the sidebar drops a group whose sections are all off the menu, title and
  all;
- the mobile menu drops the active brand's Prompts link with the Prompts
  section.

If the menu can't be read, the whole menu shows. Hide only: an address
still opens its page.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A removed member keeps their profile and an invitation moves it to the
next organization, so a menu manager of one organization arrived in
another still able to change its menus, with their old exceptions. A
trigger now clears menu_shown, menu_hidden and can_manage_menus on a new
organization and can_manage_menus on a new role, unless the same update
sets them; it fires after the guard, so the guard still checks what the
person asked for.

Also reloads PostgREST's schema at the end of 00374, validates
setMenuManager's flag with Zod, and tests that the work-area check in
the database lists exactly the app's work areas.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…areas

"What do you work on?" is for new sign-ups and people joining from an
invite, once. Without this, every existing person would get the step at
their next sign-in. They can still pick work areas in Settings › Account.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… access, part 2 review)

The dashboard layout read the viewer's menu through getMyMenu, a second
user check and profile read after its own: two or three requests in a row
on every render. The menu columns now come with the profile the layout
already reads. The role's row (none for admins) is read alongside the
organization and the brands. menuOfProfile builds the menu from both,
and getMyMenu uses the same.

- A role row that can't be read is logged (console.error) and the menu
  shows whole, rather than the failure passing silently.
- The sidebar no longer reads the tracked prompts' count while Prompts is
  off the menu.
- Tests cover a group dropped with its title when all its sections are
  hidden, the whole menu without a menu to go by, the count not read, the
  mobile menu leaving hidden sections off (the brand's Prompts link with
  Prompts), and readRoleHidden.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good, with follow-ups. 00374 is now on the production database, so the order in 1 is met.

What I checked:

  • Own change. The diff from part 1's head (d44c81f) to c323a26: 49755f6 (feature), c323a26 (the layout reads the menu with its own profile read), and two merges of part 1. It touches no migration, so 00374 is the same as in part 1. On today's main, only part 1's supabase/schema.sql conflicts. None of this part's files changed on main since the stack's base apart from en.json, and that merges on its own.
  • Layout. The profile read now also selects the menu columns, and the role's row is read in the same Promise.all as the organization and brands. Someone without an organization, or who hasn't finished onboarding (a removed member, or someone signing up), is still sent to onboarding before any menu read, so the layout can't crash for them. readRoleHidden skips the read for admins. When the row can't be read, it logs and shows the whole menu instead of throwing. This also covers part 1's follow-up 3: the layout no longer calls getMyMenu, which throws without an organization.
  • Hide only. shouldShowDashboardNavItem drops an item by its section and changes nothing else, so pages still open from a link. The mobile menu's brand Prompts link goes with Prompts. The sidebar drops a group whose items are all hidden, and stops reading the tracked-prompt count while Prompts is hidden. Admins get no role row, and only their own work areas can narrow their menu (part 1's rule).
  • Refactor. canManageMenus, workAreasOf, menuOfProfile and MyMenu moved from the action file to lib/menu-access.ts and behave the same. getMyMenu gives the same result, built on the shared helpers.
  • Tests. I ran mobile-nav, sidebar, dashboard-navigation, menu-access and actions/menu-access on the PR's tree: 66 tests pass. menu-access.test.ts reads supabase/migrations, so I laid that folder out next to web. tsc shows no errors in the changed files. It does report 13 errors elsewhere, from packages missing in my test setup (@ai-sdk/*, the sanitize-html types); those are the same without this change.

Follow-ups:

  1. Deploy order. The layout's profile read now names work_areas, work_areas_asked_at, menu_shown, menu_hidden and can_manage_menus. Before 00374 adds those columns, the read fails and profile is null. The layout then sends every signed-in user to onboarding, and onboarding sends someone who has finished it back to /dashboard, so they loop. The web goes out on merge, so 00374 has to be applied first. The same would happen to a self-hosted install that pulls this change without running the migration. I'd also make the layout safe on its own: read the menu columns in a separate query, and fall back to the whole menu when that read fails, as readRoleHidden already does. Then a missing column only costs the menu filter, not the dashboard.
  2. Nothing tests the layout's wiring: that it passes menu.hidden to the provider and that the onboarding redirect still comes before the menu read. A small test of DashboardLayout with a mocked client would cover both, and also 1's fallback once it's in.

@gkhngyk
gkhngyk merged commit a62b2c5 into ansvisor:main Oct 28, 2026
4 of 5 checks passed
@github-actions github-actions Bot removed the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants