diff --git a/src/lib/components/chat/Placeholder/ChatList.svelte b/src/lib/components/chat/Placeholder/ChatList.svelte index 4baa27b18f..280821943e 100644 --- a/src/lib/components/chat/Placeholder/ChatList.svelte +++ b/src/lib/components/chat/Placeholder/ChatList.svelte @@ -50,6 +50,8 @@ export let onMove: (chat: WorkspaceChat, status: FolderStatus) => Promise; export let onPriority: (chat: WorkspaceChat, priority: FolderPriority) => Promise; export let onTagsChange: () => Promise; + export let collapsed: Record = {}; + export let onCollapse: (id: string) => void; // Same payload as the sidebar chat item, so a row can be dropped into split view // or onto the composer. @@ -60,7 +62,6 @@ event.dataTransfer.setData('application/x-open-webui-chat', chat.id); }; - let collapsed: Record = {}; let menuOpen: Record = {}; // Inline rename, like the sidebar chat item. @@ -161,7 +162,7 @@ aria-label={collapsed[group.id] ? $i18n.t('Expand {{name}}', { name: group.label }) : $i18n.t('Collapse {{name}}', { name: group.label })} - on:click={() => (collapsed = { ...collapsed, [group.id]: !collapsed[group.id] })} + on:click={() => onCollapse(group.id)} > Promise; export let onTagsChange: () => Promise; export let onAddStatus: (() => void) | null = null; + /** Saves a new column order; set only when columns are statuses. */ + export let onReorder: ((ids: string[]) => Promise) | null = null; + /** Swimlanes the user folded. */ + export let collapsed: Record = {}; + export let onCollapse: (id: string) => void; export let saving = ''; export let loading = false; export let loadingGroup = ''; let dragged: WorkspaceChat | null = null; let over = ''; - let collapsed: Record = {}; + + // Status columns move by their header, live like the statuses modal. + let moving = ''; + let order: string[] | null = null; + $: shownColumns = order + ? order.flatMap((id) => columns.filter((column) => column.id === id)) + : columns; + const movable = (column: BoardGroup) => !!onReorder && !!column.status; + function moveColumn(event: DragEvent, overId: string) { + if (!moving || !order) return false; + event.preventDefault(); + const target = columns.find((column) => column.id === overId); + if (overId === moving || !target || !movable(target)) return true; + const next = order.filter((id) => id !== moving); + next.splice(order.indexOf(overId), 0, moving); + order = next; + return true; + } + async function endMove(event: DragEvent) { + const ids = order; + moving = ''; + if ( + ids && + event.dataTransfer?.dropEffect !== 'none' && + ids.join() !== columns.map((column) => column.id).join() + ) + await onReorder?.(ids); + order = null; + } // Inline rename, like the list rows. let renaming = ''; @@ -117,7 +150,7 @@ const dropzone = (column: string, row: string | null) => ({ dragover: (event: DragEvent) => { - if (!dragged || !canDrop(column, row)) return; + if (moveColumn(event, column) || !dragged || !canDrop(column, row)) return; event.preventDefault(); over = cellKey(column, row); if (event.dataTransfer) @@ -164,7 +197,20 @@ {/snippet} {#snippet columnHeader(column: BoardGroup)} -
+ +
{ + moving = column.id; + order = columns.map((item) => item.id); + event.dataTransfer?.setData('text/plain', column.id); + if (event.dataTransfer) event.dataTransfer.effectAllowed = 'move'; + }} + on:dragend={endMove} + > {@render groupIcon(column)}

{column.label} @@ -354,12 +400,14 @@ class="scrollbar-hidden flex h-full min-h-0 gap-2 overflow-x-auto px-3 pt-1 pb-2" aria-label={$i18n.t('Conversation board')} > - {#each columns as column (column.id)} + {#each shownColumns as column (column.id)} {@const chats = column.page?.chats ?? []} {@const zone = dropzone(column.id, null)}
- {#each columns as column (column.id)} -
+ {#each shownColumns as column (column.id)} +
moveColumn(event, column.id)} + on:drop|preventDefault + > {@render columnHeader(column)}
{/each} @@ -414,7 +470,7 @@ aria-label={collapsed[row.id] ? $i18n.t('Expand {{name}}', { name: row.label }) : $i18n.t('Collapse {{name}}', { name: row.label })} - on:click={() => (collapsed = { ...collapsed, [row.id]: !collapsed[row.id] })} + on:click={() => onCollapse(row.id)} > - {#each columns as column (column.id)} + {#each shownColumns as column (column.id)} {@const chats = cellChats(column, row)} {@const zone = dropzone(column.id, row.id)}
- {#each columns as column (column.id)} + {#each shownColumns as column (column.id)}
{@render more(column)}
{/each}
diff --git a/src/lib/components/chat/Placeholder/FolderPlaceholder.svelte b/src/lib/components/chat/Placeholder/FolderPlaceholder.svelte index fce721dd79..343608fec3 100644 --- a/src/lib/components/chat/Placeholder/FolderPlaceholder.svelte +++ b/src/lib/components/chat/Placeholder/FolderPlaceholder.svelte @@ -22,6 +22,7 @@ NO_STATUS, NO_PRIORITY, statusDefs, + groupedStatusDefs, priorityDefs, priorityKey, isChatUnread, @@ -261,6 +262,29 @@ } }; + // Folded groups are remembered per folder and grouping. + const COLLAPSED = 'folder-workspace-collapsed'; + let collapsed: Record> = (() => { + try { + return JSON.parse(localStorage.getItem(COLLAPSED) ?? '{}') ?? {}; + } catch { + return {}; + } + })(); + const toggleCollapsed = (by: GroupBy, id: string) => { + if (!folder?.id) return; + const key = `${folder.id}:${by}`; + const { [id]: folded, ...rest } = collapsed[key] ?? {}; + const next = folded ? rest : { ...rest, [id]: true }; + const { [key]: _, ...others } = collapsed; + collapsed = Object.keys(next).length ? { ...others, [key]: next } : others; + try { + localStorage.setItem(COLLAPSED, JSON.stringify(collapsed)); + } catch { + /* Storage is optional. */ + } + }; + // Built-in plus folder-defined statuses, shared with rows, cards and menus. let defs: StatusDef[] = statusDefs(null, (key) => key); const defsStore = writable(defs); @@ -300,17 +324,31 @@ } } - async function saveStatuses(custom: CustomStatus[]) { + // A reorder changes no chat, so it skips the reload. + // Saved in order; a `{ id: NO_STATUS }` entry places "No status" (see groupedStatusDefs). + type StatusEntry = CustomStatus | { id: typeof NO_STATUS }; + async function saveStatuses(statuses: StatusEntry[], reload = true) { if (!folder?.id) return; const folderId = folder.id; + // The modal edits only the folder's own statuses: keep "No status" after the one it followed. + if (!statuses.some((item) => item.id === NO_STATUS)) { + const order = groupedStatusDefs(folder.meta, (key) => key).map((item) => item.id); + const before = order.slice(0, order.indexOf(NO_STATUS)); + if (before.length < order.length - 1) { + const anchor = before.reverse().find((id) => statuses.some((item) => item.id === id)); + const at = anchor ? statuses.findIndex((item) => item.id === anchor) + 1 : 0; + statuses = [...statuses.slice(0, at), { id: NO_STATUS }, ...statuses.slice(at)]; + } + } const updated = await updateFolderById(localStorage.token, folderId, { - meta: { statuses: custom } + meta: { statuses } }); if (!updated) return; updateFolderDetails(folderId, updated); selectedFolder.update((current) => current?.id === folderId ? { ...current, ...updated } : current ); + if (!reload) return; const valid = new Set(statusDefs(updated.meta, (key) => key).map((item) => item.id)); statusFilter = statusFilter.filter((id) => valid.has(id)); markFolderChatsDirty(folderId); @@ -318,6 +356,25 @@ await load(); } + // Board columns dragged into a new order; statuses the filter hides keep their places. + async function reorderStatuses(ids: string[]) { + const order = groupedStatusDefs(folder?.meta, (key) => key); + const moved = ids.filter((id) => order.some((item) => item.id === id)); + const byId = new Map(order.map((item) => [item.id, item])); + let index = 0; + const next = order.map((item) => (moved.includes(item.id) ? byId.get(moved[index++])! : item)); + try { + await saveStatuses( + next.map(({ id, name, glyph, color, icon }) => + id === NO_STATUS ? { id: NO_STATUS } : { id, name, glyph, color, icon } + ), + false + ); + } catch (error) { + toast.error(String(error)); + } + } + let currentFolderId = ''; let section: HTMLElement; let searchInput: HTMLInputElement; @@ -371,14 +428,9 @@ _deps?: unknown ): Group[] { if (by === 'status') { - const defined = statusDefs(folder?.meta, t).filter( - (status) => !statusFilter.length || statusFilter.includes(status.id) - ); - // Grouped views put "No status" last, like "Untagged" and "Read". - return [ - ...defined.filter((status) => status.id !== NO_STATUS), - ...defined.filter((status) => status.id === NO_STATUS) - ].map((status) => ({ id: status.id, label: status.name, status: status.id })); + return groupedStatusDefs(folder?.meta, t) + .filter((status) => !statusFilter.length || statusFilter.includes(status.id)) + .map((status) => ({ id: status.id, label: status.name, status: status.id })); } if (by === 'priority') { const defined = priorityDefs(t).filter( @@ -1811,6 +1863,7 @@ {:else if view === 'board'} (showStatuses = true)} + onReorder={readOnly || columnsBy !== 'status' ? null : reorderStatuses} columns={boardColumns} rows={boardRows} {rowOf} @@ -1824,6 +1877,8 @@ onPriority={prioritize} onDrop={update} onTagsChange={changed} + collapsed={collapsed[`${folder?.id}:${rowsBy}`] ?? {}} + onCollapse={(id) => toggleCollapsed(rowsBy, id)} /> {:else} toggleCollapsed(grouping, id)} /> {/if}
diff --git a/src/lib/utils/folders.ts b/src/lib/utils/folders.ts index a44432f4b8..a685fb8276 100644 --- a/src/lib/utils/folders.ts +++ b/src/lib/utils/folders.ts @@ -58,6 +58,20 @@ export const statusDefs = ( ...customStatuses(meta).map((item) => ({ ...item, custom: true })) ]; +// Grouped views follow the folder's order; a `{ id: 'none' }` entry in meta.statuses places +// "No status", which otherwise goes last. The server already skips that entry. +export const groupedStatusDefs = ( + meta: { statuses?: unknown } | null | undefined, + t: (key: string) => string +): StatusDef[] => { + const [none, ...custom] = statusDefs(meta, t); + const statuses = Array.isArray(meta?.statuses) ? meta.statuses : []; + const marker = statuses.findIndex((item) => item?.id === NO_STATUS); + const at = + marker < 0 ? custom.length : customStatuses({ statuses: statuses.slice(0, marker) }).length; + return [...custom.slice(0, at), none, ...custom.slice(at)]; +}; + // Priorities are fixed, most urgent first. A chat's priority is null when it has none; // 'none' is only the key for that group, column and filter, like NO_STATUS. export const NO_PRIORITY = 'none';