Repository navigation
feat(ui): collapse scheduled job sessions into accordion in chat history #11265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
b03fd5f
a077680
4a0e78a
b56f75e
f885caf
3838283
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,9 @@ import { | |
| LoaderCircle, | ||
| ExternalLink, | ||
| Copy, | ||
| ChevronDown, | ||
| ChevronRight, | ||
| Clock, | ||
| } from 'lucide-react'; | ||
| import { Card } from '../ui/card'; | ||
| import { Button } from '../ui/button'; | ||
|
|
@@ -163,6 +166,14 @@ const i18n = defineMessages({ | |
| 'Anyone with this link can fetch and decrypt the session. Treat it like a secret.', | ||
| }, | ||
| close: { id: 'sessions.close', defaultMessage: 'Close' }, | ||
| scheduledJobs: { | ||
| id: 'sessions.scheduledJobs', | ||
| defaultMessage: 'Scheduled Jobs', | ||
| }, | ||
| scheduledJobsCount: { | ||
| id: 'sessions.scheduledJobsCount', | ||
| defaultMessage: '{count} {count, plural, one {job} other {jobs}}', | ||
| }, | ||
| }); | ||
|
|
||
| interface EditSessionModalProps { | ||
|
|
@@ -314,6 +325,7 @@ const SessionListView: React.FC<SessionListViewProps> = React.memo(({ onSelectSe | |
| const [error, setError] = useState<string | null>(null); | ||
|
|
||
| const [visibleGroupsCount, setVisibleGroupsCount] = useState(15); | ||
| const [isScheduledExpanded, setIsScheduledExpanded] = useState(false); | ||
|
|
||
| // Edit modal state | ||
| const [showEditModal, setShowEditModal] = useState(false); | ||
|
|
@@ -343,9 +355,20 @@ const SessionListView: React.FC<SessionListViewProps> = React.memo(({ onSelectSe | |
|
|
||
| const fileInputRef = useRef<HTMLInputElement>(null); | ||
|
|
||
| const memoizedAllDateGroups = useMemo(() => { | ||
| if (sessions.length > 0) { | ||
| return groupSessionsByDate(sessions); | ||
| } | ||
| return []; | ||
| }, [sessions]); | ||
|
|
||
| const activeDateGroups = useMemo(() => { | ||
| return debouncedSearchTerm.length > 0 ? memoizedAllDateGroups : dateGroups; | ||
| }, [debouncedSearchTerm, memoizedAllDateGroups, dateGroups]); | ||
|
|
||
| const visibleDateGroups = useMemo(() => { | ||
| return dateGroups.slice(0, visibleGroupsCount); | ||
| }, [dateGroups, visibleGroupsCount]); | ||
| return activeDateGroups.slice(0, visibleGroupsCount); | ||
| }, [activeDateGroups, visibleGroupsCount]); | ||
|
|
||
| const previousSearchTermRef = useRef(''); | ||
| useEffect(() => { | ||
|
|
@@ -354,11 +377,11 @@ const SessionListView: React.FC<SessionListViewProps> = React.memo(({ onSelectSe | |
| previousSearchTermRef.current = debouncedSearchTerm; | ||
|
|
||
| if (isSearching) { | ||
| setVisibleGroupsCount(dateGroups.length); | ||
| setVisibleGroupsCount(memoizedAllDateGroups.length); | ||
| } else if (wasSearching) { | ||
| setVisibleGroupsCount(15); | ||
| } | ||
| }, [debouncedSearchTerm, dateGroups.length]); | ||
| }, [debouncedSearchTerm, memoizedAllDateGroups.length]); | ||
|
|
||
| const loadRemainingSessionPages = useCallback( | ||
| async (initialCursor: string, loadId: number, keyword?: string) => { | ||
|
|
@@ -437,11 +460,11 @@ const SessionListView: React.FC<SessionListViewProps> = React.memo(({ onSelectSe | |
|
|
||
| if (scrollHeight - scrollTop - clientHeight >= threshold) return; | ||
|
|
||
| if (visibleGroupsCount < dateGroups.length) { | ||
| setVisibleGroupsCount((prev) => Math.min(prev + 5, dateGroups.length)); | ||
| if (visibleGroupsCount < activeDateGroups.length) { | ||
| setVisibleGroupsCount((prev) => Math.min(prev + 5, activeDateGroups.length)); | ||
| } | ||
| }, | ||
| [visibleGroupsCount, dateGroups.length] | ||
| [visibleGroupsCount, activeDateGroups.length] | ||
| ); | ||
|
|
||
| useEffect(() => { | ||
|
|
@@ -474,13 +497,34 @@ const SessionListView: React.FC<SessionListViewProps> = React.memo(({ onSelectSe | |
| return () => void 0; | ||
| }, [isLoading, showSkeleton]); | ||
|
|
||
| // Split sessions into human-created and scheduled job sessions | ||
| const { humanSessions, scheduledSessions } = useMemo(() => { | ||
| const human: SessionListItem[] = []; | ||
| const scheduled: SessionListItem[] = []; | ||
| for (const s of sessions) { | ||
| if (s.sessionType === 'scheduled') { | ||
| scheduled.push(s); | ||
| } else { | ||
| human.push(s); | ||
| } | ||
| } | ||
| return { humanSessions: human, scheduledSessions: scheduled }; | ||
| }, [sessions]); | ||
|
|
||
| // Memoize date groups calculation to prevent unnecessary recalculations | ||
| const memoizedDateGroups = useMemo(() => { | ||
| if (sessions.length > 0) { | ||
| return groupSessionsByDate(sessions); | ||
| if (humanSessions.length > 0) { | ||
| return groupSessionsByDate(humanSessions); | ||
| } | ||
| return []; | ||
| }, [sessions]); | ||
| }, [humanSessions]); | ||
|
|
||
| const memoizedScheduledDateGroups = useMemo(() => { | ||
| if (scheduledSessions.length > 0) { | ||
| return groupSessionsByDate(scheduledSessions); | ||
| } | ||
| return []; | ||
| }, [scheduledSessions]); | ||
|
|
||
| // Update date groups when filtered sessions change | ||
| useEffect(() => { | ||
|
|
@@ -972,6 +1016,57 @@ const SessionListView: React.FC<SessionListViewProps> = React.memo(({ onSelectSe | |
| </div> | ||
| ))} | ||
|
|
||
| {!debouncedSearchTerm && memoizedScheduledDateGroups.length > 0 && ( | ||
| <div className="space-y-4"> | ||
| <button | ||
| onClick={() => setIsScheduledExpanded((v) => !v)} | ||
| className="sticky top-0 z-10 w-full flex items-center justify-between bg-background-primary/95 backdrop-blur-sm py-2 px-1 rounded-lg hover:bg-background-secondary transition-colors cursor-pointer" | ||
| > | ||
| <div className="flex items-center gap-2"> | ||
| <Clock className="w-4 h-4 text-text-secondary" /> | ||
| <h2 className="text-text-secondary font-medium"> | ||
| {intl.formatMessage(i18n.scheduledJobs)} | ||
| </h2> | ||
| <span className="text-xs text-text-tertiary bg-background-secondary px-2 py-0.5 rounded-full"> | ||
| {intl.formatMessage(i18n.scheduledJobsCount, { count: scheduledSessions.length })} | ||
| </span> | ||
| </div> | ||
| {isScheduledExpanded ? ( | ||
| <ChevronDown className="w-4 h-4 text-text-secondary" /> | ||
| ) : ( | ||
| <ChevronRight className="w-4 h-4 text-text-secondary" /> | ||
| )} | ||
| </button> | ||
|
|
||
| {isScheduledExpanded && ( | ||
| <div className="space-y-8"> | ||
| {memoizedScheduledDateGroups.map((group) => ( | ||
|
Comment on lines
+1043
to
+1045
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When the history spans more than the initial 15 human date groups and this accordion is expanded, this branch renders every scheduled group after only those 15 groups. Because Useful? React with 👍 / 👎.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in b56f75e. The scheduled accordion is now rendered only after every human date group is visible, so expanded scheduled history cannot block pagination to older human sessions. |
||
| <div key={group.label} className="space-y-4"> | ||
| <div className="sticky top-0 z-10 bg-background-primary/95 backdrop-blur-sm"> | ||
| <h2 className="text-text-secondary">{group.label}</h2> | ||
| </div> | ||
| <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 2xl:grid-cols-5 gap-4"> | ||
| {group.sessions.map((session) => ( | ||
| <SessionItem | ||
| key={session.id} | ||
| session={session} | ||
| onEditClick={handleEditSession} | ||
| onDuplicateClick={handleDuplicateSession} | ||
| onDeleteClick={handleDeleteSession} | ||
| onExportClick={handleExportSession} | ||
| onShareClick={handleShareSessionNostr} | ||
| onOpenInNewWindow={handleOpenInNewWindow} | ||
| isSharing={sharingSessionId === session.id} | ||
| /> | ||
| ))} | ||
| </div> | ||
| </div> | ||
| ))} | ||
| </div> | ||
| )} | ||
| </div> | ||
| )} | ||
|
|
||
| {isPrefetchingSessions && ( | ||
| <div className="flex justify-center py-8"> | ||
| <div className="flex items-center space-x-2 text-text-secondary"> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For screen-reader users, expanding this disclosure leaves the button's accessible name unchanged and exposes no expanded/collapsed state, so they cannot determine whether the scheduled sessions are currently visible. Add an
aria-expandedvalue tied toisScheduledExpanded(and preferablyaria-controlstargeting the collapsible region).Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in the latest push. The disclosure button now exposes
aria-expandedand references the collapsible region througharia-controls.