This commit is contained in:
Timothy Jaeryang Baek committed 2026-11-26 03:20:54 +04:00
1 parent d6812c851b
commit fdfcb03a0a
4 files changed
+151 -23

No files matched your search

@@ -50,6 +50,8 @@
export let onMove: (chat: WorkspaceChat, status: FolderStatus) => Promise<void>;
export let onPriority: (chat: WorkspaceChat, priority: FolderPriority) => Promise<void>;
export let onTagsChange: () => Promise<void>;
export let collapsed: Record<string, boolean> = {};
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<string, boolean> = {};
let menuOpen: Record<string, boolean> = {};
// 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)}
>
<ChevronRight
className="size-3 transition-transform {collapsed[group.id] ? '' : 'rotate-90'}"
@@ -62,13 +62,46 @@
export let onDrop: (chat: WorkspaceChat, changes: [Field, string][]) => Promise<void>;
export let onTagsChange: () => Promise<void>;
export let onAddStatus: (() => void) | null = null;
/** Saves a new column order; set only when columns are statuses. */
export let onReorder: ((ids: string[]) => Promise<void>) | null = null;
/** Swimlanes the user folded. */
export let collapsed: Record<string, boolean> = {};
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<string, boolean> = {};
// 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)}
<header class="flex h-9 shrink-0 items-center gap-2 px-3">
<!-- svelte-ignore a11y_no_static_element_interactions -->
<header
class="flex h-9 shrink-0 items-center gap-2 px-3 {movable(column)
? 'cursor-grab active:cursor-grabbing'
: ''}"
draggable={movable(column) && !saving && !loading}
on:dragstart={(event) => {
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)}
<h3 class="min-w-0 truncate text-xs text-base-700 dark:text-base-200">
{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)}
<section
class="flex min-h-0 w-72 min-w-64 flex-1 flex-col rounded-2xl transition-colors {over ===
cellKey(column.id, null)
class="flex min-h-0 w-72 min-w-64 flex-1 flex-col rounded-2xl transition-colors {moving ===
column.id
? 'opacity-40'
: ''} {over === cellKey(column.id, null)
? 'bg-base-100 ring-1 ring-base-200 dark:bg-base-850 dark:ring-base-800'
: 'bg-base-50/80 dark:bg-base-850/40'}"
aria-label={column.label}
@@ -395,8 +443,16 @@
<div
class="sticky top-0 z-[2] flex gap-2 bg-base-0/80 pb-1 backdrop-blur-md dark:bg-base-900/80"
>
{#each columns as column (column.id)}
<div class="w-72 shrink-0 rounded-2xl bg-base-50/80 dark:bg-base-850/40">
{#each shownColumns as column (column.id)}
<div
class="w-72 shrink-0 rounded-2xl bg-base-50/80 dark:bg-base-850/40 {moving === column.id
? 'opacity-40'
: ''}"
role="group"
aria-label={column.label}
on:dragover={(event) => moveColumn(event, column.id)}
on:drop|preventDefault
>
{@render columnHeader(column)}
</div>
{/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)}
>
<ChevronRight
className="size-3 transition-transform {collapsed[row.id] ? '' : 'rotate-90'}"
@@ -428,7 +484,7 @@
{#if !collapsed[row.id]}
<div class="flex gap-2 pb-2">
{#each columns as column (column.id)}
{#each shownColumns as column (column.id)}
{@const chats = cellChats(column, row)}
{@const zone = dropzone(column.id, row.id)}
<div
@@ -456,7 +512,7 @@
{/each}
<div class="flex gap-2">
{#each columns as column (column.id)}
{#each shownColumns as column (column.id)}
<div class="w-72 shrink-0">{@render more(column)}</div>
{/each}
</div>
@@ -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<string, Record<string, boolean>> = (() => {
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<StatusDef[]>(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'}
<FolderBoard
onAddStatus={readOnly || columnsBy !== 'status' ? null : () => (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}
<ChatList
@@ -1836,6 +1891,8 @@
onMove={move}
onPriority={prioritize}
onTagsChange={changed}
collapsed={collapsed[`${folder?.id}:${grouping}`] ?? {}}
onCollapse={(id) => toggleCollapsed(grouping, id)}
/>
{/if}
</div>
+14
View File
@@ -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';