Skip to content

Commit 84829e3

Browse files
authored
Add welcome view support to chat sessions (microsoft#262207)
* Add welcome view support to chat sessions Part of microsoft/vscode-pull-request-github#7614 * Add a button
1 parent f6875c0 commit 84829e3

File tree

1 file changed

+27
-47
lines changed

1 file changed

+27
-47
lines changed

src/vs/workbench/contrib/chat/browser/chatSessions.ts

Lines changed: 27 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import * as DOM from '../../../../base/browser/dom.js';
7-
import { $, append, clearNode, getActiveWindow } from '../../../../base/browser/dom.js';
7+
import { $, append, getActiveWindow } from '../../../../base/browser/dom.js';
88
import { ActionBar } from '../../../../base/browser/ui/actionbar/actionbar.js';
99
import { IListVirtualDelegate } from '../../../../base/browser/ui/list/list.js';
1010
import { IAsyncDataSource, ITreeContextMenuEvent, ITreeNode, ITreeRenderer } from '../../../../base/browser/ui/tree/tree.js';
@@ -510,6 +510,13 @@ class ChatSessionsViewPaneContainer extends ViewPaneContainer {
510510

511511
viewDescriptorsToRegister.push(viewDescriptor);
512512
this.registeredViewDescriptors.set(provider.chatSessionType, viewDescriptor);
513+
514+
if (provider.chatSessionType === 'local') {
515+
const viewsRegistry = Registry.as<IViewsRegistry>(Extensions.ViewsRegistry);
516+
this._register(viewsRegistry.registerViewWelcomeContent(viewDescriptor.id, {
517+
content: nls.localize('chatSessions.noResults', "No local chat sessions\n[Start a Chat](command:workbench.action.openChat)"),
518+
}));
519+
}
513520
}
514521
});
515522

@@ -936,6 +943,7 @@ class SessionsViewPane extends ViewPane {
936943
private dataSource?: SessionsDataSource;
937944
private labels?: ResourceLabels;
938945
private messageElement?: HTMLElement;
946+
private _isEmpty: boolean = true;
939947

940948
constructor(
941949
private readonly provider: IChatSessionItemProvider,
@@ -967,6 +975,10 @@ class SessionsViewPane extends ViewPane {
967975
}
968976
}
969977

978+
override shouldShowWelcome(): boolean {
979+
return this._isEmpty;
980+
}
981+
970982
private isLocalChatSessionItem(item: IChatSessionItem): item is ILocalChatSessionItem {
971983
return ('editor' in item && 'group' in item) || ('widget' in item && 'sessionType' in item);
972984
}
@@ -977,59 +989,27 @@ class SessionsViewPane extends ViewPane {
977989
}
978990
}
979991

980-
private showEmptyMessage(): void {
981-
if (!this.messageElement) {
982-
return;
983-
}
984-
985-
const messageText = this.provider.chatSessionType === 'local'
986-
? nls.localize('chatSessions.noChatSessions', "No chat sessions")
987-
: nls.localize('chatSessions.noAgentSessions', "No agent sessions found");
988-
989-
// Clear the message element using DOM utility
990-
clearNode(this.messageElement);
991-
992-
const messageContainer = append(this.messageElement, $('.no-sessions-message'));
993-
994-
const textElement = append(messageContainer, $('span'));
995-
textElement.textContent = messageText;
996-
997-
// Show the message element
998-
this.messageElement.style.display = 'block';
999-
1000-
// Hide the tree
1001-
if (this.treeContainer) {
1002-
this.treeContainer.style.display = 'none';
1003-
}
1004-
}
1005-
1006-
private hideMessage(): void {
1007-
if (this.messageElement) {
1008-
this.messageElement.style.display = 'none';
992+
private isEmpty() {
993+
// Check if the tree has the provider node and get its children count
994+
if (!this.tree?.hasNode(this.provider)) {
995+
return true;
1009996
}
997+
const providerNode = this.tree.getNode(this.provider);
998+
const childCount = providerNode.children?.length || 0;
1010999

1011-
// Show the tree
1012-
if (this.treeContainer) {
1013-
this.treeContainer.style.display = 'block';
1014-
}
1000+
return childCount === 0;
10151001
}
10161002

10171003
/**
10181004
* Updates the empty state message based on current tree data.
10191005
* Uses the tree's existing data to avoid redundant provider calls.
10201006
*/
1021-
private updateEmptyStateMessage(): void {
1007+
private updateEmptyState(): void {
10221008
try {
1023-
// Check if the tree has the provider node and get its children count
1024-
if (this.tree?.hasNode(this.provider)) {
1025-
const providerNode = this.tree.getNode(this.provider);
1026-
const childCount = providerNode.children?.length || 0;
1027-
1028-
if (childCount === 0) {
1029-
this.showEmptyMessage();
1030-
} else {
1031-
this.hideMessage();
1032-
}
1009+
const newEmptyState = this.isEmpty();
1010+
if (newEmptyState !== this._isEmpty) {
1011+
this._isEmpty = newEmptyState;
1012+
this._onDidChangeViewWelcomeState.fire();
10331013
}
10341014
} catch (error) {
10351015
this.logService.error('Error checking tree data for empty state:', error);
@@ -1057,7 +1037,7 @@ class SessionsViewPane extends ViewPane {
10571037
);
10581038

10591039
// Check for empty state after refresh using tree data
1060-
this.updateEmptyStateMessage();
1040+
this.updateEmptyState();
10611041
} catch (error) {
10621042
// Log error but don't throw to avoid breaking the UI
10631043
this.logService.error('Error refreshing chat sessions tree:', error);
@@ -1085,7 +1065,7 @@ class SessionsViewPane extends ViewPane {
10851065
);
10861066

10871067
// Check for empty state after loading using tree data
1088-
this.updateEmptyStateMessage();
1068+
this.updateEmptyState();
10891069
} catch (error) {
10901070
// Log error but don't throw to avoid breaking the UI
10911071
this.logService.error('Error loading chat sessions data:', error);

0 commit comments

Comments
 (0)