Skip to content

Commit 8d4e9d5

Browse files
committed
msg: working-partially;
- Fileclick work correctly - undo button however is only coming up for the last file now and not persitent, works though
1 parent 3e11fc5 commit 8d4e9d5

File tree

1 file changed

+26
-40
lines changed

1 file changed

+26
-40
lines changed

src/components/modified-files-tracker.ts

Lines changed: 26 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
import { DomBuilder, ExtendedHTMLElement } from '../helper/dom';
77
import { StyleLoader } from '../helper/style-loader';
88
import { CollapsibleContent } from './collapsible-content';
9-
import { ChatItem, ChatItemContent, ChatItemButton, MynahEventNames } from '../static';
9+
import { ChatItem, ChatItemContent, 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';
1213
import { MynahUIGlobalEvents } from '../helper/events';
1314

1415
export interface ModifiedFilesTrackerProps {
@@ -91,35 +92,26 @@ export class ModifiedFilesTracker {
9192
}
9293

9394
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-
10095
this.allFiles.forEach(({ fileList, messageId }) => {
10196
const { filePaths = [], deletedFiles = [], actions, details, flatList } = fileList;
10297

103-
// Merge existing actions with button actions
104-
const mergedActions = { ...actions, ...buttonActions };
105-
10698
// Create a wrapper for each file group
10799
const fileGroupWrapper = DomBuilder.getInstance().build({
108100
type: 'div',
109101
classNames: [ 'mynah-modified-files-group' ],
110102
children: []
111103
});
112104

113-
// Render the file tree with actions and buttons as provided by the data
105+
// Render the file tree with original actions only
114106
fileGroupWrapper.appendChild(new ChatItemTreeViewWrapper({
115107
tabId: this.props.tabId,
116-
messageId,
108+
messageId: this.getOriginalMessageId(messageId),
117109
files: filePaths,
118110
cardTitle: '',
119111
rootTitle: fileList.rootFolderTitle,
120112
deletedFiles,
121113
flatList,
122-
actions: mergedActions,
114+
actions,
123115
details,
124116
hideFileCount: fileList.hideFileCount ?? true,
125117
collapsed: fileList.collapsed ?? false,
@@ -130,36 +122,30 @@ export class ModifiedFilesTracker {
130122

131123
contentWrapper.appendChild(fileGroupWrapper);
132124
});
133-
}
134125

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] = [];
145-
}
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-
}
126+
// Add buttons separately using ChatItemButtonsWrapper, same as chat-item-card.ts
127+
if (((this.props.chatItem?.buttons) != null) && Array.isArray(this.props.chatItem.buttons) && this.props.chatItem.buttons.length > 0) {
128+
const buttonsWrapper = new ChatItemButtonsWrapper({
129+
tabId: this.props.tabId,
130+
classNames: [ 'mynah-modified-files-buttons' ],
131+
formItems: null,
132+
buttons: this.props.chatItem.buttons,
133+
onActionClick: action => {
134+
MynahUIGlobalEvents.getInstance().dispatch(MynahEventNames.BODY_ACTION_CLICKED, {
135+
tabId: this.props.tabId,
136+
messageId: this.getOriginalMessageId(this.props.chatItem?.messageId ?? ''),
137+
actionId: action.id,
138+
actionText: action.text
158139
});
159-
});
140+
}
160141
});
161-
});
162-
return actions;
142+
contentWrapper.appendChild(buttonsWrapper.render);
143+
}
144+
}
145+
146+
private getOriginalMessageId (messageId: string): string {
147+
// Remove "modified-files-" prefix if present
148+
return messageId.startsWith('modified-files-') ? messageId.replace('modified-files-', '') : messageId;
163149
}
164150

165151
public addChatItem (chatItem: ChatItem): void {

0 commit comments

Comments
 (0)