Skip to content

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.

Studio: sort projects in the sidebar and show pinned chats once (#11988)

Michael Han6edd350a1252
diff --git a/studio/frontend/src/components/app-sidebar.tsx b/studio/frontend/src/components/app-sidebar.tsx
index 7975779bd00..1d0e5e13b0a 100644
--- a/studio/frontend/src/components/app-sidebar.tsx
+++ b/studio/frontend/src/components/app-sidebar.tsx
@@ -176,6 +176,7 @@ import {
RECENTS_ORDER_SCOPE,
type SidebarChatSort,
type SidebarOrganizeBy,
+ type SidebarProjectSort,
type ProjectRecord,
type SidebarItem,
type ChatNavigationState,
@@ -367,8 +368,8 @@ const DROP_INTO_HEADER_CUE =
// The sort a list is on and its setter: a reorder switches a sorted list to Manual, or the
// sort would undo the drop.
type RowSort = {
- value: SidebarChatSort;
- set: (next: SidebarChatSort) => void;
+ value: SidebarChatSort | SidebarProjectSort;
+ set: (next: "manual") => void;
};
// The list a chat row is rendered in: its ids, for shift-click ranges and for the order a drag
// rewrites; the sort a drop switches to Manual; and, where the list is a folder's or Recents',
@@ -457,6 +458,15 @@ const CHAT_SORT_OPTIONS: Array<{
{ value: "updated", key: "shell.organize.lastUpdated" },
{ value: "manual", key: "shell.organize.manualOrder" },
];
+const PROJECT_SORT_OPTIONS: Array<{
+ value: SidebarProjectSort;
+ key: TranslationKey;
+}> = [
+ { value: "updated", key: "shell.organize.lastUpdated" },
+ { value: "name", key: "shell.organize.name" },
+ { value: "created", key: "shell.organize.dateCreated" },
+ { value: "manual", key: "shell.organize.manualOrder" },
+];
const ORGANIZE_OPTIONS: Array<{
value: SidebarOrganizeBy;
key: TranslationKey;
@@ -1105,6 +1115,8 @@ export function AppSidebar() {
const setOrganizeBy = useSidebarOrganizationStore((s) => s.setOrganizeBy);
const setChatSort = useSidebarOrganizationStore((s) => s.setChatSort);
const setPinnedSort = useSidebarOrganizationStore((s) => s.setPinnedSort);
+ const projectSort = useSidebarOrganizationStore((s) => s.projectSort);
+ const setProjectSort = useSidebarOrganizationStore((s) => s.setProjectSort);
const setManualOrder = useSidebarOrganizationStore((s) => s.setManualOrder);
// 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
@@ -1127,15 +1139,14 @@ export function AppSidebar() {
() => new Set(pinnedProjectIds),
[pinnedProjectIds],
);
- // Pinned chats, in pin order. A pinned project chat also stays in its folder.
+ // Pinned chats, in pin order. A pinned project chat shows here only.
const pinnedChatItems = useMemo(() => {
const byId = new Map(allChatItems.map((item) => [item.id, item]));
return pinnedIds
.map((id) => byId.get(id))
.filter((item): item is SidebarItem => Boolean(item));
}, [allChatItems, pinnedIds]);
- // Chats per project, newest first. Pinned ones stay: a chat belongs to its
- // project either way, and these rows are mirrored in Recents regardless.
+ // Chats per project, newest first. Pinned ones included, as they still count as activity.
const chatsByProjectId = useMemo(() => {
const map = new Map<string, SidebarItem[]>();
for (const item of allChatItems) {
@@ -1177,13 +1188,17 @@ export function AppSidebar() {
};
const rest = projects
.filter((p) => !pinnedProjectIdSet.has(p.id))
- .sort((a, b) => lastActivityAt(b) - lastActivityAt(a));
- return applyManualOrder(
- rest,
- manualOrder[PROJECT_ORDER_SCOPE],
- (project) => project.id,
- );
- }, [projects, pinnedProjectIdSet, manualOrder, chatsByProjectId]);
+ .sort((a, b) =>
+ projectSort === "name"
+ ? a.name.localeCompare(b.name, undefined, { numeric: true, sensitivity: "base" })
+ : projectSort === "created"
+ ? b.createdAt - a.createdAt
+ : lastActivityAt(b) - lastActivityAt(a),
+ );
+ return projectSort === "manual"
+ ? applyManualOrder(rest, manualOrder[PROJECT_ORDER_SCOPE], (project) => project.id)
+ : rest;
+ }, [projects, pinnedProjectIdSet, manualOrder, chatsByProjectId, projectSort]);
// Memoised for its identity, not for the slice. It feeds the rendered-row set the selection guard
// depends on, and that effect sets state: React re-renders once to find the bail-out, which would
// rebuild this array and schedule the effect again, without end.
@@ -1353,11 +1368,15 @@ export function AppSidebar() {
for (const [projectId, items] of chatsByProjectId) {
map.set(
projectId,
- sortChatItems(items, projectOrderScope(projectId), chatSort),
+ sortChatItems(
+ items.filter((item) => !pinnedIdSet.has(item.id)),
+ projectOrderScope(projectId),
+ chatSort,
+ ),
);
}
return map;
- }, [chatsByProjectId, sortChatItems, chatSort]);
+ }, [chatsByProjectId, sortChatItems, chatSort, pinnedIdSet]);
// One id array per list, shared by every row in it. Built per row, these
// would be N arrays of length N on each render.
const recentRowIds = useMemo(
@@ -1872,6 +1891,7 @@ export function AppSidebar() {
organizeBy,
chatSort,
pinnedSort,
+ projectSort,
pinnedChatIds: pinnedIdSet,
pinnedProjectIds: pinnedProjectIdSet,
orders: {
@@ -1885,6 +1905,7 @@ export function AppSidebar() {
organizeBy,
chatSort,
pinnedSort,
+ projectSort,
pinnedIdSet,
pinnedProjectIdSet,
pinnedRowIds,
@@ -1956,6 +1977,10 @@ export function AppSidebar() {
setPinnedSort("manual");
toast.info(t("shell.organize.switchedToManual"));
}
+ if (effects.switchSort === "projects") {
+ setProjectSort("manual");
+ toast.info(t("shell.organize.switchedToManual"));
+ }
};
const move = effects.moveChat;
if (!move) {
@@ -3112,6 +3137,7 @@ export function AppSidebar() {
sortValue: SidebarChatSort;
onSortChange: (next: SidebarChatSort) => void;
includeOrganize?: boolean;
+ includeProjectSort?: boolean;
}) {
return (
<NonModalDropdownMenu
@@ -3153,6 +3179,25 @@ export function AppSidebar() {
</DropdownMenuRadioGroup>
</>
)}
+ {options.includeProjectSort && (
+ <>
+ <DropdownMenuLabel>{t("shell.organize.sortProjectsBy")}</DropdownMenuLabel>
+ <DropdownMenuRadioGroup
+ value={projectSort}
+ onValueChange={(value) => setProjectSort(value as SidebarProjectSort)}
+ >
+ {PROJECT_SORT_OPTIONS.map((option) => (
+ <DropdownMenuRadioItem
+ key={option.value}
+ value={option.value}
+ className={menuRadioItemClass}
+ >
+ {t(option.key)}
+ </DropdownMenuRadioItem>
+ ))}
+ </DropdownMenuRadioGroup>
+ </>
+ )}
<DropdownMenuLabel>{options.sortLabel}</DropdownMenuLabel>
<DropdownMenuRadioGroup
value={options.sortValue}
@@ -4572,6 +4617,7 @@ export function AppSidebar() {
{renderSidebarHeaderMenu({
ariaLabel: t("shell.organize.organizeProjects"),
includeOrganize: true,
+ includeProjectSort: true,
sortLabel: t("shell.organize.sortChatsBy"),
sortValue: chatSort,
onSortChange: setChatSort,
@@ -4593,6 +4639,7 @@ export function AppSidebar() {
scope: PROJECT_ORDER_SCOPE,
orderedIds: projectRowIds,
section: "projects",
+ sort: { value: projectSort, set: setProjectSort },
}),
)}
{/* Every project is pinned, so the section is drawn with nothing in it. The
diff --git a/studio/frontend/src/features/chat/index.ts b/studio/frontend/src/features/chat/index.ts
index e62f0066705..d6a54b991f7 100644
--- a/studio/frontend/src/features/chat/index.ts
+++ b/studio/frontend/src/features/chat/index.ts
@@ -162,6 +162,7 @@ export {
} from "./stores/sidebar-organization-store";
export type {
SidebarChatSort,
+ SidebarProjectSort,
SidebarOrganizeBy,
} from "./stores/sidebar-organization-store";
export { useChatPreferencesStore } from "./stores/chat-preferences-store";
diff --git a/studio/frontend/src/features/chat/lib/sidebar-drag.ts b/studio/frontend/src/features/chat/lib/sidebar-drag.ts
index e2806ebd95f..081af12b03a 100644
--- a/studio/frontend/src/features/chat/lib/sidebar-drag.ts
+++ b/studio/frontend/src/features/chat/lib/sidebar-drag.ts
@@ -13,6 +13,7 @@ import {
projectOrderScope,
RECENTS_ORDER_SCOPE,
type SidebarChatSort,
+ type SidebarProjectSort,
type SidebarOrganizeBy,
} from "../stores/sidebar-organization-store.ts";
@@ -54,6 +55,7 @@ export interface SidebarDropContext {
organizeBy: SidebarOrganizeBy;
chatSort: SidebarChatSort;
pinnedSort: SidebarChatSort;
+ projectSort: SidebarProjectSort;
pinnedChatIds: ReadonlySet<string>;
pinnedProjectIds: ReadonlySet<string>;
/** Row ids per list, in drawn order. Pinned is one list of folders and chats. */
@@ -96,7 +98,7 @@ export interface SidebarDropEffects {
unpinProject?: string;
moveChat?: { chatId: string; projectId: string | null };
/** The list to switch to Manual, or its own rule undoes the drop. */
- switchSort?: "chats" | "pinned";
+ switchSort?: "chats" | "pinned" | "projects";
}
export interface SidebarDropPlan {
@@ -240,6 +242,7 @@ function planFolderDrop(
if (zone.section === "recents") return null;
if (zone.folderId === drag.id) return STAY;
const ids = ctx.orders.projects;
+ const switchSort = ctx.projectSort === "manual" ? undefined : "projects";
let target: { id: string; edge: DropEdge } | null = null;
if (zone.folderId) {
target =
@@ -255,7 +258,7 @@ function planFolderDrop(
return {
action: { kind: "reorder" },
cue: folderLine(PROJECT_ORDER_SCOPE, target.id, target.edge, zone),
- effects: { orders: [{ scope: PROJECT_ORDER_SCOPE, ids: next }] },
+ effects: { orders: [{ scope: PROJECT_ORDER_SCOPE, ids: next }], switchSort },
};
}
// Out of Pinned: unpinned, landing against a folder or last.
@@ -268,6 +271,7 @@ function planFolderDrop(
effects: {
orders: [{ scope: PROJECT_ORDER_SCOPE, ids: next }],
unpinProject: drag.id,
+ switchSort,
},
};
}
@@ -293,11 +297,11 @@ function planChatDrop(
const folderId = zone.folderId;
const sameFolder = drag.projectId === folderId;
if (fromPinnedList) {
- // A pinned folder keeps the pin; a folder under Projects takes it away.
- if (zone.section === "pinned") {
- return sameFolder ? STAY : moveChat(drag, zone, edge, ctx, folderId, false);
+ // Another pinned folder keeps the pin; a folder under Projects takes it away.
+ if (!sameFolder) {
+ return moveChat(drag, zone, edge, ctx, folderId, zone.section !== "pinned");
}
- if (!sameFolder) return moveChat(drag, zone, edge, ctx, folderId, true);
+ // Dropping it on its own folder unpins it.
const landing = landingIn(
projectOrderScope(folderId),
ctx.orders.projectChats(folderId),
diff --git a/studio/frontend/src/features/chat/stores/sidebar-organization-store.ts b/studio/frontend/src/features/chat/stores/sidebar-organization-store.ts
index a532b522c1c..b093548f7ed 100644
--- a/studio/frontend/src/features/chat/stores/sidebar-organization-store.ts
+++ b/studio/frontend/src/features/chat/stores/sidebar-organization-store.ts
@@ -8,6 +8,8 @@ import { persist } from "zustand/middleware";
export type SidebarOrganizeBy = "project" | "list";
/** How chat rows are ordered inside whichever list they land in. */
export type SidebarChatSort = "priority" | "updated" | "manual";
+/** How project folders are ordered in the Projects section. */
+export type SidebarProjectSort = "updated" | "name" | "created" | "manual";
// Defined in a leaf module and re-exported here so existing importers are unchanged: this
// store is in an import cycle, so a binding defined here would be readable too late. See
@@ -34,11 +36,14 @@ export interface SidebarOrganizationState {
// Pinned sorts on its own. Pin order already is a manual order, so it defaults to "manual" and
// stays put while the lists below re-sort.
pinnedSort: SidebarChatSort;
+ // Manual by default: the drag order, falling back to last activity.
+ projectSort: SidebarProjectSort;
/** Scope key -> row ids, in the order the user dragged them into. */
manualOrder: Record<string, string[]>;
setOrganizeBy: (value: SidebarOrganizeBy) => void;
setChatSort: (value: SidebarChatSort) => void;
setPinnedSort: (value: SidebarChatSort) => void;
+ setProjectSort: (value: SidebarProjectSort) => void;
setManualOrder: (scope: string, ids: string[]) => void;
}
@@ -160,10 +165,12 @@ export const useSidebarOrganizationStore = create<SidebarOrganizationState>()(
organizeBy: "project",
chatSort: "priority",
pinnedSort: "manual",
+ projectSort: "manual",
manualOrder: {},
setOrganizeBy: (value) => set({ organizeBy: value }),
setChatSort: (value) => set({ chatSort: value }),
setPinnedSort: (value) => set({ pinnedSort: value }),
+ setProjectSort: (value) => set({ projectSort: value }),
setManualOrder: (scope, ids) =>
set((state) => ({
manualOrder: { ...state.manualOrder, [scope]: ids },
@@ -187,6 +194,12 @@ export const useSidebarOrganizationStore = create<SidebarOrganizationState>()(
: fallback;
const chatSort = readSort(saved?.chatSort, "priority");
const pinnedSort = readSort(saved?.pinnedSort, "manual");
+ const projectSort: SidebarProjectSort =
+ saved?.projectSort === "updated" ||
+ saved?.projectSort === "name" ||
+ saved?.projectSort === "created"
+ ? saved.projectSort
+ : "manual";
const manualOrder: Record<string, string[]> = {};
if (saved?.manualOrder && typeof saved.manualOrder === "object") {
for (const [scope, ids] of Object.entries(saved.manualOrder)) {
@@ -202,6 +215,7 @@ export const useSidebarOrganizationStore = create<SidebarOrganizationState>()(
organizeBy,
chatSort,
pinnedSort,
+ projectSort,
manualOrder,
};
},
diff --git a/studio/frontend/src/i18n/locales/en.ts b/studio/frontend/src/i18n/locales/en.ts
index 285db413014..b7748490cfb 100644
--- a/studio/frontend/src/i18n/locales/en.ts
+++ b/studio/frontend/src/i18n/locales/en.ts
@@ -226,6 +226,9 @@ export const en = {
inOneList: "In one list",
sortChatsBy: "Sort chats by",
sortPinnedBy: "Sort pinned by",
+ sortProjectsBy: "Sort projects by",
+ name: "Name",
+ dateCreated: "Date created",
priority: "Priority",
lastUpdated: "Last updated",
manualOrder: "Manual order",
diff --git a/studio/frontend/tests/sidebar-organization-store.test.ts b/studio/frontend/tests/sidebar-organization-store.test.ts
index 3ccf0b9075f..6139609acb7 100644
--- a/studio/frontend/tests/sidebar-organization-store.test.ts
+++ b/studio/frontend/tests/sidebar-organization-store.test.ts
@@ -269,6 +269,17 @@ test("Pinned sorts independently of the chat lists", () => {
assert.equal(state.pinnedSort, "priority");
});
+test("Projects sort on their own, keeping the drag order by default", () => {
+ assert.equal(useSidebarOrganizationStore.getInitialState().projectSort, "manual");
+ const store = useSidebarOrganizationStore.getState();
+ store.setChatSort("priority");
+ store.setProjectSort("name");
+ const state = useSidebarOrganizationStore.getState();
+ assert.equal(state.projectSort, "name");
+ assert.equal(state.chatSort, "priority");
+ store.setProjectSort("manual");
+});
+
// Reset-all is the only in-app way back to the shipped sidebar layout, and it
// only removes the keys it lists, so an unlisted one survives the reload.
test("Reset all local preferences clears this key", async () => {
diff --git a/studio/frontend/tests/sidebar-row-drag.test.ts b/studio/frontend/tests/sidebar-row-drag.test.ts
index f3dcba09dae..2ff1f88e370 100644
--- a/studio/frontend/tests/sidebar-row-drag.test.ts
+++ b/studio/frontend/tests/sidebar-row-drag.test.ts
@@ -64,6 +64,7 @@ function context(
organizeBy: "project",
chatSort: "priority",
pinnedSort: "manual",
+ projectSort: "manual",
pinnedChatIds: new Set(["p1"]),
pinnedProjectIds: new Set(["work"]),
orders: {
@@ -171,6 +172,58 @@ test("a reorder in a sorted list switches it to Manual order", () => {
assert.equal(manual.effects.switchSort, undefined);
});
+// A folder drop switches a sorted Projects list to Manual.
+test("a folder reorder or unpin switches a sorted Projects list to Manual", () => {
+ // Alt + arrow and Move up/down take the same switch.
+ assert.ok(APP_SIDEBAR.includes("sort: { value: projectSort, set: setProjectSort }"));
+ const home = folder("home", "projects", PROJECT_ORDER_SCOPE);
+ const miscRow = folderRow("projects", PROJECT_ORDER_SCOPE, "misc");
+ const reorder = plannedDrop(
+ planSidebarDrop(home, miscRow, "bottom", context({ projectSort: "name" })),
+ );
+ assert.equal(reorder.action.kind, "reorder");
+ assert.equal(reorder.effects.switchSort, "projects");
+ const unpin = plannedDrop(
+ planSidebarDrop(
+ folder("work", "pinned", PINNED_ORDER_SCOPE),
+ miscRow,
+ "bottom",
+ context({ projectSort: "created" }),
+ ),
+ );
+ assert.equal(unpin.action.kind, "unpin");
+ assert.equal(unpin.effects.switchSort, "projects");
+ const manual = plannedDrop(planSidebarDrop(home, miscRow, "bottom", context()));
+ assert.equal(manual.effects.switchSort, undefined);
+});
+
+// A pinned project chat shows in Pinned only; its own folder unpins it.
+test("a pinned chat is listed once and drops back into its folder unpinned", () => {
+ assert.ok(
+ APP_SIDEBAR.includes("items.filter((item) => !pinnedIdSet.has(item.id))"),
+ "a folder still lists its pinned chats",
+ );
+ const ctx = context({
+ pinnedChatIds: new Set(["p1", "c1"]),
+ orders: {
+ ...context().orders,
+ pinned: ["work", "c1", "p1"],
+ projectChats: (projectId) =>
+ ({ work: ["c2"], home: ["c3"], misc: [] })[projectId] ?? [],
+ },
+ });
+ const drag = chat("c1", "pinned", PINNED_ORDER_SCOPE, "work");
+ for (const zone of [
+ folderRow("pinned", PINNED_ORDER_SCOPE, "work"),
+ chatRow("pinned", projectOrderScope("work"), "c2", "work"),
+ ]) {
+ const plan = plannedDrop(planSidebarDrop(drag, zone, "bottom", ctx));
+ assert.equal(plan.action.kind, "unpin");
+ assert.equal(plan.effects.unpinChat, "c1");
+ assert.equal(plan.effects.moveChat, undefined);
+ }
+});
+
// An edge the row is already on is not a move, and a line there would promise one. The spot
// still answers, with STAY, so the section around it does not offer its last slot instead.
test("an edge that moves nothing stays, and still claims the drag", () => {