Skip to content

Commit db1d16c

Browse files
authored
refactor: deduplicate messages, avoid unnecessary exports #4679
1 parent f484517 commit db1d16c

File tree

6 files changed

+19
-23
lines changed

6 files changed

+19
-23
lines changed

packages/core/src/codecatalyst/auth.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import * as vscode from 'vscode'
77
import { onAccessDeniedException, CodeCatalystClient, createClient } from '../shared/clients/codecatalystClient'
88
import { Auth } from '../auth/auth'
9+
import * as localizedText from '../shared/localizedText'
910
import { getSecondaryAuth } from '../auth/secondaryAuth'
1011
import { getLogger } from '../shared/logger'
1112
import { ToolkitError, isAwsError } from '../shared/errors'
@@ -195,15 +196,12 @@ export class CodeCatalystAuthenticationProvider {
195196
}
196197

197198
public async showReauthenticationPrompt(conn: Connection, isPartialExpiration?: boolean): Promise<void> {
198-
const expiredMessage =
199-
'Connection expired. To continue using CodeCatalyst, connect with AWS Builder ID or AWS IAM Identity center.'
200199
const partiallyExpiredMessage =
201200
'CodeCatalyst connection has expired. Amazon Q/CodeWhisperer is still connected.'
202201

203202
await showReauthenticateMessage({
204-
message: isPartialExpiration ? partiallyExpiredMessage : expiredMessage,
205-
connect: 'Connect with AWS',
206-
doNotShow: "Don't Show Again",
203+
message: isPartialExpiration ? partiallyExpiredMessage : localizedText.connectionExpired('CodeCatalyst'),
204+
connect: localizedText.connect,
207205
suppressId: 'codeCatalystConnectionExpired',
208206
reauthFunc: async () => {
209207
await this.auth.reauthenticate(conn)

packages/core/src/codewhisperer/models/constants.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,6 @@ export const ssoConfigAlertMessageShareData = `This setting doesn\’t apply, si
241241

242242
export const settingsLearnMore = 'Learn More about CodeWhisperer Settings'
243243

244-
export const connectWithAWSBuilderId = `Connect with AWS`
245-
246244
export const freeTierLimitReached = 'You have reached the monthly fair use limit of code recommendations.'
247245

248246
export const freeTierLimitReachedCodeScan = 'You have reached the monthly quota of code scans.'
@@ -260,10 +258,6 @@ export const failedToConnectAwsBuilderId = `Failed to connect to AWS Builder ID`
260258

261259
export const failedToConnectIamIdentityCenter = `Failed to connect to IAM Identity Center`
262260

263-
export const connectionExpired = `Connection expired. To continue using Amazon Q/CodeWhisperer, connect with AWS Builder ID or AWS IAM Identity center.`
264-
265-
export const DoNotShowAgain = `Don\'t Show Again`
266-
267261
export const stopScanMessage =
268262
'Stop security scan? This scan will be counted as one complete scan towards your monthly security scan limits.'
269263

packages/core/src/codewhisperer/util/authUtil.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
import * as vscode from 'vscode'
7-
import * as CodeWhispererConstants from '../models/constants'
7+
import * as localizedText from '../../shared/localizedText'
88
import { Auth } from '../../auth/auth'
99
import { ToolkitError } from '../../shared/errors'
1010
import { getSecondaryAuth } from '../../auth/secondaryAuth'
@@ -367,9 +367,8 @@ export class AuthUtil {
367367
}
368368

369369
await showReauthenticateMessage({
370-
message: CodeWhispererConstants.connectionExpired,
371-
connect: CodeWhispererConstants.connectWithAWSBuilderId,
372-
doNotShow: CodeWhispererConstants.DoNotShowAgain,
370+
message: localizedText.connectionExpired('Amazon Q/CodeWhisperer'),
371+
connect: localizedText.connect,
373372
suppressId: 'codeWhispererConnectionExpired',
374373
reauthFunc: async () => {
375374
await this.reauthenticate()

packages/core/src/shared/localizedText.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ export const dontShow = localize('aws.generic.doNotShowAgain', "Don't Show Again
2626
export const loadMore = localize('AWS.generic.loadMore', 'Load More')
2727
export const learnMore = localize('AWS.generic.learnMore', 'Learn More')
2828
export const proceed = localize('AWS.generic.proceed', 'Proceed')
29+
export const connect = localize('AWS.auth.connect', 'Connect with AWS')
30+
export function connectionExpired(name: string) {
31+
return localize(
32+
'AWS.auth.expired',
33+
'Connection expired. To continue using {0}, connect with AWS Builder ID or AWS IAM Identity center.',
34+
name
35+
)
36+
}
2937

3038
export const checklogs = () =>
3139
localize(

packages/core/src/shared/settings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ export function fromExtensionManifest<T extends TypeDescriptor & Partial<Section
581581
}
582582

583583
const prompts = settingsProps['aws.suppressPrompts'].properties
584-
export type PromptName = keyof typeof prompts
584+
type PromptName = keyof typeof prompts
585585

586586
/**
587587
* Controls flags for prompts that allow the user to hide them. Usually this is presented as

packages/core/src/shared/utilities/messages.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { addCodiconToString } from './textUtilities'
1515
import { getIcon, codicon } from '../icons'
1616
import globals from '../extensionGlobals'
1717
import { openUrl } from './vsCodeUtils'
18-
import { PromptSettings, PromptName } from '../../shared/settings'
18+
import { PromptSettings } from '../../shared/settings'
1919

2020
export const messages = {
2121
editCredentials(icon: boolean) {
@@ -145,21 +145,18 @@ export async function showConfirmationMessage({
145145
*
146146
* @param message the line informing the user that they need to reauthenticate
147147
* @param connect the text to display on the "connect" button
148-
* @param doNotShow the text to display on the "do not show again" button
149148
* @param suppressId the ID of the prompt in
150149
* @param reauthFunc the function called if the "connect" button is clicked
151150
*/
152151
export async function showReauthenticateMessage({
153152
message,
154153
connect,
155-
doNotShow,
156154
suppressId,
157155
reauthFunc,
158156
}: {
159157
message: string
160158
connect: string
161-
doNotShow: string
162-
suppressId: PromptName
159+
suppressId: Parameters<PromptSettings['isPromptEnabled']>[0]
163160
reauthFunc: () => Promise<void>
164161
}) {
165162
const settings = PromptSettings.instance
@@ -168,10 +165,10 @@ export async function showReauthenticateMessage({
168165
return
169166
}
170167

171-
await vscode.window.showInformationMessage(message, connect, doNotShow).then(async resp => {
168+
await vscode.window.showInformationMessage(message, connect, localizedText.dontShow).then(async resp => {
172169
if (resp === connect) {
173170
await reauthFunc()
174-
} else if (resp === doNotShow) {
171+
} else if (resp === localizedText.dontShow) {
175172
await settings.disablePrompt(suppressId)
176173
}
177174
})

0 commit comments

Comments
 (0)