Skip to content
Merged
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
419 changes: 276 additions & 143 deletions frontend/src/components/OnboardingWizard.vue

Large diffs are not rendered by default.

23 changes: 22 additions & 1 deletion frontend/src/stores/onboarding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import api from '@/services/api'
* onboarding.openWizard()
* }
*/
/** Tabs the wizard renders, in order. */
export type WizardTab = 'clients' | 'servers' | 'verify'

export const useOnboardingStore = defineStore('onboarding', () => {
// State fetched from backend
const state = ref<OnboardingStateResponse | null>(null)
Expand All @@ -29,6 +32,14 @@ export const useOnboardingStore = defineStore('onboarding', () => {
// are satisfied.
const wizardOpen = ref(false)

// Which tab the wizard should land on when it next opens. Callers that mean
// a *specific* step ("Import from your AI client configs" on the Servers
// page) set it; everything else leaves it null and gets the default first
// tab. It is a one-shot request: the wizard consumes it on open and clears
// it, so a later plain `openWizard()` is never silently redirected to a tab
// some earlier caller asked for.
const wizardInitialTab = ref<WizardTab | null>(null)

// Computed
const shouldShowWizard = computed(() => state.value?.should_show_wizard ?? false)
const hasConnectedClient = computed(() => state.value?.has_connected_client ?? false)
Expand Down Expand Up @@ -146,12 +157,20 @@ export const useOnboardingStore = defineStore('onboarding', () => {
await mark({ engaged: true })
}

function openWizard(): void {
function openWizard(tab: WizardTab | null = null): void {
wizardInitialTab.value = tab
wizardOpen.value = true
// Best-effort first-shown stamp.
void markShown()
}

/** Read and clear the one-shot initial-tab request. */
function consumeWizardInitialTab(): WizardTab | null {
const tab = wizardInitialTab.value
wizardInitialTab.value = null
return tab
}

function closeWizard(): void {
wizardOpen.value = false
}
Expand All @@ -161,6 +180,7 @@ export const useOnboardingStore = defineStore('onboarding', () => {
loading,
error,
wizardOpen,
wizardInitialTab,
shouldShowWizard,
hasConnectedClient,
hasConfiguredServer,
Expand All @@ -179,6 +199,7 @@ export const useOnboardingStore = defineStore('onboarding', () => {
markServerSkipped,
markEngaged,
openWizard,
consumeWizardInitialTab,
closeWizard,
}
})
32 changes: 28 additions & 4 deletions frontend/src/stores/servers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,27 @@ export const useServersStore = defineStore('servers', () => {
let issueSeq = 0
let appliedSeq = 0

function applyServerList(list: Server[], ticket: number) {
if (ticket < appliedSeq) return
// A request settles when it produces an outcome — a list OR a failure. Both
// advance the mark, because both are news about the same list: if only
// successes advanced it, a newer request failing would leave the mark behind
// and an older list arriving afterwards would still be accepted, overwriting
// the newer outcome with stale data.
function claimTicket(ticket: number): boolean {
if (ticket < appliedSeq) return false
appliedSeq = ticket
return true
}

function applyServerList(list: Server[], ticket: number) {
if (!claimTicket(ticket)) return
// Smart merge preserves object references and avoids unnecessary re-renders
servers.value = mergeServers(servers.value, list)
loaded.value = true
// A list that arrived is proof the previous failure is over. Without this
// an error is write-only: silent background refreshes set it and nothing
// ever clears it, so one transient blip pins an error banner on the
// Servers page for the rest of the session.
loading.value.error = null
}

// Actions
Expand All @@ -120,15 +135,24 @@ export const useServersStore = defineStore('servers', () => {
}
const ticket = ++issueSeq

// Failures are sequenced exactly like successes: an older request failing
// after a newer one already delivered a list must not raise a stale error
// over fresh data — the mirror image of the stale-list problem the
// sequencing exists to prevent.
const recordError = (message: string) => {
if (!claimTicket(ticket)) return
loading.value.error = message
}

try {
const response = await api.getServers()
if (response.success && response.data) {
applyServerList(response.data.servers, ticket)
} else {
loading.value.error = response.error || 'Failed to fetch servers'
recordError(response.error || 'Failed to fetch servers')
}
} catch (error) {
loading.value.error = error instanceof Error ? error.message : 'Unknown error'
recordError(error instanceof Error ? error.message : 'Unknown error')
} finally {
if (!silent) {
loading.value.loading = false
Expand Down
178 changes: 92 additions & 86 deletions frontend/src/views/Dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,92 +6,12 @@
<!-- Upgrade nudge (Spec 079): dismissible per-version update banner -->
<UpdateBanner />

<!-- Usage ↔ Overview switcher (Spec 069 T016). Usage is the default panel
(analytics-as-landing-page); each tab maps to a deep-linkable route
(/usage, /overview) so the panel survives a reload or a shared link. -->
<div role="tablist" class="tabs tabs-boxed w-fit" data-test="dashboard-view-switcher">
<a
role="tab"
class="tab"
:class="activeView === 'usage' ? 'tab-active' : ''"
data-test="dashboard-tab-usage"
@click="selectUsage"
>Usage</a>
<a
role="tab"
class="tab"
:class="activeView === 'overview' ? 'tab-active' : ''"
data-test="dashboard-tab-overview"
@click="selectOverview"
>Overview</a>
</div>

<!-- Usage view: the panel wrapper is always in the DOM (kept hidden with
v-show so switching back is instant and the Overview subtree is never
torn down, SC-006). The heavy chart bundle + the usage fetch inside
UsageView are mounted only once the panel has been active
(usageEverActive) AND the server list has arrived, and stay code-split
behind Suspense, so the Dashboard shell still paints immediately
(SC-004). -->
<div v-show="activeView === 'usage'" data-test="dashboard-usage-panel">
<!-- First run: no upstream servers configured, so the analytics panel
would only ever show "no data". Point the new user at the one action
that makes the dashboard useful instead. -->
<div
v-if="showFirstRunCta"
class="card bg-base-200 border border-base-300"
data-test="dashboard-usage-first-run"
>
<div class="card-body items-center text-center py-12">
<svg class="w-12 h-12 opacity-40" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z" />
</svg>
<h3 class="font-semibold text-lg mt-2">Add your first server to see usage</h3>
<p class="text-sm opacity-60 max-w-md">
No upstream MCP servers are configured yet, so there is nothing to chart.
Add one and this page will show call volume, token sinks, error rates and a timeline.
</p>
<div class="flex flex-wrap gap-2 justify-center mt-2">
<button
class="btn btn-primary btn-sm"
data-test="dashboard-first-run-add-server"
@click="showAddServer = true"
>
Add your first server
</button>
<router-link to="/repositories" class="btn btn-sm btn-ghost">Browse Registry</router-link>
<button
class="btn btn-sm btn-ghost"
data-test="dashboard-first-run-overview"
@click="selectOverview"
>
Go to Overview
</button>
</div>
</div>
</div>
<!-- Hold the charts back until the server list has arrived: mounting
UsageView first would fire a usage aggregate request and flash the
"no usage data yet" card on a fresh install, only to be replaced by
the CTA above a moment later. Both requests are issued together in
onMounted, so this costs no extra round-trip. -->
<div
v-else-if="!serversFetchSettled && !serversStore.loaded"
class="flex justify-center py-16"
data-test="dashboard-usage-pending"
>
<span class="loading loading-spinner loading-lg"></span>
</div>
<Suspense v-else-if="usageEverActive">
<UsageView />
<template #fallback>
<div class="flex justify-center py-16"><span class="loading loading-spinner loading-lg"></span></div>
</template>
</Suspense>
</div>

<!-- Overview: v-show (not v-if) so its state survives a switch to Usage and back (SC-006). -->
<div v-show="activeView === 'overview'" class="space-y-6" data-test="dashboard-overview-panel">
<!-- "What needs me": servers in a bad state and tools awaiting approval.
These live above the panel switcher rather than inside a panel — they
are the one thing on this page the user is expected to act on, and
burying them under a tab means the landing page can look calm while a
server is down or an unreviewed tool is waiting. Each renders only
when it has something to say, so a healthy install sees neither. -->
<!-- Servers Needing Attention Banner (using unified health status) -->
<div
v-if="serversNeedingAttention.length > 0"
Expand Down Expand Up @@ -179,6 +99,92 @@
</router-link>
</div>

<!-- Usage ↔ Overview switcher (Spec 069 T016). Usage is the default panel
(analytics-as-landing-page); each tab maps to a deep-linkable route
(/usage, /overview) so the panel survives a reload or a shared link. -->
<div role="tablist" class="tabs tabs-boxed w-fit" data-test="dashboard-view-switcher">
<a
role="tab"
class="tab"
:class="activeView === 'usage' ? 'tab-active' : ''"
data-test="dashboard-tab-usage"
@click="selectUsage"
>Usage</a>
<a
role="tab"
class="tab"
:class="activeView === 'overview' ? 'tab-active' : ''"
data-test="dashboard-tab-overview"
@click="selectOverview"
>Overview</a>
</div>

<!-- Usage view: the panel wrapper is always in the DOM (kept hidden with
v-show so switching back is instant and the Overview subtree is never
torn down, SC-006). The heavy chart bundle + the usage fetch inside
UsageView are mounted only once the panel has been active
(usageEverActive) AND the server list has arrived, and stay code-split
behind Suspense, so the Dashboard shell still paints immediately
(SC-004). -->
<div v-show="activeView === 'usage'" data-test="dashboard-usage-panel">
<!-- First run: no upstream servers configured, so the analytics panel
would only ever show "no data". Point the new user at the one action
that makes the dashboard useful instead. -->
<div
v-if="showFirstRunCta"
class="card bg-base-200 border border-base-300"
data-test="dashboard-usage-first-run"
>
<div class="card-body items-center text-center py-12">
<svg class="w-12 h-12 opacity-40" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z" />
</svg>
<h3 class="font-semibold text-lg mt-2">Add your first server to see usage</h3>
<p class="text-sm opacity-60 max-w-md">
No upstream MCP servers are configured yet, so there is nothing to chart.
Add one and this page will show call volume, token sinks, error rates and a timeline.
</p>
<div class="flex flex-wrap gap-2 justify-center mt-2">
<button
class="btn btn-primary btn-sm"
data-test="dashboard-first-run-add-server"
@click="showAddServer = true"
>
Add your first server
</button>
<router-link to="/repositories" class="btn btn-sm btn-ghost">Browse Registry</router-link>
<button
class="btn btn-sm btn-ghost"
data-test="dashboard-first-run-overview"
@click="selectOverview"
>
Go to Overview
</button>
</div>
</div>
</div>
<!-- Hold the charts back until the server list has arrived: mounting
UsageView first would fire a usage aggregate request and flash the
"no usage data yet" card on a fresh install, only to be replaced by
the CTA above a moment later. Both requests are issued together in
onMounted, so this costs no extra round-trip. -->
<div
v-else-if="!serversFetchSettled && !serversStore.loaded"
class="flex justify-center py-16"
data-test="dashboard-usage-pending"
>
<span class="loading loading-spinner loading-lg"></span>
</div>
<Suspense v-else-if="usageEverActive">
<UsageView />
<template #fallback>
<div class="flex justify-center py-16"><span class="loading loading-spinner loading-lg"></span></div>
</template>
</Suspense>
</div>

<!-- Overview: v-show (not v-if) so its state survives a switch to Usage and back (SC-006). -->
<div v-show="activeView === 'overview'" class="space-y-6" data-test="dashboard-overview-panel">
<!-- Hub Visualization -->
<div class="grid grid-cols-1 lg:grid-cols-[280px_1fr_280px] gap-0 min-h-[520px] relative">

Expand Down
Loading
Loading