Skip to content

Commit d88b595

Browse files
committed
Adding feedback mechanism for internal amazon users as part of V2 version
1 parent 997b3b7 commit d88b595

File tree

5 files changed

+50
-15
lines changed

5 files changed

+50
-15
lines changed

packages/core/src/amazonq/webview/ui/apps/testChatConnector.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ export class Connector extends BaseConnector {
162162
body: messageData.message,
163163
canBeVoted: false,
164164
informationCard: messageData.informationCard,
165+
buttons: messageData.buttons ?? [],
165166
}
166167
this.onChatAnswerReceived(messageData.tabID, answer, messageData)
167168
}

packages/core/src/amazonqTest/chat/controller/controller.ts

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
import MessengerUtils, { ButtonActions } from './messenger/messengerUtils'
2727
import { getTelemetryReasonDesc, isAwsError } from '../../../shared/errors'
2828
import { ChatItemType } from '../../../amazonq/commons/model'
29-
import { ProgressField } from '@aws/mynah-ui'
29+
import { ChatItemButton, MynahIcons, ProgressField } from '@aws/mynah-ui'
3030
import { FollowUpTypes } from '../../../amazonq/commons/types'
3131
import {
3232
cancelBuild,
@@ -63,6 +63,9 @@ import {
6363
} from '../../../codewhisperer/models/constants'
6464
import { UserWrittenCodeTracker } from '../../../codewhisperer/tracker/userWrittenCodeTracker'
6565
import { ReferenceLogViewProvider } from '../../../codewhisperer/service/referenceLogViewProvider'
66+
import { submitFeedback } from '../../../feedback/vue/submitFeedback'
67+
import { placeholder } from '../../../shared/vscode/commands2'
68+
import { Auth } from '../../../auth/auth'
6669

6770
export interface TestChatControllerEventEmitters {
6871
readonly tabOpened: vscode.EventEmitter<any>
@@ -354,6 +357,7 @@ export class TestController {
354357
// This function handles actions if user clicked on any Button one of these cases will be executed
355358
private async handleFormActionClicked(data: any) {
356359
const typedAction = MessengerUtils.stringToEnumValue(ButtonActions, data.action as any)
360+
let getFeedbackCommentData = ''
357361
switch (typedAction) {
358362
case ButtonActions.STOP_TEST_GEN:
359363
testGenState.setToCancelling()
@@ -366,6 +370,16 @@ export class TestController {
366370
this.messenger.sendChatInputEnabled(data.tabID, true)
367371
await this.sessionCleanUp()
368372
break
373+
case ButtonActions.PROVIDE_FEEDBACK:
374+
getFeedbackCommentData = `Q Test Generation: RequestId: ${this.sessionStorage.getSession().startTestGenerationRequestId}`
375+
void submitFeedback(placeholder, 'Amazon Q', getFeedbackCommentData)
376+
telemetry.ui_click.emit({ elementId: 'unitTestGeneration_provideFeedback' })
377+
this.messenger.sendMessage(
378+
'Unit test generation completed. Thanks for providing feedback.',
379+
data.tabID,
380+
'answer'
381+
)
382+
break
369383
}
370384
}
371385
// This function handles actions if user gives any input from the chatInput box
@@ -897,7 +911,25 @@ export class TestController {
897911

898912
// TODO: Check if there are more cases to endSession if yes create a enum or type for step
899913
private async endSession(data: any, step: FollowUpTypes) {
900-
this.messenger.sendMessage('Unit test generation completed.', data.tabID, 'answer')
914+
const buttons: ChatItemButton[] = []
915+
if (Auth.instance.isInternalAmazonUser()) {
916+
buttons.push({
917+
keepCardAfterClick: false,
918+
text: 'How can we make /test better?',
919+
id: ButtonActions.PROVIDE_FEEDBACK,
920+
disabled: false, // allow button to be re-clicked
921+
position: 'outside',
922+
icon: 'comment' as MynahIcons,
923+
})
924+
}
925+
926+
this.messenger.sendMessage(
927+
'Unit test generation completed.',
928+
data.tabID,
929+
'answer',
930+
'testGenEndSessionMessage',
931+
buttons
932+
)
901933

902934
const session = this.sessionStorage.getSession()
903935
if (step === FollowUpTypes.RejectCode) {

packages/core/src/amazonqTest/chat/controller/messenger/messenger.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
UpdatePromptProgressMessage,
2525
} from '../../views/connector/connector'
2626
import { ChatItemType } from '../../../../amazonq/commons/model'
27-
import { ChatItemAction, ProgressField } from '@aws/mynah-ui'
27+
import { ChatItemAction, ChatItemButton, ProgressField } from '@aws/mynah-ui'
2828
import * as CodeWhispererConstants from '../../../../codewhisperer/models/constants'
2929
import { TriggerPayload } from '../../../../codewhispererChat/controllers/chat/model'
3030
import {
@@ -76,8 +76,16 @@ export class Messenger {
7676
this.dispatcher.sendChatMessage(new CapabilityCardMessage(params.tabID))
7777
}
7878

79-
public sendMessage(message: string, tabID: string, messageType: ChatItemType) {
80-
this.dispatcher.sendChatMessage(new ChatMessage({ message, messageType }, tabID))
79+
public sendMessage(
80+
message: string,
81+
tabID: string,
82+
messageType: ChatItemType,
83+
messageId?: string,
84+
buttons?: ChatItemButton[]
85+
) {
86+
this.dispatcher.sendChatMessage(
87+
new ChatMessage({ message, messageType, messageId: messageId, buttons: buttons }, tabID)
88+
)
8189
}
8290

8391
public sendShortSummary(params: {
@@ -159,16 +167,7 @@ export class Messenger {
159167
message = CodeWhispererConstants.invalidFileTypeChatMessage
160168
break
161169
}
162-
163-
this.dispatcher.sendChatMessage(
164-
new ChatMessage(
165-
{
166-
message,
167-
messageType: 'answer-stream',
168-
},
169-
tabID
170-
)
171-
)
170+
this.sendMessage(message, tabID, 'answer-stream')
172171
}
173172

174173
public sendErrorMessage(errorMessage: string, tabID: string) {

packages/core/src/amazonqTest/chat/controller/messenger/messengerUtils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export enum ButtonActions {
1212
VIEW_DIFF = 'View-Diff',
1313
STOP_TEST_GEN = 'Stop-Test-Generation',
1414
STOP_BUILD = 'Stop-Build-Process',
15+
PROVIDE_FEEDBACK = 'Provide-Feedback',
1516
}
1617

1718
// TODO: Refactor the common functionality between Transform, FeatureDev, CWSPRChat, Scan and UTG to a new Folder.

packages/core/src/amazonqTest/chat/views/connector/connector.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ export class ChatMessage extends UiMessage {
8080
readonly messageId?: string | undefined
8181
readonly messageType: ChatItemType
8282
readonly canBeVoted?: boolean
83+
readonly buttons?: ChatItemButton[]
8384
readonly informationCard: ChatItemContent['informationCard']
8485
override type: TestMessageType = 'chatMessage'
8586

@@ -90,6 +91,7 @@ export class ChatMessage extends UiMessage {
9091
this.messageId = props.messageId || undefined
9192
this.canBeVoted = props.canBeVoted || undefined
9293
this.informationCard = props.informationCard || undefined
94+
this.buttons = props.buttons || undefined
9395
}
9496
}
9597

0 commit comments

Comments
 (0)