Skip to content

feat(settings): complete tab refactor — extract remaining 4 tabs + URL rewrite on fallback #717

Open

Description

@pavshulin

Summary

Follow-up to #302 (PR #700). Two related items in views/Settings.vue worth bundling into one refactor:

  1. Complete the tab-as-component extraction — only McpKeysTab.vue was extracted in Refactor Settings page with tabbed layout and absorb API Keys #302; the other 4 tabs (General, Access, Integrations, Agents) remain inline v-if sections in Settings.vue. The file is currently ~3,000 lines.
  2. Rewrite URL on tab-fallback — when a non-admin user navigates to /settings?tab=integrations, the URL stays as typed but the active tab silently resolves to mcp-keys. URL ↔ content mismatch is confusing.

Both surface in the same file and have similar shape (Settings.vue refactor), which is why they're bundled.

Background — what shipped in #302

PR #700 delivered:

  • ✅ Tabbed nav with ?tab= URL param, role-gated
  • ✅ MCP Keys absorbed from /api-keys (extracted to components/settings/McpKeysTab.vue)
  • ✅ NavBar Keys link removed; /api-keys redirects to /settings?tab=mcp-keys
  • ✅ Backend security boundary unchanged (require_admin enforced server-side)
  • ⚠️ Partially met: "Each tab a separate Vue component (no 2,600-line monolith)" — only 1 of 5 tabs extracted

The other 4 tabs remain as <div v-if="activeTab === 'general'" class="...">...</div> inline blocks in Settings.vue.

Item 1 — Extract remaining 4 tabs

Target structure

src/frontend/src/components/settings/
├── McpKeysTab.vue        # ✅ already exists
├── GeneralTab.vue        # NEW — Platform, Trinity Prompt, Default Avatars
├── AccessTab.vue         # NEW — Email Whitelist, User Management, SSH Access
├── IntegrationsTab.vue   # NEW — API Keys (Anthropic+GitHub), Slack, Subscriptions
└── AgentsTab.vue         # NEW — Agent Quotas, Skills Library, GitHub Templates

After extraction, Settings.vue becomes a thin shell (~300 lines):

<template>
  <div class="...">
    <NavBar />
    <main>
      <h1>Settings</h1>
      <!-- Tab strip — unchanged -->
      <div role="tablist">...</div>
      <!-- Tab content — one component each -->
      <GeneralTab      v-if="activeTab === 'general'" />
      <AccessTab       v-if="activeTab === 'access'" />
      <IntegrationsTab v-if="activeTab === 'integrations'" />
      <McpKeysTab      v-if="activeTab === 'mcp-keys'" />
      <AgentsTab       v-if="activeTab === 'agents'" />
    </main>
  </div>
</template>

Each tab component is self-contained: own state (refs, reactives), own loaders (axios calls), own methods (save, delete, etc.), own modals.

Why this is a real refactor (not a five-minute change)

Each tab pulls in chunks of state and methods that are currently global to Settings.vue:

  • GeneralTab: trinityPrompt, originalPrompt, publicUrl, defaultAvatars, loadPublicUrl, loadDefaultAvatars, saveTrinityPrompt, generateDefaultAvatars, etc.
  • AccessTab: emailWhitelist, users, sshAccess, loadEmailWhitelist, loadUsers, addEmail, removeEmail, updateUserRole, etc.
  • IntegrationsTab: anthropicKey, githubPat, slackSettings, slackTransportStatus, subscriptions, loadApiKeyStatus, loadSlackSettings, saveAnthropic, saveGithubPat, connectSlack, etc.
  • AgentsTab: agentQuotas, skillsLibraryUrl, githubTemplates, loadAgentQuotas, loadSkillsLibrarySettings, loadGithubTemplates, etc.

The Settings.vue loadAdminOnlySettings() function currently fires all these loaders on watch(isAdmin, ..., immediate: true). After extraction, each tab's onMounted triggers its own loaders — which is actually cleaner because non-admin users never mount admin tabs at all (no wasted API calls).

Acceptance — Item 1

  • Settings.vue is < 400 lines (down from ~3,000)
  • 4 new components: GeneralTab.vue, AccessTab.vue, IntegrationsTab.vue, AgentsTab.vue
  • Each component owns its state, loaders, methods, and modals
  • All 13 sections functional (regression-safe — covered by existing F1 test in e2e/settings-tabs.spec.js)
  • All save buttons still work (Anthropic key save, GitHub PAT save, Trinity Prompt save, Email Whitelist add/remove, User role change, Agent Quotas save, Skills Library URL, GitHub Templates add/remove, etc.)
  • No regression in role-based gating (admin sees 5 tabs, non-admin sees 1)
  • No regression in URL deep-linking, browser back/forward, ConfirmDialog flows
  • Existing 23 e2e tests still pass

Item 2 — Rewrite URL on tab-fallback

Current behavior

Settings.vue has:

const activeTab = ref(resolveTabFromQuery(route.query.tab))

watch(() => route.query.tab, (newTab) => {
  activeTab.value = resolveTabFromQuery(newTab)  // resolves to default if invalid
})
  • Non-admin pastes /settings?tab=integrations → URL stays ?tab=integrations, content shows MCP Keys (the resolved fallback)
  • Anyone pastes /settings?tab=foobar → URL stays ?tab=foobar, content shows default tab

URL ↔ content mismatch.

Proposed fix

watch(() => route.query.tab, (newTab) => {
  const resolved = resolveTabFromQuery(newTab)
  activeTab.value = resolved
  // Rewrite URL to match resolved tab when input was invalid/inaccessible
  if (newTab !== undefined && newTab !== resolved) {
    router.replace({ query: { ...route.query, tab: resolved } })
  }
}, { immediate: true })  // also fires for the initial-mount case

Tradeoff acknowledged

Pro — URL always matches displayed content. Non-confusing. Bookmarks work.

Con — sharing /settings?tab=integrations from non-admin to admin no longer works (URL gets rewritten on the non-admin's side before they share). This is theoretical; "share my settings URL" is rarely a real use case.

Acceptance — Item 2

  • Non-admin pasting /settings?tab=integrations → URL becomes /settings?tab=mcp-keys, MCP Keys content shows
  • Anyone pasting /settings?tab=foobar → URL becomes /settings?tab=<default>, default content shows
  • Admin pasting /settings?tab=integrations → URL stays /settings?tab=integrations (valid), Integrations content shows
  • Existing behavior 3 test (?tab=foobar falls back) updated to also assert URL rewrite
  • New test pinning non-admin URL rewrite

Test changes required

Update src/frontend/e2e/settings-tabs.spec.js:

  1. Update behavior 3 (unknown ?tab=foobar falls back to default) — add await expect(page).toHaveURL(/\/settings\?.*tab=general/) after the existing assertion
  2. Add new test — non-admin URL rewrite to mcp-keys
  3. Update F1 (every section appears under expected tab) — sections may have moved; update selectors if needed
  4. Verify all 23 existing tests still pass after the component extraction

Out of scope (file as separate issues if desired)

  • Save-button regression tests (F7-F9 — Trinity Prompt save, Whitelist add/remove, MCP Server URL save). Discussed but deferred — could be added either before or after this refactor.
  • v-show vs v-if for modal-state preservation across tab switches (informational item I3 in Refactor Settings page with tabbed layout and absorb API Keys #302 review)
  • Vitest unit-test infra (frontend has only Playwright e2e)

References

Suggested labels & priority

  • enhancement, frontend, priority-p2
  • Tier: P1b or P1c (refactor without user-visible bug; nice-to-have)

Activity

  1. added
    enhancement
    priority-p2
    frontend
    on May 7, 2026
  2. added
    theme-ui-ux
    type-refactor
    on Jun 3, 2026
  3. added
    complexity-medium
    status-incubating
    on Jun 12, 2026
  4. removed
    enhancement
    frontend
    on Aug 4, 2026
  5. added
    status-ready
    and removed
    status-incubating
    on Sep 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    complexity-mediumpriority-p2status-readytheme-ui-uxtype-refactor

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions