Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Studio: drag pinned pages in the sidebar like chats (#12927)
Michael Han67c533f13a67
diff --git a/studio/frontend/src/components/app-sidebar.tsx b/studio/frontend/src/components/app-sidebar.tsxindex 92d6dcd3f4f..bde6c857ecc 100644--- a/studio/frontend/src/components/app-sidebar.tsx+++ b/studio/frontend/src/components/app-sidebar.tsx@@ -293,7 +293,7 @@ import {import { ShutdownDialog } from "@/components/shutdown-dialog";import { buildChatItemMarkdown } from "@/features/chat/prompt-storage/prompt-storage-dialog";import { useActiveChatMenuStore } from "@/features/chat/stores/active-chat-menu-store";-import { PinnedPageRows, usePinnedPageCount } from "@/features/browser";+import { type PinnedPage, PinnedPageRow, usePinnedPages } from "@/features/browser";import { translate, useT, type TranslationKey } from "@/i18n";const RECENT_SLOT_NUMBERS = [1, 2, 3, 4, 5, 6] as const;@@ -471,10 +471,11 @@ type SectionTarget = {selection?: boolean;};-// One row of the Pinned list, which holds folders and chats together.+// One row of Pinned or a custom section: a folder, chat or pinned page.type PinnedRow =| { kind: "project"; id: string; project: ProjectRecord }- | { kind: "chat"; id: string; item: SidebarItem };+ | { kind: "chat"; id: string; item: SidebarItem }+ | { kind: "page"; id: string; page: PinnedPage };// A row's menu is written once and rendered into both the 3-dot dropdown and the right-click// menu, which offer the same actions. Typed as the props the rows pass, not as a union of the@@ -1361,6 +1362,7 @@ export function AppSidebar() {// User-made sections, what is filed in them, and which sections "Show" turned off.const customSections = useSidebarOrganizationStore((s) => s.customSections);const sectionByChatId = useSidebarOrganizationStore((s) => s.sectionByChatId);+ const sectionByPageId = useSidebarOrganizationStore((s) => s.sectionByPageId);const sectionByProjectId = useSidebarOrganizationStore((s) => s.sectionByProjectId,);@@ -1431,6 +1433,7 @@ export function AppSidebar() {);const setChatsSection = useSidebarOrganizationStore((s) => s.setChatsSection);const setProjectsSection = useSidebarOrganizationStore((s) => s.setProjectsSection);+ const setPagesSection = useSidebarOrganizationStore((s) => s.setPagesSection);const setSectionHidden = useSidebarOrganizationStore((s) => s.setSectionHidden);// With the Projects section on, a project chat lives in its folder and repeating it here would be// noise. With it off there are no folders, so Recents is where those chats go. Pinned chats are@@ -1446,7 +1449,7 @@ export function AppSidebar() {[allChatItems, pinnedIdSet, sectionByChatId, organizeBy],);const [pinnedOpen, setPinnedOpen] = useState(true);- const pinnedPageCount = usePinnedPageCount();+ const pinnedPages = usePinnedPages();const [projectsOpen, setProjectsOpen] = useState(true);const [showAllProjects, setShowAllProjects] = useState(false);// Pinning a project moves its folder into the Pinned section, beside the pinned chats.@@ -1798,19 +1801,25 @@ export function AppSidebar() {for (const item of sortedPinnedChatItems) {rows.push({ kind: "chat", id: item.id, item });}+ // Pages go after sorted chats, in pin order. Pages filed in a section show there instead.+ for (const page of pinnedPages) {+ if (!sectionByPageId[page.id]) rows.push({ kind: "page", id: page.id, page });+ }return pinnedSort === "manual"? applyManualOrder(rows, manualOrder[PINNED_ORDER_SCOPE], (row) => row.id): rows;- }, [pinnedProjectBase, sortedPinnedChatItems, pinnedSort, manualOrder]);+ }, [pinnedProjectBase, sortedPinnedChatItems, pinnedPages, sectionByPageId, pinnedSort, manualOrder]);const pinnedRowIds = useMemo(() => pinnedRows.map((row) => row.id), [pinnedRows]);// Each custom section is one list of folders and chats, as Pinned is: folders lead until a drop// says otherwise. A pinned row stays in Pinned and keeps its section for when it is unpinned.const customSectionRows = useMemo(() => {const folders = new Map<string, PinnedRow[]>();const chats = new Map<string, SidebarItem[]>();+ const pages = new Map<string, PinnedRow[]>();for (const section of customSections) {folders.set(section.id, []);chats.set(section.id, []);+ pages.set(section.id, []);}for (const project of projects) {const sectionId = sectionByProjectId[project.id];@@ -1822,6 +1831,10 @@ export function AppSidebar() {if (!sectionId || pinnedIdSet.has(item.id)) continue;chats.get(sectionId)?.push(item);}+ for (const page of pinnedPages) {+ const sectionId = sectionByPageId[page.id];+ if (sectionId) pages.get(sectionId)?.push({ kind: "page", id: page.id, page });+ }const rows = new Map<string, PinnedRow[]>();for (const section of customSections) {const scope = customSectionScope(section.id);@@ -1830,6 +1843,7 @@ export function AppSidebar() {...sortChatItems(chats.get(section.id) ?? [], scope, section.sort).map((item): PinnedRow => ({ kind: "chat", id: item.id, item }),),+ ...(pages.get(section.id) ?? []),];rows.set(section.id,@@ -1845,6 +1859,8 @@ export function AppSidebar() {allChatItems,sectionByProjectId,sectionByChatId,+ pinnedPages,+ sectionByPageId,pinnedProjectIdSet,pinnedIdSet,sortChatItems,@@ -1957,7 +1973,9 @@ export function AppSidebar() {? pinnedRows.flatMap((row) =>row.kind === "project"? folderChatItems(true, [row.project])- : [row.item],+ : row.kind === "chat"+ ? [row.item]+ : [],): [],[chatListsOnScreen, pinnedOpen, pinnedRows, folderChatItems],@@ -1971,7 +1989,11 @@ export function AppSidebar() {bySection.set(section.id,(customSectionRows.get(section.id) ?? []).flatMap((row) =>- row.kind === "project" ? folderChatItems(true, [row.project]) : [row.item],+ row.kind === "project"+ ? folderChatItems(true, [row.project])+ : row.kind === "chat"+ ? [row.item]+ : [],),);}@@ -2402,6 +2424,7 @@ export function AppSidebar() {pinnedProjectIds: pinnedProjectIdSet,sectionByChatId,sectionByProjectId,+ sectionByPageId,sectionSort: (sectionId) =>customSections.find((section) => section.id === sectionId)?.sort ?? "manual",orders: {@@ -2415,6 +2438,7 @@ export function AppSidebar() {[sectionByChatId,sectionByProjectId,+ sectionByPageId,customSections,customSectionIds,organizeBy,@@ -2522,6 +2546,7 @@ export function AppSidebar() {const filing = effects.fileInSection;if (!filing) return;if (filing.kind === "chat") setChatsSection([filing.id], filing.sectionId);+ else if (filing.kind === "page") setPagesSection([filing.id], filing.sectionId);else setProjectsSection([filing.id], filing.sectionId);if (filing.sectionId) setCustomSectionOpen(filing.sectionId, true);};@@ -3974,7 +3999,8 @@ export function AppSidebar() {// them into decides where it goes.// Pinned: folders and chats in one list, in the order they were dropped into.function renderPinnedSection(): ReactNode {- if (isStudioRoute || showTrainingRecents || (pinnedRows.length === 0 && pinnedPageCount === 0)) return null;+ // Kept while pages are filed elsewhere, so they can be dragged back.+ if (isStudioRoute || showTrainingRecents || (pinnedRows.length === 0 && pinnedPages.length === 0)) return null;const firstPinnedRow = pinnedRows[0];return (<Collapsible open={pinnedOpen} onOpenChange={setPinnedOpen} asChild>@@ -4012,7 +4038,11 @@ export function AppSidebar() {<CollapsibleContent>{/* The space under the rows lands a drop last. */}<SidebarGroupContent- className={cn(unrailedRowPadding, "relative")}+ className={cn(+ unrailedRowPadding,+ "relative",+ dnd.ringLit(sectionRingKey("pinned")) && DROP_INTO_CUE,+ )}{...dnd.dropZoneProps({ section: "pinned" })}><SidebarMenu>@@ -4025,16 +4055,29 @@ export function AppSidebar() {section: "pinned",sort: { value: pinnedSort, set: setPinnedSort },})- : renderChatSidebarItem(row.item, "recent", {- scope: PINNED_ORDER_SCOPE,- ids: pinnedChatRowIds,- orderIds: pinnedRowIds,- section: "pinned",- sort: { value: pinnedSort, set: setPinnedSort },- }),+ : row.kind === "page"+ ? renderPinnedPageRow(row.page, {+ scope: PINNED_ORDER_SCOPE,+ orderedIds: pinnedRowIds,+ section: "pinned",+ sort: { value: pinnedSort, set: setPinnedSort },+ })+ : renderChatSidebarItem(row.item, "recent", {+ scope: PINNED_ORDER_SCOPE,+ ids: pinnedChatRowIds,+ orderIds: pinnedRowIds,+ section: "pinned",+ sort: { value: pinnedSort, set: setPinnedSort },+ }),)}- {/* Pages pinned from a browser tab's menu, after the chats and folders. */}- <PinnedPageRows />+ {pinnedRows.length === 0 ? (+ // Every pinned page is filed elsewhere: somewhere to drag them back to.+ <SidebarMenuItem>+ <p className="flex h-[calc(30px*var(--ui-space-scale,1))] items-center pl-3 pr-4 text-ui-13 leading-ui-18 tracking-nav text-nav-fg-muted">+ {t("shell.sections.empty")}+ </p>+ </SidebarMenuItem>+ ) : null}{/* The end of the list, as somewhere to aim. A folder last in Pinned runs itsblock to the bottom of the section, so every pixel down there is inside itand a chat meant to go after the folder was filed into it instead.@@ -4152,13 +4195,15 @@ export function AppSidebar() {section: scope,sort,})- : renderChatSidebarItem(row.item, "recent", {- scope,- ids: ids.chats,- orderIds: ids.rows,- section: scope,- sort,- }),+ : row.kind === "page"+ ? renderPinnedPageRow(row.page, { scope, orderedIds: ids.rows, section: scope, sort })+ : renderChatSidebarItem(row.item, "recent", {+ scope,+ ids: ids.chats,+ orderIds: ids.rows,+ section: scope,+ sort,+ }),)}{rows.length === 0 ? (// Gives an empty section a body to hit, as the empty Projects line does.@@ -4666,6 +4711,35 @@ export function AppSidebar() {);}+ /** A pinned page row, draggable and keyboard-reorderable like a chat row. */+ function renderPinnedPageRow(+ page: PinnedPage,+ list: { scope: string; orderedIds: string[]; section: SidebarSection; sort?: RowSort },+ ): ReactNode {+ return (+ <PinnedPageRow+ key={page.id}+ page={page}+ className={cn(+ DROP_ROW_HIT,+ draggingRow?.id === page.id && "opacity-40",+ dropCueClass(list.scope, page.id),+ )}+ rowProps={{+ ...rowDragProps({+ item: { kind: "page", id: page.id, section: list.section, scope: list.scope, projectId: null },+ orderedIds: list.orderedIds,+ sort: list.sort,+ }),+ ...dnd.dropZoneProps({+ section: list.section,+ row: { id: page.id, kind: "page", scope: list.scope },+ }),+ }}+ />+ );+ }+function renderChatSidebarItem(item: SidebarItem,variant: "project" | "recent",diff --git a/studio/frontend/src/features/browser/index.ts b/studio/frontend/src/features/browser/index.tsindex 6c2e5d0b49c..3306a4c31d6 100644--- a/studio/frontend/src/features/browser/index.ts+++ b/studio/frontend/src/features/browser/index.ts@@ -26,7 +26,8 @@ export {export { type FileViewMode, type OpenFileInput, useBrowserStore } from "./store";export { browserPanelAvailable, setBrowserPanelAvailable } from "./panel-availability";-export { PinnedPageRows, usePinnedPageCount } from "./pinned-page-row";+export { PinnedPageRow, usePinnedPages } from "./pinned-page-row";+export type { PinnedPage } from "./pinned-pages-store";/** Open a link in the browser panel; false if unavailable or links go to the system browser. */export function openUrlInBrowser(url: string): boolean {diff --git a/studio/frontend/src/features/browser/pinned-page-row.tsx b/studio/frontend/src/features/browser/pinned-page-row.tsxindex 5866a8584e9..bd5bef64ac0 100644--- a/studio/frontend/src/features/browser/pinned-page-row.tsx+++ b/studio/frontend/src/features/browser/pinned-page-row.tsx@@ -1,9 +1,8 @@// SPDX-License-Identifier: AGPL-3.0-only// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0-// A page pinned from a tab's menu, as a row of the sidebar's Pinned section: its icon and name,-// a one-click unpin, and the tab's menu (3-dot and right-click). Clicking it shows its tab in the-// browser panel, opening one at the pinned address when none is open.+// A pinned page's sidebar row: icon, name, unpin and the tab's menu. Clicking shows its tab,+// opening one if needed. The sidebar places and drags it like a chat (`rowProps`).import {ContextMenu,@@ -18,7 +17,7 @@ import { cn } from "@/lib/utils";import { MoreHorizontalIcon, PinOffIcon } from "@hugeicons/core-free-icons";import { HugeiconsIcon } from "@hugeicons/react";import { useNavigate, useRouterState } from "@tanstack/react-router";-import { useRef, useState } from "react";+import { type HTMLAttributes, useRef, useState } from "react";import { browserPanelAvailable } from "./panel-availability";import { type PinnedPage, usePinnedPagesStore } from "./pinned-pages-store";import { SiteFavicon } from "./site-favicon";@@ -38,23 +37,21 @@ const MENU = "unsloth-plus-menu sidebar-row-menu sidebar-menu w-60";const ACTION ="sidebar-row-action sidebar-touch-reveal group-hover/recent-item:opacity-100 group-hover/recent-item:pointer-events-auto focus-visible:opacity-100 focus-visible:pointer-events-auto group-has-[.sidebar-row-action[data-state=open]]/recent-item:opacity-100 group-has-[.sidebar-row-action[data-state=open]]/recent-item:pointer-events-auto";-/** The Pinned section's page rows, after its chats and folders. */-export function PinnedPageRows() {- const pages = usePinnedPagesStore((state) => state.pages);- return (- <>- {pages.map((page) => (- <PinnedPageRow key={page.id} page={page} />- ))}- </>- );-}--export function usePinnedPageCount(): number {- return usePinnedPagesStore((state) => state.pages.length);+/** Every pinned page, in pin order. */+export function usePinnedPages(): PinnedPage[] {+ return usePinnedPagesStore((state) => state.pages);}-function PinnedPageRow({ page }: { page: PinnedPage }) {+export function PinnedPageRow({+ page,+ className,+ rowProps,+}: {+ page: PinnedPage;+ className?: string;+ /** Sidebar drag and drop props, as on a chat row. */+ rowProps?: HTMLAttributes<HTMLLIElement> & Record<`data-${string}`, string>;+}) {const t = useT();const navigate = useNavigate();const onChat = useRouterState({ select: (state) => state.location.pathname.startsWith("/chat") });@@ -105,7 +102,11 @@ function PinnedPageRow({ page }: { page: PinnedPage }) {return (<ContextMenu><ContextMenuTrigger asChild={true}>- <SidebarMenuItem className="group/recent-item relative" data-pinned-page={page.id}>+ <SidebarMenuItem+ {...rowProps}+ className={cn("group/recent-item relative", className)}+ data-pinned-page={page.id}+ ><SidebarMenuButtonisActive={active}title={page.url}diff --git a/studio/frontend/src/features/chat/lib/sidebar-drag.ts b/studio/frontend/src/features/chat/lib/sidebar-drag.tsindex 8e811a89d06..4e6d31c71dd 100644--- a/studio/frontend/src/features/chat/lib/sidebar-drag.ts+++ b/studio/frontend/src/features/chat/lib/sidebar-drag.ts@@ -19,7 +19,8 @@ import {type SidebarOrganizeBy,} from "../stores/sidebar-organization-store.ts";-export type SidebarRowKind = "chat" | "project";+/** `page` is a pinned browser page: shown in Pinned or a custom section only. */+export type SidebarRowKind = "chat" | "project" | "page";/** A built-in list, or a custom section keyed by its order scope (`section:<id>`). */export type SidebarSection =| "pinned"@@ -36,7 +37,7 @@ export interface SidebarDragItem {section: SidebarSection;/** Order scope of the list it was picked up from. */scope: string;- /** For a chat, the folder it is filed in. Null outside every folder, and for a folder. */+ /** For a chat, the folder it is filed in. Null outside every folder, and for a folder or page. */projectId: string | null;}@@ -68,6 +69,7 @@ export interface SidebarDropContext {/** The custom section each chat and folder is filed in. Pinned still draws a pinned row. */sectionByChatId: Readonly<Record<string, string>>;sectionByProjectId: Readonly<Record<string, string>>;+ sectionByPageId: Readonly<Record<string, string>>;/** A custom section's chat sort. */sectionSort: (sectionId: string) => SidebarChatSort;/** Row ids per list, in drawn order. Pinned and every custom section are one list of folders@@ -170,6 +172,7 @@ function ownSection(if (ctx.pinnedProjectIds.has(id)) return null;return ctx.sectionByProjectId[id] ?? null;}+ if (kind === "page") return ctx.sectionByPageId[id] ?? null;if (ctx.pinnedChatIds.has(id)) return null;return ctx.sectionByChatId[id] ?? null;}@@ -186,7 +189,11 @@ function leavingSection(if (!outcome || outcome === STAY) return outcome;if (outcome.action.kind === "reorder" || outcome.action.kind === "pin") return outcome;const filed =- drag.kind === "project" ? ctx.sectionByProjectId[drag.id] : ctx.sectionByChatId[drag.id];+ drag.kind === "project"+ ? ctx.sectionByProjectId[drag.id]+ : drag.kind === "page"+ ? ctx.sectionByPageId[drag.id]+ : ctx.sectionByChatId[drag.id];if (!filed || outcome.effects.fileInSection) return outcome;return {...outcome,@@ -243,6 +250,8 @@ export function planSidebarDrop(if (zone.section === "pinned") {return leavingSection(drag, planPinnedDrop(drag, zone, edge, ctx), ctx);}+ // Pages can't go in Projects, Recents or a folder.+ if (drag.kind === "page") return null;return leavingSection(drag,drag.kind === "project"@@ -347,10 +356,13 @@ function planPinnedDrop(return planChatDrop(drag, zone, edge, ctx);}const ids = ctx.orders.pinned;+ // A page is in Pinned unless filed in a section.const inList =drag.kind === "project"? ctx.pinnedProjectIds.has(drag.id)- : ctx.pinnedChatIds.has(drag.id);+ : drag.kind === "page"+ ? ownSection("page", drag.id, ctx) === null+ : ctx.pinnedChatIds.has(drag.id);let target: { id: string; edge: DropEdge } | null = null;if (zone.row) {if (zone.folderId && zone.row.kind === "chat" && zone.block) {@@ -366,21 +378,30 @@ function planPinnedDrop(// The section's own space: last.target = { id: ids[ids.length - 1], edge: "bottom" };}- if (!target) return null;- if (target.id === drag.id) return STAY;+ if (target?.id === drag.id) return STAY;const resorts = ctx.pinnedSort !== "manual";- const next = inList- ? insertIdAt(ids, drag.id, target.id, target.edge)- : placeIdAt(ids, drag.id, target.id, target.edge);+ // No target: Pinned is empty (shown while its pages are filed elsewhere), so this is its first row.+ const next = !target+ ? [drag.id]+ : inList+ ? insertIdAt(ids, drag.id, target.id, target.edge)+ : placeIdAt(ids, drag.id, target.id, target.edge);if (next === ids) return STAY;// folderLine is the plain line unless the zone names a block end to land below, so the section's// own tail draws under the last row of the folder that ends it, not under that folder's title.- const cue = folderLine(PINNED_ORDER_SCOPE, target.id, target.edge, zone);+ const cue = target+ ? folderLine(PINNED_ORDER_SCOPE, target.id, target.edge, zone)+ : ring(sectionRingKey("pinned"));const effects: SidebarDropEffects = {orders: [{ scope: PINNED_ORDER_SCOPE, ids: next }],switchSort: resorts ? "pinned" : undefined,};if (inList) return { action: { kind: "reorder" }, cue, effects };+ if (drag.kind === "page") {+ // Back to Pinned means leaving its section.+ effects.fileInSection = { kind: "page", id: drag.id, sectionId: null };+ return { action: { kind: "pin" }, cue, effects };+ }if (drag.kind === "project") effects.pinProject = drag.id;else effects.pinChat = drag.id;return { action: { kind: "pin" }, cue, effects };diff --git a/studio/frontend/src/features/chat/stores/remove-custom-section.ts b/studio/frontend/src/features/chat/stores/remove-custom-section.tsindex 90a8781a0f7..87571c5c439 100644--- a/studio/frontend/src/features/chat/stores/remove-custom-section.ts+++ b/studio/frontend/src/features/chat/stores/remove-custom-section.ts@@ -20,6 +20,9 @@ export function removeCustomSectionWithUndo(section: SidebarCustomSection): () =const projectIds = Object.keys(state.sectionByProjectId).filter((id) => state.sectionByProjectId[id] === section.id,);+ const pageIds = Object.keys(state.sectionByPageId).filter(+ (id) => state.sectionByPageId[id] === section.id,+ );const order = state.manualOrder[customSectionScope(section.id)];const hidden = state.hiddenSections.includes(section.id);// Undo reinserts it above the first of these that still exists.@@ -35,6 +38,8 @@ export function removeCustomSectionWithUndo(section: SidebarCustomSection): () =for (const id of chatIds) sectionByChatId[id] ??= section.id;const sectionByProjectId = assignmentMap(now.sectionByProjectId);for (const id of projectIds) sectionByProjectId[id] ??= section.id;+ const sectionByPageId = assignmentMap(now.sectionByPageId);+ for (const id of pageIds) sectionByPageId[id] ??= section.id;const sectionOrder = resolveSectionOrder(now.sectionOrder, now.customSections);const follower = followers.find((key) => sectionOrder.includes(key));sectionOrder.splice(@@ -48,6 +53,7 @@ export function removeCustomSectionWithUndo(section: SidebarCustomSection): () =sectionOrder,sectionByChatId,sectionByProjectId,+ sectionByPageId,hiddenSections: hidden? [...now.hiddenSections, section.id]: now.hiddenSections,diff --git a/studio/frontend/src/features/chat/stores/sidebar-organization-store.ts b/studio/frontend/src/features/chat/stores/sidebar-organization-store.tsindex 189ca52f43a..6c86fbf2632 100644--- a/studio/frontend/src/features/chat/stores/sidebar-organization-store.ts+++ b/studio/frontend/src/features/chat/stores/sidebar-organization-store.ts@@ -149,6 +149,8 @@ export interface SidebarOrganizationState {sectionByChatId: Record<string, string>;/** Project id -> the custom section its folder is drawn in, on the same terms. */sectionByProjectId: Record<string, string>;+ /** Pinned page id -> the custom section it shows in instead of Pinned. */+ sectionByPageId: Record<string, string>;/** Section keys the "Show" toggles turned off: Projects or a custom section's id. */hiddenSections: string[];/** The order of the sections above Recents, as dragged; read through resolveSectionOrder. */@@ -171,6 +173,7 @@ export interface SidebarOrganizationState {/** Files chats into a section, or out of every section with null. */setChatsSection: (chatIds: string[], sectionId: string | null) => void;setProjectsSection: (projectIds: string[], sectionId: string | null) => void;+ setPagesSection: (pageIds: string[], sectionId: string | null) => void;setSectionHidden: (key: string, hidden: boolean) => void;/** Drops the section `key` against the `edge` side of `targetKey`, as a row drag lands. */moveSection: (key: string, targetKey: string, edge: "top" | "bottom") => void;@@ -403,6 +406,7 @@ export function mergePersistedOrganization(customSections,sectionByChatId: readAssignments(saved?.sectionByChatId),sectionByProjectId: readAssignments(saved?.sectionByProjectId),+ sectionByPageId: readAssignments(saved?.sectionByPageId),hiddenSections,sectionOrder,};@@ -419,6 +423,7 @@ export const useSidebarOrganizationStore = create<SidebarOrganizationState>()(customSections: [],sectionByChatId: assignmentMap(),sectionByProjectId: assignmentMap(),+ sectionByPageId: assignmentMap(),hiddenSections: [],sectionOrder: [],pendingNewChatSection: null,@@ -472,6 +477,7 @@ export const useSidebarOrganizationStore = create<SidebarOrganizationState>()(customSections: state.customSections.filter((s) => s.id !== sectionId),sectionByChatId: withoutSection(state.sectionByChatId, gone),sectionByProjectId: withoutSection(state.sectionByProjectId, gone),+ sectionByPageId: withoutSection(state.sectionByPageId, gone),hiddenSections: state.hiddenSections.filter((key) => key !== sectionId),sectionOrder: state.sectionOrder.filter((key) => key !== sectionId),manualOrder,@@ -536,6 +542,27 @@ export const useSidebarOrganizationStore = create<SidebarOrganizationState>()(customSections: touchSections(state.customSections, touched),};}),+ setPagesSection: (pageIds, sectionId) =>+ set((state) => {+ if (sectionId && !state.customSections.some((s) => s.id === sectionId)) {+ return state;+ }+ const next = assignmentMap(state.sectionByPageId);+ const touched = new Set<string>();+ for (const id of pageIds) {+ const from = next[id];+ if (from === (sectionId ?? undefined)) continue;+ if (from) touched.add(from);+ if (sectionId) {+ next[id] = sectionId;+ touched.add(sectionId);+ } else delete next[id];+ }+ return {+ sectionByPageId: next,+ customSections: touchSections(state.customSections, touched),+ };+ }),setSectionHidden: (key, hidden) =>set((state) => {const has = state.hiddenSections.includes(key);diff --git a/studio/frontend/tests/sidebar-custom-sections.test.ts b/studio/frontend/tests/sidebar-custom-sections.test.tsindex 14918bf6456..54b5531244a 100644--- a/studio/frontend/tests/sidebar-custom-sections.test.ts+++ b/studio/frontend/tests/sidebar-custom-sections.test.ts@@ -6,6 +6,7 @@// and Projects with the same header menu every other list carries.import assert from "node:assert/strict";+import { register } from "node:module";import test from "node:test";import {@@ -52,6 +53,7 @@ function resetStore() {customSections: initial.customSections,sectionByChatId: initial.sectionByChatId,sectionByProjectId: initial.sectionByProjectId,+ sectionByPageId: initial.sectionByPageId,hiddenSections: initial.hiddenSections,sectionOrder: initial.sectionOrder,pendingNewChatSection: null,@@ -339,6 +341,7 @@ function context(overrides: Partial<SidebarDropContext> = {}): SidebarDropContexpinnedProjectIds: new Set(),sectionByChatId: { s1: S },sectionByProjectId: { lab: S },+ sectionByPageId: {},sectionSort: () => "manual",orders: {pinned: ["p1"],@@ -1041,3 +1044,110 @@ test("a row's section menu offers Remove from section only when it is in one", aassert.doesNotMatch(source, /noSection:/, locale);}});++// ---------------------------------------------------------------------------------------------+// Pinned pages drag like chats++const page = (id: string, section: SidebarDragItem["section"], scope: string): SidebarDragItem => ({+ kind: "page",+ id,+ section,+ scope,+ projectId: null,+});++test("a pinned page reorders among Pinned's chats, and a sorted Pinned switches to Manual", () => {+ const ctx = context({ orders: { ...context().orders, pinned: ["p1", "pg"] } });+ const plan = plannedDrop(+ planSidebarDrop(page("pg", "pinned", PINNED_ORDER_SCOPE), chatRow("pinned", PINNED_ORDER_SCOPE, "p1"), "top", ctx),+ );+ assert.deepEqual(plan.action, { kind: "reorder" });+ assert.deepEqual(plan.effects.orders, [{ scope: PINNED_ORDER_SCOPE, ids: ["pg", "p1"] }]);+ const sorted = plannedDrop(+ planSidebarDrop(page("pg", "pinned", PINNED_ORDER_SCOPE), chatRow("pinned", PINNED_ORDER_SCOPE, "p1"), "top", {+ ...ctx,+ pinnedSort: "updated",+ }),+ );+ assert.equal(sorted.effects.switchSort, "pinned");+});++test("a pinned page files into a custom section and comes back to Pinned", () => {+ const into = plannedDrop(+ planSidebarDrop(page("pg", "pinned", PINNED_ORDER_SCOPE), chatRow(SCOPE, SCOPE, "s1"), "bottom", context()),+ );+ assert.deepEqual(into.action, { kind: "section", sectionId: S });+ assert.deepEqual(into.effects.fileInSection, { kind: "page", id: "pg", sectionId: S });+ assert.deepEqual(into.effects.orders, [{ scope: SCOPE, ids: ["lab", "s1", "pg"] }]);+ assert.equal(into.effects.unpinChat, undefined);++ const filed = context({+ sectionByPageId: { pg: S },+ orders: { ...context().orders, sections: (sectionId) => (sectionId === S ? ["lab", "s1", "pg"] : []) },+ });+ const back = plannedDrop(+ planSidebarDrop(page("pg", SCOPE, SCOPE), chatRow("pinned", PINNED_ORDER_SCOPE, "p1"), "top", filed),+ );+ assert.deepEqual(back.action, { kind: "pin" });+ assert.deepEqual(back.effects.fileInSection, { kind: "page", id: "pg", sectionId: null });+ assert.deepEqual(back.effects.orders, [{ scope: PINNED_ORDER_SCOPE, ids: ["pg", "p1"] }]);+ const reorder = plannedDrop(planSidebarDrop(page("pg", SCOPE, SCOPE), chatRow(SCOPE, SCOPE, "s1"), "top", filed));+ assert.deepEqual(reorder.action, { kind: "reorder" });+ assert.deepEqual(reorder.effects.orders, [{ scope: SCOPE, ids: ["lab", "pg", "s1"] }]);+});++test("a pinned page has no place in Recents, Projects or a folder", () => {+ const drag = page("pg", "pinned", PINNED_ORDER_SCOPE);+ assert.equal(planSidebarDrop(drag, chatRow("recents", RECENTS_ORDER_SCOPE, "r1"), "top", context()), null);+ assert.equal(planSidebarDrop(drag, { section: "projects" }, "top", context()), null);+ assert.equal(+ planSidebarDrop(drag, chatRow("projects", projectOrderScope("home"), "c3", "home"), "top", context()),+ null,+ );+});++test("pages file into sections, and a deleted section gives them back to Pinned", () => {+ resetStore();+ const store = useSidebarOrganizationStore.getState();+ const gone = store.createCustomSection("Gone")!;+ const kept = store.createCustomSection("Kept")!;+ store.setPagesSection(["a", "b"], gone);+ store.setPagesSection(["b"], kept);+ assert.deepEqual({ ...useSidebarOrganizationStore.getState().sectionByPageId }, { a: gone, b: kept });+ store.deleteCustomSection(gone);+ assert.deepEqual({ ...useSidebarOrganizationStore.getState().sectionByPageId }, { b: kept });+ store.setPagesSection(["b"], null);+ assert.deepEqual({ ...useSidebarOrganizationStore.getState().sectionByPageId }, {});+});++test("an empty Pinned takes a dragged page as its first row", () => {+ const empty = context({+ sectionByPageId: { pg: S },+ orders: { ...context().orders, pinned: [], sections: (sectionId) => (sectionId === S ? ["pg"] : []) },+ });+ for (const zone of [{ section: "pinned" as const }, { section: "pinned" as const, header: true }]) {+ const plan = plannedDrop(planSidebarDrop(page("pg", SCOPE, SCOPE), zone, "bottom", empty));+ assert.deepEqual(plan.cue, { ring: sectionRingKey("pinned") });+ assert.deepEqual(plan.effects.orders, [{ scope: PINNED_ORDER_SCOPE, ids: ["pg"] }]);+ assert.deepEqual(plan.effects.fileInSection, { kind: "page", id: "pg", sectionId: null });+ }+});++test("undoing a removed section files its pages back into it", async () => {+ // remove-custom-section.ts imports without an extension.+ const resolver = `export function resolve(specifier, context, next) {+ if (specifier === "./sidebar-organization-store") return next(specifier + ".ts", context);+ return next(specifier, context);+ }`;+ register(`data:text/javascript,${encodeURIComponent(resolver)}`);+ const { removeCustomSectionWithUndo } = await import("../src/features/chat/stores/remove-custom-section.ts");+ resetStore();+ const store = useSidebarOrganizationStore.getState();+ const id = store.createCustomSection("Reading")!;+ store.setPagesSection(["pg"], id);+ const section = useSidebarOrganizationStore.getState().customSections.find((s) => s.id === id)!;+ const undo = removeCustomSectionWithUndo(section);+ assert.deepEqual({ ...useSidebarOrganizationStore.getState().sectionByPageId }, {});+ undo();+ assert.deepEqual({ ...useSidebarOrganizationStore.getState().sectionByPageId }, { pg: id });+});diff --git a/studio/frontend/tests/sidebar-row-drag.test.ts b/studio/frontend/tests/sidebar-row-drag.test.tsindex 2985c8b8c50..3ecc5400b0c 100644--- a/studio/frontend/tests/sidebar-row-drag.test.ts+++ b/studio/frontend/tests/sidebar-row-drag.test.ts@@ -70,6 +70,7 @@ function context(pinnedProjectIds: new Set(["work"]),sectionByChatId: {},sectionByProjectId: {},+ sectionByPageId: {},sectionSort: () => "manual",orders: {pinned: ["work", "p1"],diff --git a/studio/frontend/tests/sidebar-row-menu-and-pinned-folders.test.ts b/studio/frontend/tests/sidebar-row-menu-and-pinned-folders.test.tsindex 096c5ca5df6..e53599f3ea1 100644--- a/studio/frontend/tests/sidebar-row-menu-and-pinned-folders.test.ts+++ b/studio/frontend/tests/sidebar-row-menu-and-pinned-folders.test.ts@@ -278,10 +278,11 @@ test("the walk reads the rows in the order Pinned draws them", () => {["folder-1", "folder-2", "pin-1", "proj-1", "recent-1"],);// The sidebar publishes Pinned in its drawn order, folders and chats interleaved with each open- // folder's chats under its row, and leaves the section's own chats to projectItems.+ // folder's chats under its row (pinned pages have none), and leaves the section's own chats to+ // projectItems.assert.match(APP_SIDEBAR,- /const pinnedSectionChatItems = useMemo\(\n\s*\(\) =>\n\s*chatListsOnScreen && pinnedOpen\n\s*\? pinnedRows\.flatMap\(\(row\) =>\n\s*row\.kind === "project"\n\s*\? folderChatItems\(true, \[row\.project\]\)\n\s*: \[row\.item\],/,+ /const pinnedSectionChatItems = useMemo\(\n\s*\(\) =>\n\s*chatListsOnScreen && pinnedOpen\n\s*\? pinnedRows\.flatMap\(\(row\) =>\n\s*row\.kind === "project"\n\s*\? folderChatItems\(true, \[row\.project\]\)\n\s*: row\.kind === "chat"\n\s*\? \[row\.item\]\n\s*: \[\],/,);// The walk reads pinnedItems then projectItems, so the two are every section above Recents in// the order the user dragged them into, split at Pinned.