Skip to content

Commit 49d317d

Browse files
author
Diler Zaza
committed
handling newExecution and editStateMachine messages
1 parent e75caf3 commit 49d317d

File tree

6 files changed

+305
-12
lines changed

6 files changed

+305
-12
lines changed

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

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { Result } from '../../shared/telemetry/telemetry'
1717
import { StateMachineNode } from '../explorer/stepFunctionsNodes'
1818
import { telemetry } from '../../shared/telemetry/telemetry'
1919
import { fs } from '../../shared/fs/fs'
20-
import { WorkflowStudioEditorProvider } from '../workflowStudio/workflowStudioEditorProvider'
20+
import { openWorkflowStudioWithDefinition } from '../utils'
2121

2222
export async function downloadStateMachineDefinition(params: {
2323
outputChannel: vscode.OutputChannel
@@ -35,16 +35,7 @@ export async function downloadStateMachineDefinition(params: {
3535
})
3636

3737
if (params.isPreviewAndRender) {
38-
const doc = await vscode.workspace.openTextDocument({
39-
language: 'asl',
40-
content: stateMachineDetails.definition,
41-
})
42-
43-
const textEditor = await vscode.window.showTextDocument(doc)
44-
await WorkflowStudioEditorProvider.openWithWorkflowStudio(textEditor.document.uri, {
45-
preserveFocus: true,
46-
viewColumn: vscode.ViewColumn.Beside,
47-
})
38+
await openWorkflowStudioWithDefinition(stateMachineDetails.definition)
4839
} else {
4940
const wsPath = vscode.workspace.workspaceFolders
5041
? vscode.workspace.workspaceFolders[0].uri.fsPath

packages/core/src/stepFunctions/executionDetails/executionDetailProvider.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ export class ExecutionDetailProvider {
9696
* Initializes a WebView panel with execution details.
9797
* @param panel The WebView panel to initialize
9898
* @param executionArn The ARN of the execution to display
99+
* @param startTime Optional start time for the execution
99100
*/
100101
public async initializePanel(panel: vscode.WebviewPanel, executionArn: string, startTime?: string): Promise<void> {
101102
try {

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7+
import * as nls from 'vscode-nls'
8+
const localize = nls.loadMessageBundle()
79
import {
810
Command,
911
Message,
@@ -17,6 +19,12 @@ import {
1719
handleUnsupportedMessage,
1820
apiCallMessageHandler,
1921
} from '../messageHandlers/handleMessageHelpers'
22+
import { parseExecutionArnForStateMachine, openWFSfromARN } from '../utils'
23+
import { ExecuteStateMachineWebview } from '../vue/executeStateMachine/executeStateMachine'
24+
import { VueWebview } from '../../webviews/main'
25+
import globals from '../../shared/extensionGlobals'
26+
// import { ExecutionDetailProvider } from './executionDetailProvider'
27+
// import { WorkflowStudioEditorProvider } from '../workflowStudio/workflowStudioEditorProvider'
2028

2129
/**
2230
* Handles messages received from the ExecutionDetails webview. Depending on the message type and command,
@@ -34,6 +42,12 @@ export async function handleMessage(message: Message, context: ExecutionDetailsC
3442
case Command.API_CALL:
3543
void apiCallMessageHandler(message as ApiCallRequestMessage, context)
3644
break
45+
case Command.START_EXECUTION:
46+
void startExecutionMessageHandler(context)
47+
break
48+
case Command.EDIT_STATE_MACHINE:
49+
void editStateMachineMessageHandler(context)
50+
break
3751
default:
3852
void handleUnsupportedMessage(context, message)
3953
break
@@ -74,3 +88,24 @@ async function initMessageHandler(context: ExecutionDetailsContext) {
7488
} as InitResponseMessage)
7589
}
7690
}
91+
92+
async function startExecutionMessageHandler(context: ExecutionDetailsContext) {
93+
// Parsing execution ARN to get state machine info
94+
const { region, stateMachineName, stateMachineArn } = parseExecutionArnForStateMachine(context.executionArn)
95+
96+
const Panel = VueWebview.compilePanel(ExecuteStateMachineWebview)
97+
const wv = new Panel(globals.context, globals.outputChannel, {
98+
arn: stateMachineArn,
99+
name: stateMachineName,
100+
region: region,
101+
})
102+
103+
await wv.show({
104+
title: localize('AWS.executeStateMachine.title', 'Start Execution'),
105+
cssFiles: ['executeStateMachine.css'],
106+
})
107+
}
108+
109+
async function editStateMachineMessageHandler(context: ExecutionDetailsContext) {
110+
await openWFSfromARN(context)
111+
}

packages/core/src/stepFunctions/messageHandlers/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ export enum Command {
6666
CLOSE_WFS = 'CLOSE_WFS',
6767
API_CALL = 'API_CALL',
6868
UNSUPPORTED_COMMAND = 'UNSUPPORTED_COMMAND',
69+
START_EXECUTION = 'START_EXECUTION',
70+
EDIT_STATE_MACHINE = 'EDIT_STATE_MACHINE',
6971
}
7072

7173
export type FileWatchInfo = {

packages/core/src/stepFunctions/utils.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,17 @@ import {
1717
} from 'amazon-states-language-service'
1818
import { fromExtensionManifest } from '../shared/settings'
1919
import { IamRole } from '../shared/clients/iam'
20+
import { ExecutionDetailsContext } from './messageHandlers/types'
21+
import { WorkflowStudioEditorProvider } from './workflowStudio/workflowStudioEditorProvider'
2022

2123
const documentSettings: DocumentLanguageSettings = { comments: 'error', trailingCommas: 'error' }
2224
const languageService = getLanguageService({})
2325

2426
const arnResourceTypeSegmentIndex = 5
2527
const expressExecutionArnSegmentCount = 9
28+
const arnRegionSegmentIndex = 3
29+
const arnAccountIdSegmentIndex = 4
30+
const arnStateMachineNameSegmentIndex = 6
2631

2732
export async function* listStateMachines(
2833
client: StepFunctionsClient
@@ -107,6 +112,60 @@ export const isExpressExecution = (arn: string): boolean => {
107112
)
108113
}
109114

115+
/**
116+
* Parses an execution ARN to extract state machine information
117+
* @param executionArn The execution ARN to parse
118+
* @returns Object containing region, state machine name, and state machine ARN
119+
*/
120+
export const parseExecutionArnForStateMachine = (executionArn: string) => {
121+
const arnSegments = executionArn.split(':')
122+
const region = arnSegments[arnRegionSegmentIndex]
123+
const stateMachineName = arnSegments[arnStateMachineNameSegmentIndex]
124+
const stateMachineArn = `arn:aws:states:${region}:${arnSegments[arnAccountIdSegmentIndex]}:stateMachine:${stateMachineName}`
125+
126+
return {
127+
region,
128+
stateMachineName,
129+
stateMachineArn,
130+
}
131+
}
132+
133+
/**
134+
* Opens a state machine definition in Workflow Studio
135+
* @param stateMachineArn The ARN of the state machine
136+
* @param region The AWS region
137+
*/
138+
export const openWorkflowStudio = async (stateMachineArn: string, region: string) => {
139+
const client: StepFunctionsClient = new StepFunctionsClient(region)
140+
const stateMachineDetails: StepFunctions.DescribeStateMachineCommandOutput = await client.getStateMachineDetails({
141+
stateMachineArn,
142+
})
143+
144+
await openWorkflowStudioWithDefinition(stateMachineDetails.definition)
145+
}
146+
147+
/**
148+
* Opens a state machine definition in Workflow Studio using pre-fetched definition content
149+
* @param definition The state machine definition content
150+
*/
151+
export const openWorkflowStudioWithDefinition = async (definition: string | undefined) => {
152+
const doc = await vscode.workspace.openTextDocument({
153+
language: 'asl',
154+
content: definition,
155+
})
156+
157+
const textEditor = await vscode.window.showTextDocument(doc)
158+
await WorkflowStudioEditorProvider.openWithWorkflowStudio(textEditor.document.uri, {
159+
preserveFocus: true,
160+
viewColumn: vscode.ViewColumn.Beside,
161+
})
162+
}
163+
164+
export const openWFSfromARN = async (context: ExecutionDetailsContext) => {
165+
const params = parseExecutionArnForStateMachine(context.executionArn)
166+
await openWorkflowStudio(params.stateMachineArn, params.region)
167+
}
168+
110169
const isInvalidJson = (content: string): boolean => {
111170
try {
112171
JSON.parse(content)

0 commit comments

Comments
 (0)