Skip to content

Commit cf8abf9

Browse files
committed
refactor insert code pill text logic
1 parent 4370248 commit cf8abf9

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

packages/core/src/amazonqFeatureDev/controllers/chat/controller.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,11 @@ export class FeatureDevController {
289289
tabID: message.tabID,
290290
followUps: [
291291
{
292-
pillText: i18n('AWS.amazonq.featureDev.pillText.acceptAllChanges'),
292+
pillText:
293+
session?.getInsertCodePillText([
294+
...(session?.state.filePaths ?? []),
295+
...(session?.state.deletedFiles ?? []),
296+
]) ?? i18n('AWS.amazonq.featureDev.pillText.acceptAllChanges'),
293297
type: FollowUpTypes.InsertCode,
294298
icon: 'ok' as MynahIcons,
295299
status: 'success',

packages/core/src/amazonqFeatureDev/session/session.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -157,16 +157,7 @@ export class Session {
157157
public async updateFilesPaths(params: UpdateFilesPathsParams) {
158158
const { tabID, filePaths, deletedFiles, messageId, disableFileActions = false } = params
159159
this.messenger.updateFileComponent(tabID, filePaths, deletedFiles, messageId, disableFileActions)
160-
const allFiles = [...filePaths, ...deletedFiles]
161-
if (allFiles.some((file) => file.rejected || file.changeApplied)) {
162-
if (allFiles.every((file) => file.rejected || file.changeApplied)) {
163-
await this.updateChatAnswer(tabID, i18n('AWS.amazonq.featureDev.pillText.continue'))
164-
} else {
165-
await this.updateChatAnswer(tabID, i18n('AWS.amazonq.featureDev.pillText.acceptRemainingChanges'))
166-
}
167-
} else {
168-
await this.updateChatAnswer(tabID, i18n('AWS.amazonq.featureDev.pillText.acceptAllChanges'))
169-
}
160+
await this.updateChatAnswer(tabID, this.getInsertCodePillText([...filePaths, ...deletedFiles]))
170161
}
171162

172163
public async updateChatAnswer(tabID: string, insertCodePillText: string) {
@@ -272,6 +263,16 @@ export class Session {
272263
this._acceptCodeTelemetrySent = sent
273264
}
274265

266+
public getInsertCodePillText(files: Array<NewFileInfo | DeletedFileInfo>) {
267+
if (files.every((file) => file.rejected || file.changeApplied)) {
268+
return i18n('AWS.amazonq.featureDev.pillText.continue')
269+
}
270+
if (files.some((file) => file.rejected || file.changeApplied)) {
271+
return i18n('AWS.amazonq.featureDev.pillText.acceptRemainingChanges')
272+
}
273+
return i18n('AWS.amazonq.featureDev.pillText.acceptAllChanges')
274+
}
275+
275276
get state() {
276277
if (!this._state) {
277278
throw new Error("State should be initialized before it's read")

0 commit comments

Comments
 (0)