Change to show graph title in graph panel

This commit is contained in:
dimitrievgs 2025-10-05 19:11:41 +03:00
parent 47cff8a121
commit b0d802241b
2 changed files with 259 additions and 215 deletions

25
main.js

File diff suppressed because one or more lines are too long

View File

@ -24,6 +24,7 @@ export class GraphView extends ItemView {
graphsList: any[];
selectedGraphId: string | null;
selectedNodeIds: Set<string>; // Добавляем Set для хранения ID выделенных узлов
selectedGraphTitle: string | null;
// UI Elements
historyPanel: HistoryPanel | null;
@ -48,6 +49,7 @@ export class GraphView extends ItemView {
this.reactRoot = null;
this.isHistoryCollapsed = true;
this.selectedNodeIds = new Set<string>(); // Инициализируем Set
this.selectedGraphTitle = null;
}
/**
@ -61,7 +63,7 @@ export class GraphView extends ItemView {
* @returns {string} Отображаемое имя представления.
*/
getDisplayText(): string {
return 'LLM Agent Graph';
return this.selectedGraphTitle || 'LLM Agent Graph';
}
/**
@ -143,6 +145,20 @@ export class GraphView extends ItemView {
this.plugin.eventBus.off('delete-node', this.handleDeleteNodeFromChat);
}
// ----------------------------------------------- Custom Title Update ---------------------------------------------------
/**
* Обновляет текстовое содержимое заголовка представления.
* Этот метод должен быть вызван для динамического изменения заголовка
* после первоначальной отрисовки представления.
*/
updateTitle(): void {
const titleElement = this.containerEl.querySelector('.view-header-title');
if (titleElement) {
titleElement.textContent = this.selectedGraphTitle || 'LLM Agent Graph';
}
}
// ----------------------------------------------- History Panel Toggle --------------------------------------------------
/**
@ -283,6 +299,8 @@ export class GraphView extends ItemView {
this.graphData = { nodes: [], edges: [] };
this.currentNode = null;
this.selectedNodeIds.clear(); // Очищаем выделения
this.selectedGraphTitle = null; // Сброс заголовка
this.updateTitle(); // Обновляем заголовок
this.renderGraphPanel();
this.plugin.eventBus.emit('chat-history-updated', { graphId: null, messages: [], current_node_id: null });
return;
@ -301,6 +319,9 @@ export class GraphView extends ItemView {
};
this.currentNode = data.current_node_id;
// Устанавливаем заголовок графа
this.selectedGraphTitle = data.title || data.first_message || `Граф ${graphId.substring(0, 8)}...`;
this.updateTitle(); // Обновляем заголовок
// Перерендериваем граф
this.renderGraphPanel();
@ -310,9 +331,10 @@ export class GraphView extends ItemView {
messages: data.messages || [],
current_node_id: data.current_node_id // Передаем актуальный current_node_id
});
} catch (error) {
console.error('Ошибка загрузки данных графа:', error);
this.selectedGraphTitle = null;
this.updateTitle(); // Обновляем заголовок
// Optionally: show a notice to the user
// new Notice(`Ошибка загрузки данных графа: ${error.message}`);
}
@ -347,7 +369,6 @@ export class GraphView extends ItemView {
// Сбрасываем выделение, если удаленный узел был выделен
this.selectedNodeIds.delete(nodeId);
} catch (error) {
console.error(`Ошибка при удалении узла ${nodeId}:`, error);
new Notice(`Ошибка при удалении узла: ${error.message}`, 5000);
@ -393,6 +414,8 @@ export class GraphView extends ItemView {
this.currentNode = null;
this.selectedGraphId = null;
this.selectedNodeIds.clear(); // Очищаем выделения
this.selectedGraphTitle = null; // Сброс заголовка при новом чате
this.updateTitle(); // Обновляем заголовок
this.renderGraphPanel();
this.fetchGraphsList(); // Обновить список графов, чтобы показать новый пустой чат
this.plugin.eventBus.emit('chat-history-updated', { graphId: null, messages: [], current_node_id: null });