(
'windmill_sidebar_list',
'workspace',
'string'
)
-/** The list the sidebar shows beside `pathname`, where it offers sessions. */
-export function sidebarListFor(pathname: string): SidebarList {
- if (pathname.startsWith('/sessions')) return 'sessions'
- return pathname === '/' ? homeSidebarList.val : 'workspace'
-}
-
/** Turning AI Sessions back on asks to see them: Home, with the session list beside it. */
export function activateAiSessions(): void {
- homeSidebarList.val = 'sessions'
+ chosenSidebarList.val = 'sessions'
clearSessionsBetaOptOut('/')
}
diff --git a/frontend/src/lib/components/sidebar/MenuButton.svelte b/frontend/src/lib/components/sidebar/MenuButton.svelte
index e6f23361bf..f92ef9a7c1 100644
--- a/frontend/src/lib/components/sidebar/MenuButton.svelte
+++ b/frontend/src/lib/components/sidebar/MenuButton.svelte
@@ -43,6 +43,8 @@
buttonClass?: string | undefined
// Show a trailing chevron to signal the button opens a dropdown.
showChevron?: boolean
+ // An icon at the row's end, hidden with the label when collapsed.
+ trailingIcon?: any | undefined
// Render the label with stronger weight/size (e.g. the workspace name).
emphasizeLabel?: boolean
// Drop the native `title` attributes — for callers that wrap the button
@@ -78,6 +80,7 @@
class: classNames = undefined,
buttonClass = undefined,
showChevron = false,
+ trailingIcon = undefined,
emphasizeLabel = false,
disableTitle = false,
ariaLabel = undefined,
@@ -213,6 +216,14 @@
/>
{/if}
+ {#if trailingIcon && !isCollapsed}
+ {@const TrailingIcon = trailingIcon}
+
+ {/if}
+
{#if isCollapsed && notificationsCount > 0}
diff --git a/frontend/src/lib/components/sidebar/workspaceSwitchUrl.ts b/frontend/src/lib/components/sidebar/workspaceSwitchUrl.ts
index 7a9a0d6fe4..23d9a667b7 100644
--- a/frontend/src/lib/components/sidebar/workspaceSwitchUrl.ts
+++ b/frontend/src/lib/components/sidebar/workspaceSwitchUrl.ts
@@ -1,13 +1,11 @@
import { page } from '$app/state'
import { goto } from '$lib/navigation'
-// Post-workspace-switch URL fixup shared by the sidebar workspace pickers, and by the
-// Workspace side of the sidebar switch for a page it left before a switch.
+// Post-workspace-switch URL fixup shared by the sidebar workspace pickers.
// Item-scoped pages would show a wrong-workspace (or missing) item after a
// switch — go home instead. Otherwise, really rewrite the params in the address
// bar that name a workspace (mutating page.url is a no-op there): left stale,
-// they get re-applied on reload or when the switch restores the page, silently
-// switching the workspace back.
+// they get re-applied on reload, silently switching the workspace back.
//
// `workspace_id` names the workspace a page acts on (the compare page's pair) and
// `workspace` the one the app is pointed at; a switch moves both. `target`, the
@@ -27,13 +25,21 @@ const EDIT_PAGES = [
'/apps_raw/get/'
]
-/** Matches a route id or a pathname alike. */
-function isItemPage(route: string): boolean {
- return EDIT_PAGES.some((p) => route.includes(p))
-}
-
-/** Points the params naming a workspace at `id`; whether anything changed. */
-function moveWorkspaceParams(url: URL, id: string): boolean {
+export async function fixupUrlAfterWorkspaceSwitch(
+ id: string,
+ // Decided by the caller so the rule stays with the picker that has the context
+ // for it — a picker rendered outside the sidebar drives its own page and must
+ // not be navigated away from.
+ opts?: { landOnHome?: boolean }
+): Promise {
+ if (EDIT_PAGES.some((p) => page.route.id?.includes(p) ?? false) || opts?.landOnHome) {
+ await goto('/')
+ return
+ }
+ // `window.location`, never `page.url`: a param written by a previous shallow update
+ // is in the address bar but not in `page.url`, so rebuilding from it would undo that
+ // write (see the note on `setQuery` in $lib/navigation).
+ const url = new URL(window.location.href)
let changed = false
for (const key of WORKSPACE_PARAMS) {
if (url.searchParams.get(key) === id) continue
@@ -46,33 +52,7 @@ function moveWorkspaceParams(url: URL, id: string): boolean {
url.searchParams.delete(key)
changed = true
}
- return changed
-}
-
-/** Where `href` (a pathname with its search) leads once the app has switched to `id`. */
-export function hrefAfterWorkspaceSwitch(href: string, id: string): string {
- const url = new URL(href, 'http://localhost')
- if (isItemPage(url.pathname)) return '/'
- moveWorkspaceParams(url, id)
- return `${url.pathname}${url.search}${url.hash}`
-}
-
-export async function fixupUrlAfterWorkspaceSwitch(
- id: string,
- // Decided by the caller so the rule stays with the picker that has the context
- // for it — a picker rendered outside the sidebar drives its own page and must
- // not be navigated away from.
- opts?: { landOnHome?: boolean }
-): Promise {
- if (isItemPage(page.route.id ?? '') || opts?.landOnHome) {
- await goto('/')
- return
- }
- // `window.location`, never `page.url`: a param written by a previous shallow update
- // is in the address bar but not in `page.url`, so rebuilding from it would undo that
- // write (see the note on `setQuery` in $lib/navigation).
- const url = new URL(window.location.href)
- if (!moveWorkspaceParams(url, id)) return
+ if (!changed) return
// `goto` rather than `replaceState`: a page reading these params through `page.url`
// (the compare page derives the workspace it compares from them) sees nothing when
// they are written shallowly, since SvelteKit refreshes `page.url` only on a
diff --git a/frontend/src/lib/newDraftFlag.test.ts b/frontend/src/lib/newDraftFlag.test.ts
index c60fe5bb3e..ecf1823a15 100644
--- a/frontend/src/lib/newDraftFlag.test.ts
+++ b/frontend/src/lib/newDraftFlag.test.ts
@@ -17,18 +17,14 @@ vi.mock('./localDraftHints.svelte', () => ({
setLocalDraftHint: vi.fn(),
getLocalDraftHint: () => hints.value
}))
-// `stripNewDraftFlag` rewrites the URL through SvelteKit's `replaceState` and
-// refreshes the page the sidebar switch returns to. Mock those so the strip is
-// observable via `window.location.href` (mirroring jsdom) and the remembered
-// page can be asserted.
-const rememberWorkspacePage = vi.hoisted(() => vi.fn())
+// `stripNewDraftFlag` rewrites the URL through SvelteKit's `replaceState`. Mock it
+// so the strip is observable via `window.location.href` (mirroring jsdom).
vi.mock('$app/navigation', () => ({
replaceState: (url: URL | string, _state: unknown) => {
window.location.href = new URL(url, window.location.href).toString()
}
}))
vi.mock('$app/state', () => ({ page: { state: {} } }))
-vi.mock('$lib/components/sessions/sessionSwitch.svelte', () => ({ rememberWorkspacePage }))
import { UserDraftDbSyncer } from './userDraftDbSyncer.svelte'
import { stripNewDraftFlagOnSave, shouldSeedNewDraft } from './newDraftFlag'
@@ -120,9 +116,6 @@ describe('stripNewDraftFlagOnSave', () => {
expect(window.location.href).not.toContain('new_draft')
// Sibling seeding params are preserved.
expect(window.location.href).toContain('template=foo')
- // The switch's Workspace side returns to the stripped URL, so it does not
- // come back with ?new_draft.
- expect(rememberWorkspacePage).toHaveBeenCalledWith('/scripts/edit/u/me/draft_d?template=foo')
})
it('does not strip on a delete save', async () => {
diff --git a/frontend/src/lib/newDraftFlag.ts b/frontend/src/lib/newDraftFlag.ts
index d6184ba705..05bf4d864e 100644
--- a/frontend/src/lib/newDraftFlag.ts
+++ b/frontend/src/lib/newDraftFlag.ts
@@ -1,6 +1,5 @@
import { page } from '$app/state'
import { replaceState } from '$app/navigation'
-import { rememberWorkspacePage } from '$lib/components/sessions/sessionSwitch.svelte'
import { UserDraftDbSyncer, type UserDraftLastSyncQuery } from '$lib/userDraftDbSyncer.svelte'
import { getLocalDraftHint } from '$lib/localDraftHints.svelte'
import type { UserDraftItemKind } from '$lib/gen'
@@ -11,17 +10,13 @@ import type { UserDraftItemKind } from '$lib/gen'
*
* Uses SvelteKit's `replaceState` (not raw `history.replaceState`, which the
* router warns conflicts with it) so the history entry keeps the router's
- * bookkeeping and `page.state`. Also refreshes the page the sidebar switch's
- * Workspace side returns to: `afterNavigate` never observes this in-place
- * rewrite, so the switch would restore the pre-strip URL — still carrying
- * `?new_draft=true` — and re-enter the seed-empty branch. */
+ * bookkeeping and `page.state`. */
export function stripNewDraftFlag(): void {
if (typeof window === 'undefined') return
const url = new URL(window.location.href)
if (url.searchParams.get('new_draft') !== 'true') return
url.searchParams.delete('new_draft')
replaceState(url, page.state)
- rememberWorkspacePage(url.pathname + url.search)
}
/**
@@ -31,7 +26,7 @@ export function stripNewDraftFlag(): void {
* `u//draft_?new_draft=true`; the seed branch bootstraps an empty
* (or template/hub/fork-seeded) editor instead of fetching a row that doesn't
* exist yet. But the flag can outlive the seed: a return to the editor's URL
- * (Back, the sidebar switch's Workspace side, a link kept from before) still
+ * (Back, a link kept from before) still
* carries `?new_draft=true` after the
* draft was materialized — by the first autosave, or by "Open in AI session"'s
* `forcePersist`. Re-running the seed branch then blanks the saved draft.
diff --git a/frontend/src/routes/(root)/(logged)/+layout.svelte b/frontend/src/routes/(root)/(logged)/+layout.svelte
index 142d9355de..8fb84fc8e0 100644
--- a/frontend/src/routes/(root)/(logged)/+layout.svelte
+++ b/frontend/src/routes/(root)/(logged)/+layout.svelte
@@ -120,7 +120,10 @@
parsePreviewItemRoute,
barePath
} from '$lib/components/sessions/previewPaths'
- import { sessionsSwitchShown, sidebarListFor } from '$lib/components/sessions/sidebarList.svelte'
+ import {
+ chosenSidebarList,
+ sessionsSwitchShown
+ } from '$lib/components/sessions/sidebarList.svelte'
import { noteArrival } from '$lib/components/sessions/sessionSwitch.svelte'
import { sessionState } from '$lib/components/sessions/sessionState.svelte'
import { restoreSessionBackups } from '$lib/components/sessions/sessionMirror.svelte'
@@ -154,10 +157,6 @@
})
)
let menuOpen = $state(false)
- // Set by the Workspace ⇄ AI Sessions switch before it navigates, so the mobile menu
- // drawer stays open across it to show the list it switched to (unlike a normal link
- // navigation, which dismisses it). Consumed once in beforeNavigate.
- let preserveMenuOnNextNav = false
let globalSearchModal: GlobalSearchModal | undefined = $state(undefined)
// Persisted nav-rail collapse preference. A deliberate collapse writes to it —
// the manual toggle and a drag past the collapse threshold. The contextual
@@ -324,10 +323,8 @@
// A workspace that hid the assistant (`ai_config.copilot_disabled`) loses both entry
// points: the Workspace ⇄ AI Sessions switch and the legacy Ask-AI button.
const switchRowShown = $derived(sessionsSwitchShown())
- // The page picks the list: a session's page lists sessions and a workspace page shows
- // the workspace nav. Home keeps the list you came from. Where the switch is hidden, so
- // is the session list.
- const sidebarList = $derived(sidebarListFor(page.url.pathname))
+ // Where the switch is hidden, so is the session list.
+ const sidebarList = $derived(chosenSidebarList.val)
const sidebarListsSessions = $derived(switchRowShown && sidebarList === 'sessions')
const askAiShown = $derived(
(!globalAiEnabled || !sessionsAllowed) && !$copilotInfo.workspaceDisabled
@@ -448,11 +445,7 @@
onNavigate(homeSessionsTransition)
beforeNavigate((navigation) => {
- if (preserveMenuOnNextNav) {
- preserveMenuOnNextNav = false
- } else {
- menuOpen = false
- }
+ menuOpen = false
// Inside a sessions-preview iframe, hand an editor-route navigation up to the
// parent so it mounts the in-process editor (sharing the session runtime)
@@ -789,9 +782,7 @@
$usedTriggerKinds = usedKinds
}
- // Where each side of the Workspace ⇄ AI Sessions switch was left, so the switch comes
- // back there. Not inside a preview iframe: it has no switch, and Home's list is stored
- // per browser, so the frame's own navigation would set the list of the page around it.
+ // Not inside a preview iframe: it opens no session page of its own.
afterNavigate((n) => {
if (!embedded && n.to) noteArrival(n.to.url)
})
@@ -1262,87 +1253,98 @@ outside this layout, and their shortcut must reopen the URL that is their creden
aiDescription="Button to navigate to home which contains all the user's scripts, flows and apps"
/>
- {#if switchRowShown}
-
-
-
(preserveMenuOnNextNav = true) : undefined}
- />
+
+
- {/if}
+ {/if}
- {#if sidebarListsSessions}
-
-
- {@render settingsMenu(collapsed)}
- {:else}
-
-
- {/if}
+
+ {@render settingsMenu(collapsed)}
+
+
+ {/if}
+
{@render accountSetupBanner(collapsed)}
diff --git a/frontend/src/routes/(root)/(logged)/sessions/+page.svelte b/frontend/src/routes/(root)/(logged)/sessions/+page.svelte
index c6d036aac9..a3818334b7 100644
--- a/frontend/src/routes/(root)/(logged)/sessions/+page.svelte
+++ b/frontend/src/routes/(root)/(logged)/sessions/+page.svelte
@@ -50,11 +50,7 @@
type SessionPreviewTab
} from '$lib/components/sessions/sessionState.svelte'
import { withWorkspaceParam } from '$lib/components/sessions/sessionMode.svelte'
- import {
- openDraftOnHome,
- resumeAiSessions,
- returnToWorkspace
- } from '$lib/components/sessions/sessionSwitch.svelte'
+ import { openDraftOnHome, resumeAiSessions } from '$lib/components/sessions/sessionSwitch.svelte'
import { sendUserToast } from '$lib/toast'
import type { SessionPreviewTabs } from '$lib/components/sessions/sessionPreviewTabs.svelte'
import {
@@ -179,8 +175,8 @@
// Family reconcile: a workspace switch can land this page with no session
// selected or with another family's session in the URL (the workspace menu's
// link navigation keeps the route), and a chat must not bleed across
- // families. Both resume as the switch's AI Sessions side does, within the
- // active family. A `session` that resolves to nothing is left to the
+ // families. Both resume the last session opened, within the active family.
+ // A `session` that resolves to nothing is left to the
// recovery effect below.
$effect(() => {
if (embedded || !sessionState.hydrated) return
@@ -1238,7 +1234,7 @@
>
AI Sessions are hidden in this workspace
A workspace admin hid AI sessions in the workspace settings.
-
returnToWorkspace()}>Back to workspace
+
goto('/')}>Back to workspace
{/if}