agent sessions - show flat list of unread sessions when filter is enabled (#292520)

This commit is contained in:
Benjamin Pasero
2026-02-03 11:37:00 +01:00
committed by GitHub
parent ee6f04619f
commit c7f71097f1
3 changed files with 61 additions and 12 deletions

View File

@@ -327,17 +327,8 @@ export class AgentSessionsControl extends Disposable implements IAgentSessionsCo
break;
}
case AgentSessionSection.More: {
if (child.collapsed) {
let autoExpandMore = false;
if (this.sessionsListFindIsOpen) {
autoExpandMore = true; // always expand when find is open
} else if (this.options.filter.getExcludes().read && child.element.sessions.some(session => !session.isRead())) {
autoExpandMore = true; // expand when showing only unread and this section includes unread
}
if (autoExpandMore) {
this.sessionsList.expand(child.element);
}
if (child.collapsed && this.sessionsListFindIsOpen) {
this.sessionsList.expand(child.element); // always expand when find is open
}
break;
}

View File

@@ -657,6 +657,10 @@ export class AgentSessionsDataSource implements IAsyncDataSource<IAgentSessionsM
const sortedSessions = sessions.sort(this.sorter.compare.bind(this.sorter));
if (this.filter?.groupResults?.() === AgentSessionsGrouping.Capped) {
if (this.filter?.getExcludes().read) {
return sortedSessions; // When filtering to show only unread sessions, show a flat list
}
return this.groupSessionsCapped(sortedSessions);
} else {
return this.groupSessionsByDate(sortedSessions);

View File

@@ -146,12 +146,13 @@ suite('AgentSessionsDataSource', () => {
function createMockFilter(options: {
groupBy?: AgentSessionsGrouping;
exclude?: (session: IAgentSession) => boolean;
excludeRead?: boolean;
}): IAgentSessionsFilter {
return {
onDidChange: Event.None,
groupResults: () => options.groupBy,
exclude: options.exclude ?? (() => false),
getExcludes: () => ({ providers: [], states: [], archived: false, read: false })
getExcludes: () => ({ providers: [], states: [], archived: false, read: options.excludeRead ?? false })
};
}
@@ -447,5 +448,58 @@ suite('AgentSessionsDataSource', () => {
assert.strictEqual(olderSection.sessions[0].label, 'Session old2');
assert.strictEqual(olderSection.sessions[1].label, 'Session old1');
});
test('capped grouping with unread filter returns flat list without More section', () => {
const now = Date.now();
const sessions = [
createMockSession({ id: '1', startTime: now, isRead: false }),
createMockSession({ id: '2', startTime: now - ONE_DAY, isRead: false }),
createMockSession({ id: '3', startTime: now - 2 * ONE_DAY, isRead: false }),
createMockSession({ id: '4', startTime: now - 3 * ONE_DAY, isRead: false }),
createMockSession({ id: '5', startTime: now - 4 * ONE_DAY, isRead: false }),
];
const filter = createMockFilter({
groupBy: AgentSessionsGrouping.Capped,
excludeRead: true // Filtering to show only unread sessions
});
const sorter = createMockSorter();
const dataSource = new AgentSessionsDataSource(filter, sorter);
const mockModel = createMockModel(sessions);
const result = Array.from(dataSource.getChildren(mockModel));
// Should be a flat list without sections (no More section)
assert.strictEqual(result.length, 5);
assert.strictEqual(getSectionsFromResult(result).length, 0);
});
test('capped grouping without unread filter includes More section', () => {
const now = Date.now();
const sessions = [
createMockSession({ id: '1', startTime: now }),
createMockSession({ id: '2', startTime: now - ONE_DAY }),
createMockSession({ id: '3', startTime: now - 2 * ONE_DAY }),
createMockSession({ id: '4', startTime: now - 3 * ONE_DAY }),
createMockSession({ id: '5', startTime: now - 4 * ONE_DAY }),
];
const filter = createMockFilter({
groupBy: AgentSessionsGrouping.Capped,
excludeRead: false // Not filtering to unread only
});
const sorter = createMockSorter();
const dataSource = new AgentSessionsDataSource(filter, sorter);
const mockModel = createMockModel(sessions);
const result = Array.from(dataSource.getChildren(mockModel));
// Should have 3 top sessions + 1 More section
assert.strictEqual(result.length, 4);
const sections = getSectionsFromResult(result);
assert.strictEqual(sections.length, 1);
assert.strictEqual(sections[0].section, AgentSessionSection.More);
assert.strictEqual(sections[0].sessions.length, 2);
});
});
});