Skip to content

Commit b4c9240

Browse files
committed
msg: working-partially;
- now has undo button displayed - Duplicate data still being shown in the chat-item-card - no file-click, buttons action implemented
1 parent a6e1b38 commit b4c9240

File tree

2 files changed

+42
-21
lines changed

2 files changed

+42
-21
lines changed

src/components/chat-item/chat-wrapper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,8 @@ export class ChatWrapper {
429429
if (chatItem.messageId.includes('modified-files-')) {
430430
console.log('[ChatWrapper] Setting ModifiedFilesChatItem with fileList:', chatItem.header.fileList);
431431
this.setModifiedFilesChatItem(chatItem);
432+
return;
432433
}
433-
return;
434434
}
435435

436436
if (chatItem.type === ChatItemType.PROMPT || chatItem.type === ChatItemType.SYSTEM_PROMPT) {

src/components/modified-files-tracker.ts

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { CollapsibleContent } from './collapsible-content';
99
import { ChatItem, ChatItemContent, ChatItemButton, MynahEventNames } from '../static';
1010
import testIds from '../helper/test-ids';
1111
import { ChatItemTreeViewWrapper } from './chat-item/chat-item-tree-view-wrapper';
12-
import { ChatItemButtonsWrapper } from './chat-item/chat-item-buttons';
1312
import { MynahUIGlobalEvents } from '../helper/events';
1413

1514
export interface ModifiedFilesTrackerProps {
@@ -92,9 +91,18 @@ export class ModifiedFilesTracker {
9291
}
9392

9493
private renderAllFilePills (contentWrapper: Element): void {
94+
// Convert buttons to actions if available
95+
let buttonActions: Record<string, any[]> = {};
96+
if (((this.props.chatItem?.buttons) != null) && Array.isArray(this.props.chatItem.buttons) && this.props.chatItem.buttons.length > 0) {
97+
buttonActions = this.convertButtonsToActions(this.props.chatItem.buttons);
98+
}
99+
95100
this.allFiles.forEach(({ fileList, messageId }) => {
96101
const { filePaths = [], deletedFiles = [], actions, details, flatList } = fileList;
97102

103+
// Merge existing actions with button actions
104+
const mergedActions = { ...actions, ...buttonActions };
105+
98106
// Create a wrapper for each file group
99107
const fileGroupWrapper = DomBuilder.getInstance().build({
100108
type: 'div',
@@ -111,7 +119,7 @@ export class ModifiedFilesTracker {
111119
rootTitle: fileList.rootFolderTitle,
112120
deletedFiles,
113121
flatList,
114-
actions,
122+
actions: mergedActions,
115123
details,
116124
hideFileCount: fileList.hideFileCount ?? true,
117125
collapsed: fileList.collapsed ?? false,
@@ -120,31 +128,44 @@ export class ModifiedFilesTracker {
120128
onRootCollapsedStateChange: () => {}
121129
}).render);
122130

123-
// Render buttons if they exist
124-
const fileListWithButtons = fileList as ChatItemContent['fileList'] & { buttons?: ChatItemButton[] };
125-
const buttons: ChatItemButton[] | undefined = fileListWithButtons.buttons;
126-
if (Array.isArray(buttons) && buttons.length > 0) {
127-
const buttonsWrapper = new ChatItemButtonsWrapper({
128-
tabId: this.props.tabId,
129-
buttons,
130-
onActionClick: (action: ChatItemButton) => {
131-
MynahUIGlobalEvents.getInstance().dispatch(MynahEventNames.BODY_ACTION_CLICKED, {
132-
tabId: this.props.tabId,
133-
messageId: (action as any).messageId != null ? (action as any).messageId : messageId,
134-
actionId: action.id,
135-
actionText: action.text
136-
});
131+
contentWrapper.appendChild(fileGroupWrapper);
132+
});
133+
}
134+
135+
private convertButtonsToActions (buttons: ChatItemButton[]): Record<string, any[]> {
136+
// Convert buttons to actions format that ChatItemTreeViewWrapper expects
137+
const actions: Record<string, any[]> = {};
138+
139+
buttons.forEach(button => {
140+
// Add action to all files (you might want to be more specific based on your needs)
141+
this.allFiles.forEach(({ fileList }) => {
142+
fileList.filePaths?.forEach(filePath => {
143+
if (actions[filePath] == null) {
144+
actions[filePath] = [];
137145
}
146+
actions[filePath].push({
147+
id: button.id,
148+
text: button.text,
149+
icon: button.icon,
150+
onClick: () => {
151+
MynahUIGlobalEvents.getInstance().dispatch(MynahEventNames.BODY_ACTION_CLICKED, {
152+
tabId: this.props.tabId,
153+
messageId: this.props.chatItem?.messageId ?? '',
154+
actionId: button.id,
155+
actionText: button.text
156+
});
157+
}
158+
});
138159
});
139-
fileGroupWrapper.appendChild(buttonsWrapper.render);
140-
}
141-
142-
contentWrapper.appendChild(fileGroupWrapper);
160+
});
143161
});
162+
return actions;
144163
}
145164

146165
public addChatItem (chatItem: ChatItem): void {
147166
if (chatItem.header?.fileList != null) {
167+
// Store the current chatItem for button handling
168+
this.props.chatItem = chatItem;
148169
this.renderModifiedFiles(chatItem.header.fileList, chatItem.messageId);
149170
}
150171
}

0 commit comments

Comments
 (0)