Skip to content

Commit d4838ed

Browse files
l0minousDiler Zaza
authored andcommitted
fix(stepfunctions): Add document URI check for save telemetry and enable deployment from WFS (aws#7315)
## Problem - Save telemetry was being recorded for all document saves in VS Code, not just for the active workflow studio document. - Save & Deploy functionality required closing Workflow Studio before starting deployment ## Solution - Add URI comparison check to ensure telemetry is only recorded when the saved document matches the current workflow studio document. - Refactored publishStateMachine.ts to accept an optional TextDocument parameter and updated activation.ts to support new interface - Removed closeCustomEditorMessageHandler call from saveFileAndDeployMessageHandler --- - Treat all work as PUBLIC. Private `feature/x` branches will not be squash-merged at release time. - Your code changes must meet the guidelines in [CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). - License: I confirm that my contribution is made under the terms of the Apache 2.0 license. --------- Co-authored-by: Diler Zaza <zazadile@amazon.com>
1 parent cfc8229 commit d4838ed

File tree

6 files changed

+45
-21
lines changed

6 files changed

+45
-21
lines changed

packages/core/src/stepFunctions/activation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ async function registerStepFunctionCommands(
9696
}),
9797
Commands.register('aws.stepfunctions.publishStateMachine', async (node?: any) => {
9898
const region: string | undefined = node?.regionCode
99-
await publishStateMachine(awsContext, outputChannel, region)
99+
await publishStateMachine({ awsContext: awsContext, outputChannel: outputChannel, region: region })
100100
})
101101
)
102102
}

packages/core/src/stepFunctions/commands/publishStateMachine.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,21 @@ import { refreshStepFunctionsTree } from '../explorer/stepFunctionsNodes'
1515
import { PublishStateMachineWizard, PublishStateMachineWizardState } from '../wizards/publishStateMachineWizard'
1616
const localize = nls.loadMessageBundle()
1717

18-
export async function publishStateMachine(
19-
awsContext: AwsContext,
20-
outputChannel: vscode.OutputChannel,
18+
interface publishStateMachineParams {
19+
awsContext: AwsContext
20+
outputChannel: vscode.OutputChannel
2121
region?: string
22-
) {
22+
text?: vscode.TextDocument
23+
}
24+
export async function publishStateMachine(params: publishStateMachineParams) {
2325
const logger: Logger = getLogger()
26+
let textDocument: vscode.TextDocument | undefined
2427

25-
const textDocument = vscode.window.activeTextEditor?.document
28+
if (params.text) {
29+
textDocument = params.text
30+
} else {
31+
textDocument = vscode.window.activeTextEditor?.document
32+
}
2633

2734
if (!textDocument) {
2835
logger.error('Could not get active text editor for state machine definition')
@@ -53,17 +60,17 @@ export async function publishStateMachine(
5360
}
5461

5562
try {
56-
const response = await new PublishStateMachineWizard(region).run()
63+
const response = await new PublishStateMachineWizard(params.region).run()
5764
if (!response) {
5865
return
5966
}
6067
const client = new DefaultStepFunctionsClient(response.region)
6168

6269
if (response?.createResponse) {
63-
await createStateMachine(response.createResponse, text, outputChannel, response.region, client)
70+
await createStateMachine(response.createResponse, text, params.outputChannel, response.region, client)
6471
refreshStepFunctionsTree(response.region)
6572
} else if (response?.updateResponse) {
66-
await updateStateMachine(response.updateResponse, text, outputChannel, response.region, client)
73+
await updateStateMachine(response.updateResponse, text, params.outputChannel, response.region, client)
6774
}
6875
} catch (err) {
6976
logger.error(err as Error)

packages/core/src/stepFunctions/workflowStudio/handleMessage.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,22 @@ async function saveFileMessageHandler(request: SaveFileRequestMessage, context:
202202
}
203203

204204
/**
205-
* Handler for saving a file and starting the state machine deployment flow, while also switching to default editor.
205+
* Handler for saving a file and starting the state machine deployment flow while staying in WFS view.
206206
* Triggered when the user triggers 'Save and Deploy' action in WFS
207207
* @param request The request message containing the file contents.
208208
* @param context The webview context containing the necessary information for saving the file.
209209
*/
210210
async function saveFileAndDeployMessageHandler(request: SaveFileRequestMessage, context: WebviewContext) {
211211
await saveFileMessageHandler(request, context)
212-
await closeCustomEditorMessageHandler(context)
213-
await publishStateMachine(globals.awsContext, globals.outputChannel)
212+
await publishStateMachine({
213+
awsContext: globals.awsContext,
214+
outputChannel: globals.outputChannel,
215+
text: context.textDocument,
216+
})
217+
218+
telemetry.ui_click.emit({
219+
elementId: 'stepfunctions_saveAndDeploy',
220+
})
214221
}
215222

216223
/**

packages/core/src/stepFunctions/workflowStudio/workflowStudioEditor.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -147,16 +147,18 @@ export class WorkflowStudioEditor {
147147

148148
// The text document acts as our model, thus we send and event to the webview on file save to trigger update
149149
contextObject.disposables.push(
150-
vscode.workspace.onDidSaveTextDocument(async () => {
151-
await telemetry.stepfunctions_saveFile.run(async (span) => {
152-
span.record({
153-
id: contextObject.fileId,
154-
saveType: 'MANUAL_SAVE',
155-
source: 'VSCODE',
156-
isInvalidJson: isInvalidJsonFile(contextObject.textDocument),
150+
vscode.workspace.onDidSaveTextDocument(async (savedDocument) => {
151+
if (savedDocument.uri.toString() === this.documentUri.toString()) {
152+
await telemetry.stepfunctions_saveFile.run(async (span) => {
153+
span.record({
154+
id: contextObject.fileId,
155+
saveType: 'MANUAL_SAVE',
156+
source: 'VSCODE',
157+
isInvalidJson: isInvalidJsonFile(contextObject.textDocument),
158+
})
159+
await broadcastFileChange(contextObject, 'MANUAL_SAVE')
157160
})
158-
await broadcastFileChange(contextObject, 'MANUAL_SAVE')
159-
})
161+
}
160162
})
161163
)
162164

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Bug Fix",
3+
"description": "State Machine deployments can now be initiated directly from Workflow Studio without closing the editor"
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Bug Fix",
3+
"description": "Step Function performance metrics now accurately reflect only Workflow Studio document activity"
4+
}

0 commit comments

Comments
 (0)