Files
PiCloud/dashboard/src/lib/AppTabBar.svelte
MechaCat02 bce44769dd feat(dashboard): unified design system + persistent per-app tab bar
Addresses two interrelated UX complaints:

1. Browser-default controls leaking through the dark theme
   (native <select> chevrons, OS checkbox/radio look, date-picker
   icons, <details> triangle marker, number input spinners).
2. Subroute pages dropping the main app's tab bar in favor of a back
   link, breaking navigation continuity across users/files/queues/
   dead-letters/queues-[name].

Design tokens (dashboard/src/routes/+layout.svelte):

- Token vocabulary expanded with 18 new variables covering
  text-strong, accent + accent-fg, danger/success/warning bg/fg/border
  triplets, bg-elevated-hover, radii (sm/md/lg/pill), shadow-elev-2,
  and z scale (popover/modal/toast). 7 alias tokens (--muted,
  --link, --text, --color-error, --color-border, --chip-bg,
  --code-bg) absorb the orphan references the F-U-004 remediation
  partially renamed.
- Global :global(...) resets for <select>, <input type='checkbox'>,
  <input type='radio'>, <input type='number'>, <input type='date'>,
  and <details>/<summary> ensure native controls track the dark
  palette out of the box. No per-page edits needed.

Tab consistency:

- New dashboard/src/lib/AppTabBar.svelte renders all 11 per-app
  tabs (Scripts, Domains, Members, Triggers, Topics, Secrets,
  Settings, Users, Files, Queues, Dead letters) as <a> links with
  an active highlight derived from the URL. Tabs that switch
  in-page panels go to ?tab=<id>; tabs that switch routes go to
  the subroute. Admin-only tabs are hidden when canAdmin is false.
- New dashboard/src/routes/apps/[slug]/+layout.svelte loads the
  app once, handles the historical-slug redirect, exposes the
  shared app + canAdmin + canWrite + dead-letter-count state via
  Svelte context, and renders the breadcrumb + AppTabBar above
  every per-app page. The 5 subroute pages drop their own "← back"
  headers since the layout owns them now.
- apps/[slug]/+page.svelte's local-state activeTab becomes URL-
  driven via $page.url.searchParams.get('tab'). Defense-in-depth
  redirect for non-admin viewers landing on admin-only tabs uses
  goto({replaceState:true}) instead of mutating state.

Light-theme leftovers swept on 5 subroute pages:

- dead-letters: error banner, badge, pre/code blocks all swap to
  --color-danger-*, --bg-elevated, --text-primary
- files: button.danger, var(--muted,#666) → token-only
- queues + queues/[name]: bare hex fallbacks removed; .toolbar and
  .auto-refresh styled with tokens; data-testid for the queues
  empty state (already added by previous commit, reaffirmed here)
- users + users/invitations: badge-ok/badge-pending now use
  --color-success-bg/fg and --color-warning-bg/fg; chips use
  --bg-elevated + --text-strong; .create-form gets a token-styled
  surface; row-action buttons gain explicit dark-theme styling

E2E selector updates:

- members.spec.ts, integration.spec.ts, apps.spec.ts — the tab bar
  is now <a> elements (role=link) without a count suffix. Test
  selectors swap from getByRole('button', name: /^Scripts \(\d+\)$/)
  to getByRole('link', { name: 'Scripts' }), etc.
- New navigation/tabs.spec.ts still passes; existing 60+ tests
  unchanged except for the selector swap. Two pre-existing failures
  (routing.spec.ts:79, integration.spec.ts:89) untouched.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-06-09 20:55:22 +02:00

110 lines
3.3 KiB
Svelte

<script lang="ts">
import { base } from '$app/paths';
interface Props {
slug: string;
canAdmin: boolean;
/// One of: 'scripts' | 'domains' | 'members' | 'triggers' | 'topics' |
/// 'secrets' | 'settings' | 'users' | 'files' | 'queues' | 'dead-letters'
currentTab: string;
unresolvedDeadLetters?: number;
}
let { slug, canAdmin, currentTab, unresolvedDeadLetters = 0 }: Props = $props();
// Each tab is a link. In-page tabs (handled by the main app page's
// $page query-param logic) go to `?tab=<id>`; route tabs go to their
// own subpath. Layout puts this bar above every per-app page so
// navigation never disappears mid-flow.
interface Tab {
id: string;
label: string;
href: string;
adminOnly: boolean;
}
const tabs: Tab[] = $derived([
{ id: 'scripts', label: 'Scripts', href: `${base}/apps/${slug}?tab=scripts`, adminOnly: false },
{ id: 'domains', label: 'Domains', href: `${base}/apps/${slug}?tab=domains`, adminOnly: false },
{ id: 'members', label: 'Members', href: `${base}/apps/${slug}?tab=members`, adminOnly: true },
{ id: 'triggers', label: 'Triggers', href: `${base}/apps/${slug}?tab=triggers`, adminOnly: true },
{ id: 'topics', label: 'Topics', href: `${base}/apps/${slug}?tab=topics`, adminOnly: true },
{ id: 'secrets', label: 'Secrets', href: `${base}/apps/${slug}?tab=secrets`, adminOnly: true },
{ id: 'users', label: 'Users', href: `${base}/apps/${slug}/users`, adminOnly: true },
{ id: 'files', label: 'Files', href: `${base}/apps/${slug}/files`, adminOnly: true },
{ id: 'queues', label: 'Queues', href: `${base}/apps/${slug}/queues`, adminOnly: true },
{
id: 'dead-letters',
label: 'Dead letters',
href: `${base}/apps/${slug}/dead-letters`,
adminOnly: true
},
{ id: 'settings', label: 'Settings', href: `${base}/apps/${slug}?tab=settings`, adminOnly: true }
]);
</script>
<nav class="tabs" aria-label="App sections">
{#each tabs as tab (tab.id)}
{#if !tab.adminOnly || canAdmin}
<a
href={tab.href}
class:active={tab.id === currentTab}
aria-current={tab.id === currentTab ? 'page' : undefined}
>
{tab.label}
{#if tab.id === 'dead-letters' && unresolvedDeadLetters > 0}
<span class="dl-badge" aria-label="{unresolvedDeadLetters} unresolved">
{unresolvedDeadLetters}
</span>
{/if}
</a>
{/if}
{/each}
</nav>
<style>
.tabs {
display: flex;
flex-wrap: wrap;
gap: 0.25rem;
border-bottom: 1px solid var(--border);
margin: 0 0 1.5rem 0;
}
a {
display: inline-flex;
align-items: center;
gap: 0.4rem;
padding: 0.55rem 0.85rem;
border: none;
background: transparent;
color: var(--text-muted);
font-size: 0.875rem;
font-family: inherit;
text-decoration: none;
border-bottom: 2px solid transparent;
margin-bottom: -1px;
transition: color 120ms ease, border-color 120ms ease;
}
a:hover {
color: var(--text-primary);
}
a.active {
color: var(--color-link);
border-bottom-color: var(--color-link);
}
.dl-badge {
background: var(--color-danger-bg);
color: var(--color-danger-fg);
border-radius: var(--radius-pill);
padding: 0.05rem 0.4rem;
font-size: 0.7rem;
font-weight: 600;
line-height: 1.2;
}
a:focus-visible {
outline: 2px solid var(--color-link);
outline-offset: -2px;
border-radius: var(--radius-sm);
}
</style>