Skip to content

Commit f0342c1

Browse files
google-genai-botcopybara-github
authored andcommitted
ADK changes
PiperOrigin-RevId: 832211459
1 parent aa1cebd commit f0342c1

File tree

5 files changed

+108
-33
lines changed

5 files changed

+108
-33
lines changed

src/app/components/chat/chat.component.spec.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ describe('ChatComponent', () => {
182182
events: of(new NavigationEnd(1, '', '')),
183183
});
184184
mockLocation = jasmine.createSpyObj('Location', ['replaceState']);
185-
mockAgentBuilderService = jasmine.createSpyObj('AgentBuilderService', ['clear', 'setLoadedAgentData']);
185+
mockAgentBuilderService = jasmine.createSpyObj(
186+
'AgentBuilderService', ['clear', 'setLoadedAgentData']);
186187

187188
mockActivatedRoute = {
188189
snapshot: {
@@ -496,10 +497,12 @@ describe('ChatComponent', () => {
496497
expect(component.traceData.length).toBe(0);
497498
});
498499

499-
it('should hide session list spinner', () => {
500-
expect(mockUiStateService.setIsSessionListLoading)
501-
.toHaveBeenCalledWith(false);
502-
});
500+
it(
501+
'should not hide session list spinner because the session list is still being loaded',
502+
() => {
503+
expect(mockUiStateService.setIsSessionListLoading)
504+
.toHaveBeenCalledWith(true);
505+
});
503506
});
504507

505508
describe('when session is created with error', () => {
@@ -638,8 +641,7 @@ describe('ChatComponent', () => {
638641

639642
describe('when canEdit throws an error', () => {
640643
beforeEach(() => {
641-
mockSessionService.canEditResponse.error(
642-
new Error('error'));
644+
mockSessionService.canEditResponse.error(new Error('error'));
643645
mockEventService.getTraceResponse.next([]);
644646
component['updateWithSelectedSession'](mockSession as any);
645647
fixture.detectChanges();

src/app/components/chat/chat.component.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@ import {getMediaTypeFromMimetype, MediaType} from '../artifact-tab/artifact-tab.
6767
import {BuilderTabsComponent} from '../builder-tabs/builder-tabs.component';
6868
import {CanvasComponent} from '../canvas/canvas.component';
6969
import {ChatPanelComponent} from '../chat-panel/chat-panel.component';
70-
import {ThemeToggle} from '../theme-toggle/theme-toggle';
7170
import {EditJsonDialogComponent} from '../edit-json-dialog/edit-json-dialog.component';
7271
import {EvalTabComponent} from '../eval-tab/eval-tab.component';
7372
import {PendingEventDialogComponent} from '../pending-event-dialog/pending-event-dialog.component';
7473
import {DeleteSessionDialogComponent, DeleteSessionDialogData,} from '../session-tab/delete-session-dialog/delete-session-dialog.component';
7574
import {SessionTabComponent} from '../session-tab/session-tab.component';
7675
import {SidePanelComponent} from '../side-panel/side-panel.component';
7776
import {SidePanelMessagesInjectionToken} from '../side-panel/side-panel.component.i18n';
77+
import {ThemeToggle} from '../theme-toggle/theme-toggle';
7878
import {TraceEventComponent} from '../trace-tab/trace-event/trace-event.component';
7979
import {ViewImageDialogComponent} from '../view-image-dialog/view-image-dialog.component';
8080

@@ -433,8 +433,6 @@ export class ChatComponent implements OnInit, AfterViewInit, OnDestroy {
433433
this.sessionService.createSession(this.userId, this.appName)
434434
.subscribe(
435435
(res) => {
436-
this.uiStateService.setIsSessionListLoading(false);
437-
438436
this.currentSessionState = res.state;
439437
this.sessionId = res.id ?? '';
440438
this.sessionTab?.refreshSession();
@@ -523,8 +521,9 @@ export class ChatComponent implements OnInit, AfterViewInit, OnDestroy {
523521
this.updatedSessionState.set(null);
524522
}
525523
this.streamingTextMessage = null;
526-
this.featureFlagService.isSessionReloadOnNewMessageEnabled().pipe(first()).subscribe(
527-
(enabled) => {
524+
this.featureFlagService.isSessionReloadOnNewMessageEnabled()
525+
.pipe(first())
526+
.subscribe((enabled) => {
528527
if (enabled) {
529528
this.sessionTab?.reloadSession(this.sessionId);
530529
}

src/app/components/session-tab/session-tab.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
</mat-form-field>
2525
</div>
2626
} @let isSessionListLoading = uiStateService.isSessionListLoading() | async; @if
27-
(isSessionListLoading && sessionList.length === 0) {
27+
(isSessionListLoading && !isLoadingMoreInProgress()) {
2828
<div class="loading-spinner-container">
2929
<mat-progress-bar mode="indeterminate"></mat-progress-bar>
3030
</div>

src/app/components/session-tab/session-tab.component.spec.ts

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,35 @@ describe('SessionTabComponent', () => {
141141
{
142142
filter: 'abc',
143143
pageToken: '',
144-
pageSize: component.SESSIONS_PAGE_LIMIT,
144+
pageSize: 100,
145145
},
146146
);
147147
}));
148+
149+
describe('on refresh', () => {
150+
beforeEach((fakeAsync(() => {
151+
component.refreshSession();
152+
tick(300); // for debounceTime
153+
})));
154+
155+
it('should reset session list', fakeAsync(() => {
156+
expect(component.sessionList).toEqual([]);
157+
}));
158+
159+
it('should reset page token and filter', fakeAsync(() => {
160+
expect(sessionService.listSessions)
161+
.toHaveBeenCalledWith(
162+
component.userId,
163+
component.appName,
164+
{
165+
filter: undefined,
166+
pageToken: '',
167+
pageSize: 100,
168+
},
169+
);
170+
}));
171+
});
172+
148173
describe('when list is loaded', () => {
149174
beforeEach(fakeAsync(() => {
150175
mockUiStateService.isSessionListLoadingResponse.next(false);
@@ -202,7 +227,7 @@ describe('SessionTabComponent', () => {
202227
{
203228
filter: undefined,
204229
pageToken: 'nextPage',
205-
pageSize: component.SESSIONS_PAGE_LIMIT,
230+
pageSize: 100,
206231
},
207232
);
208233
}));
@@ -345,4 +370,36 @@ describe('SessionTabComponent', () => {
345370
});
346371
});
347372
});
373+
374+
describe('on refresh', () => {
375+
beforeEach(fakeAsync(() => {
376+
mockFeatureFlagService.isSessionFilteringEnabledResponse.next(true);
377+
sessionService.listSessionsResponse.next({
378+
items: [{id: 'session1', lastUpdateTime: 1}],
379+
nextPageToken: 'nextPage',
380+
});
381+
fixture = TestBed.createComponent(SessionTabComponent);
382+
component = fixture.componentInstance;
383+
fixture.detectChanges();
384+
tick(500); // for setTimeout in ngOnInit
385+
expect(component.pageToken).toBe('nextPage');
386+
expect(component.sessionList.length).toBe(1);
387+
sessionService.listSessions.calls.reset();
388+
component.refreshSession();
389+
tick(300); // for debounceTime
390+
}));
391+
392+
it('should reset page token and session list', fakeAsync(() => {
393+
expect(sessionService.listSessions)
394+
.toHaveBeenCalledWith(
395+
component.userId,
396+
component.appName,
397+
{
398+
filter: undefined,
399+
pageToken: '',
400+
pageSize: 100,
401+
},
402+
);
403+
}));
404+
});
348405
});

src/app/components/session-tab/session-tab.component.ts

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ export class SessionTabComponent implements OnInit {
8181
isSessionFilteringEnabled =
8282
this.featureFlagService.isSessionFilteringEnabled();
8383

84+
isLoadingMoreInProgress = signal(false);
85+
8486
constructor() {
8587
this.filterControl.valueChanges.pipe(debounceTime(300)).subscribe(() => {
8688
this.pageToken = '';
@@ -112,28 +114,34 @@ export class SessionTabComponent implements OnInit {
112114
.pipe(catchError(() => of({items: [], nextPageToken: ''})));
113115
}),
114116
tap(({items, nextPageToken}) => {
115-
this.sessionList = Array.from(
116-
new Map(
117-
[...this.sessionList, ...items].map((session) => [
118-
session.id,
119-
session,
120-
]),
121-
).values(),
122-
).sort(
123-
(a: any, b: any) =>
124-
Number(b.lastUpdateTime) - Number(a.lastUpdateTime),
125-
);
117+
this.sessionList =
118+
Array
119+
.from(
120+
new Map(
121+
[...this.sessionList, ...items].map(
122+
(session) =>
123+
[session.id,
124+
session,
125+
]),
126+
)
127+
.values(),
128+
)
129+
.sort(
130+
(a: any, b: any) => Number(b.lastUpdateTime) -
131+
Number(a.lastUpdateTime),
132+
);
126133
this.pageToken = nextPageToken ?? '';
127134
this.canLoadMoreSessions = !!nextPageToken;
128135
this.changeDetectorRef.markForCheck();
129-
}),
130-
debounceTime(300),
136+
})
131137
)
132138
.subscribe(
133139
() => {
140+
this.isLoadingMoreInProgress.set(false);
134141
this.uiStateService.setIsSessionListLoading(false);
135142
},
136143
() => {
144+
this.isLoadingMoreInProgress.set(false);
137145
this.uiStateService.setIsSessionListLoading(false);
138146
},
139147
);
@@ -203,6 +211,7 @@ export class SessionTabComponent implements OnInit {
203211
}
204212

205213
loadMoreSessions() {
214+
this.isLoadingMoreInProgress.set(true);
206215
this.refreshSessionsSubject.next();
207216
}
208217

@@ -229,15 +238,23 @@ export class SessionTabComponent implements OnInit {
229238
}
230239

231240
refreshSession(session?: string) {
232-
this.refreshSessionsSubject.next();
233-
if (this.sessionList.length <= 1) {
234-
return undefined;
235-
} else {
241+
let nextSession = null;
242+
243+
if (this.sessionList.length > 0) {
236244
let index = this.sessionList.findIndex((s) => s.id == session);
237245
if (index == this.sessionList.length - 1) {
238246
index = -1;
239247
}
240-
return this.sessionList[index + 1];
248+
nextSession = this.sessionList[index + 1];
241249
}
250+
251+
if (this.isSessionFilteringEnabled) {
252+
this.filterControl.setValue('');
253+
} else {
254+
this.sessionList = [];
255+
this.refreshSessionsSubject.next();
256+
}
257+
258+
return nextSession;
242259
}
243260
}

0 commit comments

Comments
 (0)