mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-11-17 00:20:51 +00:00
feat: fold sidebar AI chats and sessions inactive for over a week (#12314)
* feat: fold sidebar AI chats and sessions inactive for over a week Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: fold sidebar sessions only when no activity cutoff is picked Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * refactor: render the sidebar show-older row with Button Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat: persist the sidebar show-older state Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
c2f1cf39c1
commit
466885fd26
@@ -61,6 +61,9 @@
|
||||
import UnreadCountBadge from '$lib/components/common/badge/UnreadCountBadge.svelte'
|
||||
import { buildWorkspaceHierarchy } from '$lib/utils/workspaceHierarchy'
|
||||
import MenuButton, { sidebarClasses } from '$lib/components/sidebar/MenuButton.svelte'
|
||||
import SidebarShowOlder, {
|
||||
SIDEBAR_RECENT_MS
|
||||
} from '$lib/components/sidebar/SidebarShowOlder.svelte'
|
||||
import DropdownV2 from '$lib/components/DropdownV2.svelte'
|
||||
import { userStore, userWorkspaces, workspaceStore } from '$lib/stores'
|
||||
import { workspaceIsFork } from '$lib/utils/workspaceHierarchy'
|
||||
@@ -175,10 +178,9 @@
|
||||
)
|
||||
}
|
||||
|
||||
// Flat list passing the archive + scope filters. Grouping for display happens
|
||||
// in `sessionGroups`; this flat view drives the runtime effect, the unread
|
||||
// total, and keyboard navigation.
|
||||
const visibleSessions = $derived(
|
||||
// Every session passing the archive + scope filters, the ones folded under "Show older"
|
||||
// included.
|
||||
const filteredSessions = $derived(
|
||||
sessionState.sessions.filter((s) => {
|
||||
// A draft Home's composer holds becomes a session when its first send starts, typed
|
||||
// or not. Unsent drafts opened onto an item stay listed: the row is their only way
|
||||
@@ -198,6 +200,25 @@
|
||||
})
|
||||
)
|
||||
|
||||
// With no activity cutoff picked, sessions inactive for over a week fold under a "Show older"
|
||||
// row, except the one on screen. A picked cutoff is the reader's own choice and folds nothing.
|
||||
const showOlder = useLocalStorageValue('windmill_sessions_show_older', false, 'boolean')
|
||||
const olderIds = $derived.by(() => {
|
||||
if (lastActivityDays.val > 0) return new Set<string>()
|
||||
const cutoff = clock - SIDEBAR_RECENT_MS
|
||||
return new Set(
|
||||
filteredSessions
|
||||
.filter((s) => s.id !== activeRowId && sessionLastActivityAt(s) < cutoff)
|
||||
.map((s) => s.id)
|
||||
)
|
||||
})
|
||||
|
||||
// The rows listed. Grouping for display happens in `sessionGroups`; this flat view drives
|
||||
// the runtime effect, the unread total, and keyboard navigation.
|
||||
const visibleSessions = $derived(
|
||||
showOlder.val ? filteredSessions : filteredSessions.filter((s) => !olderIds.has(s.id))
|
||||
)
|
||||
|
||||
// Sessions grouped by workspace family for display, each group by its last turn
|
||||
// start or end, latest first. Family order follows its latest session and is NOT tied
|
||||
// to the current workspace: pinning the active family first reshuffled the
|
||||
@@ -384,7 +405,7 @@
|
||||
// sessions load, the list is empty for every reader, and the fold is a
|
||||
// layout they chose to keep.
|
||||
$effect(() => {
|
||||
if (sessionState.hydrated && visibleSessions.length === 0 && sectionCollapsed.val) {
|
||||
if (sessionState.hydrated && filteredSessions.length === 0 && sectionCollapsed.val) {
|
||||
sectionCollapsed.val = false
|
||||
}
|
||||
})
|
||||
@@ -785,7 +806,7 @@
|
||||
icon={MessageSquare}
|
||||
folded={sectionCollapsed.val}
|
||||
onToggle={() => (sectionCollapsed.val = !sectionCollapsed.val)}
|
||||
disabled={visibleSessions.length === 0}
|
||||
disabled={filteredSessions.length === 0}
|
||||
notify={totalUnread > 0}
|
||||
actions={sectionOptions}
|
||||
{isCollapsed}
|
||||
@@ -1132,6 +1153,15 @@
|
||||
{/each}
|
||||
{/if}
|
||||
</div>
|
||||
<!-- Outside the listbox, so arrow keys move through sessions only. -->
|
||||
{#if olderIds.size > 0}
|
||||
<SidebarShowOlder
|
||||
count={olderIds.size}
|
||||
expanded={showOlder.val}
|
||||
onToggle={() => (showOlder.val = !showOlder.val)}
|
||||
{rail}
|
||||
/>
|
||||
{/if}
|
||||
{#if selecting}
|
||||
<!-- Pinned to the bottom edge of whatever scrolls the list, the sidebar or the folded
|
||||
section's menu, while the rows scroll under it; z-10 keeps it above the sidebar's
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
import { useLocalStorageValue } from '$lib/svelte5Utils.svelte'
|
||||
import { agentOfChatPath } from '$lib/components/flows/conversations/agentEditorChat'
|
||||
import { sidebarClasses } from './MenuButton.svelte'
|
||||
import SidebarShowOlder, { SIDEBAR_RECENT_MS } from './SidebarShowOlder.svelte'
|
||||
|
||||
// The reader's own flow and agent chats, the ones a flow's or an agent's own page shows: the
|
||||
// editors' test chats stay with the editors.
|
||||
@@ -22,6 +23,8 @@
|
||||
'boolean'
|
||||
)
|
||||
|
||||
const showOlder = useLocalStorageValue('windmill_ai_chats_show_older', false, 'boolean')
|
||||
|
||||
// Tagged with its workspace: responses are not ordered, and a late one from the workspace
|
||||
// just left must not show here.
|
||||
const listing = resource(
|
||||
@@ -34,7 +37,11 @@
|
||||
kind: 'deployed',
|
||||
mine: true
|
||||
})
|
||||
return { ws, rows }
|
||||
// Listed newest `updated_at` first, which every new message bumps, so the chats active
|
||||
// in the window are a prefix of the page.
|
||||
const since = Date.now() - SIDEBAR_RECENT_MS
|
||||
const recent = rows.findIndex((c) => new Date(c.updated_at).getTime() < since)
|
||||
return { ws, rows, recent: recent === -1 ? rows.length : recent }
|
||||
}
|
||||
)
|
||||
// A chat is started on its flow's or agent's page, so it lists once the reader leaves one.
|
||||
@@ -43,8 +50,19 @@
|
||||
if (!left || left === to?.url.pathname) return
|
||||
if (left.startsWith('/flows/get/') || left.startsWith('/agents/get/')) listing.refetch()
|
||||
})
|
||||
const current = $derived(
|
||||
listing.current && listing.current.ws === $workspaceStore ? listing.current : undefined
|
||||
)
|
||||
const allRows = $derived(current?.rows ?? [])
|
||||
const openId = $derived(page.url.searchParams.get('conversation'))
|
||||
// The open chat always lists, however old.
|
||||
const rows = $derived(
|
||||
listing.current && listing.current.ws === $workspaceStore ? listing.current.rows : []
|
||||
showOlder.val || !current
|
||||
? allRows
|
||||
: allRows.filter((c, i) => i < current.recent || c.id === openId)
|
||||
)
|
||||
const olderCount = $derived(
|
||||
allRows.filter((c, i) => i >= (current?.recent ?? 0) && c.id !== openId).length
|
||||
)
|
||||
|
||||
function target(c: FlowConversation) {
|
||||
@@ -55,11 +73,9 @@
|
||||
href: `/${agent !== undefined ? 'agents' : 'flows'}/get/${agent ?? c.flow_path}?conversation=${c.id}`
|
||||
}
|
||||
}
|
||||
|
||||
const openId = $derived(page.url.searchParams.get('conversation'))
|
||||
</script>
|
||||
|
||||
{#if rows.length > 0}
|
||||
{#if allRows.length > 0}
|
||||
<SidebarSection
|
||||
title="AI chats"
|
||||
icon={MessagesSquare}
|
||||
@@ -95,6 +111,14 @@
|
||||
<span class={rail ? 'sr-only' : 'truncate'}>{c.title || 'Untitled chat'}</span>
|
||||
</a>
|
||||
{/each}
|
||||
{#if olderCount > 0}
|
||||
<SidebarShowOlder
|
||||
count={olderCount}
|
||||
expanded={showOlder.val}
|
||||
onToggle={() => (showOlder.val = !showOlder.val)}
|
||||
{rail}
|
||||
/>
|
||||
{/if}
|
||||
</div>
|
||||
{/snippet}
|
||||
</SidebarSection>
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
<script module lang="ts">
|
||||
/** How recent a sidebar list's activity must be to show without expanding its older rows. */
|
||||
export const SIDEBAR_RECENT_MS = 7 * 24 * 60 * 60 * 1000
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import { Ellipsis } from 'lucide-svelte'
|
||||
import { Button } from '$lib/components/common'
|
||||
|
||||
// The row under a sidebar list that reveals the rows inactive for over a week, and hides them
|
||||
// again.
|
||||
let {
|
||||
count,
|
||||
expanded,
|
||||
onToggle,
|
||||
rail = false
|
||||
}: { count: number; expanded: boolean; onToggle: () => void; rail?: boolean } = $props()
|
||||
|
||||
const label = $derived(expanded ? 'Show less' : `Show ${count} older`)
|
||||
</script>
|
||||
|
||||
<Button
|
||||
unifiedSize="xs"
|
||||
variant="subtle"
|
||||
startIcon={{ icon: Ellipsis }}
|
||||
iconOnly={rail}
|
||||
title={label}
|
||||
aria-label={label}
|
||||
aria-expanded={expanded}
|
||||
onClick={onToggle}
|
||||
btnClasses="justify-start px-2 font-normal text-tertiary hover:text-secondary"
|
||||
>
|
||||
{label}
|
||||
</Button>
|
||||
Reference in New Issue
Block a user