Skip to content

Commit d8042b2

Browse files
author
Diler Zaza
committed
adding helper functions amd adjusting tests
1 parent ddbe09b commit d8042b2

File tree

6 files changed

+157
-193
lines changed

6 files changed

+157
-193
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ export async function downloadStateMachineDefinition(params: {
3535
})
3636

3737
if (params.isPreviewAndRender) {
38-
await openWorkflowStudioWithDefinition(stateMachineDetails.definition)
38+
await openWorkflowStudioWithDefinition(stateMachineDetails.definition, {
39+
preserveFocus: true,
40+
viewColumn: vscode.ViewColumn.Beside,
41+
})
3942
} else {
4043
const wsPath = vscode.workspace.workspaceFolders
4144
? vscode.workspace.workspaceFolders[0].uri.fsPath

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class ExecutionDetailProvider {
3535
const panel = vscode.window.createWebviewPanel(
3636
ExecutionDetailProvider.viewType,
3737
`Execution: ${executionArn.split(':').pop() || executionArn}`,
38-
vscode.ViewColumn.Beside,
38+
vscode.ViewColumn.One,
3939
{
4040
enableScripts: true,
4141
retainContextWhenHidden: true,

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

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

7-
import * as nls from 'vscode-nls'
8-
const localize = nls.loadMessageBundle()
97
import {
108
Command,
119
Message,
@@ -19,10 +17,8 @@ import {
1917
handleUnsupportedMessage,
2018
apiCallMessageHandler,
2119
} from '../messageHandlers/handleMessageHelpers'
22-
import { parseExecutionArnForStateMachine, openWorkflowStudio } from '../utils'
23-
import { ExecuteStateMachineWebview } from '../vue/executeStateMachine/executeStateMachine'
24-
import { VueWebview } from '../../webviews/main'
25-
import globals from '../../shared/extensionGlobals'
20+
import { parseExecutionArnForStateMachine, openWorkflowStudio, showExecuteStateMachineWebview } from '../utils'
21+
import { getLogger } from '../../shared/logger/logger'
2622

2723
/**
2824
* Handles messages received from the ExecutionDetails webview. Depending on the message type and command,
@@ -88,25 +84,24 @@ async function initMessageHandler(context: ExecutionDetailsContext) {
8884
}
8985

9086
async function startExecutionMessageHandler(context: ExecutionDetailsContext) {
91-
// Parsing execution ARN to get state machine info
92-
const parsedArn = parseExecutionArnForStateMachine(context.executionArn)
93-
if (!parsedArn) {
94-
throw new Error(`Invalid execution ARN format: ${context.executionArn}`)
95-
}
96-
97-
const { region, stateMachineName, stateMachineArn } = parsedArn
87+
const logger = getLogger('stepfunctions')
88+
try {
89+
// Parsing execution ARN to get state machine info
90+
const parsedArn = parseExecutionArnForStateMachine(context.executionArn)
91+
if (!parsedArn) {
92+
throw new Error(`Invalid execution ARN format: ${context.executionArn}`)
93+
}
9894

99-
const Panel = VueWebview.compilePanel(ExecuteStateMachineWebview)
100-
const wv = new Panel(globals.context, globals.outputChannel, {
101-
arn: stateMachineArn,
102-
name: stateMachineName,
103-
region: region,
104-
})
95+
const { region, stateMachineName, stateMachineArn } = parsedArn
10596

106-
await wv.show({
107-
title: localize('AWS.executeStateMachine.title', 'Start Execution'),
108-
cssFiles: ['executeStateMachine.css'],
109-
})
97+
await showExecuteStateMachineWebview({
98+
arn: stateMachineArn,
99+
name: stateMachineName,
100+
region: region,
101+
})
102+
} catch (error) {
103+
logger.error('Start execution failed: %O', error)
104+
}
110105
}
111106

112107
async function editStateMachineMessageHandler(context: ExecutionDetailsContext) {

packages/core/src/stepFunctions/utils.ts

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ import {
1818
import { fromExtensionManifest } from '../shared/settings'
1919
import { IamRole } from '../shared/clients/iam'
2020
import { WorkflowStudioEditorProvider } from './workflowStudio/workflowStudioEditorProvider'
21+
import { VueWebview } from '../webviews/main'
22+
import { ExecuteStateMachineWebview } from './vue/executeStateMachine/executeStateMachine'
23+
import globals from '../shared/extensionGlobals'
2124

2225
const documentSettings: DocumentLanguageSettings = { comments: 'error', trailingCommas: 'error' }
2326
const languageService = getLanguageService({})
@@ -149,20 +152,52 @@ export const openWorkflowStudio = async (stateMachineArn: string, region: string
149152
/**
150153
* Opens a state machine definition in Workflow Studio using pre-fetched definition content
151154
* @param definition The state machine definition content
155+
* @param options Optional webview configuration options
152156
*/
153-
export const openWorkflowStudioWithDefinition = async (definition: string | undefined) => {
157+
export const openWorkflowStudioWithDefinition = async (
158+
definition: string | undefined,
159+
preserveFocus?: boolean,
160+
viewColumn?: vscode.ViewColumn
161+
) => {
154162
const doc = await vscode.workspace.openTextDocument({
155163
language: 'asl',
156164
content: definition,
157165
})
158166

159167
const textEditor = await vscode.window.showTextDocument(doc)
160168
await WorkflowStudioEditorProvider.openWithWorkflowStudio(textEditor.document.uri, {
161-
preserveFocus: false,
162-
viewColumn: vscode.ViewColumn.One,
169+
preserveFocus: preserveFocus ?? false,
170+
viewColumn: viewColumn ?? vscode.ViewColumn.One,
163171
})
164172
}
165173

174+
/**
175+
* Shows the Execute State Machine webview with the provided state machine data
176+
* @param extensionContext The extension context
177+
* @param outputChannel The output channel for logging
178+
* @param stateMachineData Object containing arn, name, and region of the state machine
179+
* @returns The webview instance
180+
*/
181+
export const showExecuteStateMachineWebview = async (stateMachineData: {
182+
arn: string
183+
name: string
184+
region: string
185+
}) => {
186+
const Panel = VueWebview.compilePanel(ExecuteStateMachineWebview)
187+
const wv = new Panel(globals.context, globals.outputChannel, {
188+
arn: stateMachineData.arn,
189+
name: stateMachineData.name,
190+
region: stateMachineData.region,
191+
})
192+
193+
await wv.show({
194+
title: localize('AWS.executeStateMachine.title', 'Start Execution'),
195+
cssFiles: ['executeStateMachine.css'],
196+
})
197+
198+
return wv
199+
}
200+
166201
const isInvalidJson = (content: string): boolean => {
167202
try {
168203
JSON.parse(content)

packages/core/src/stepFunctions/vue/executeStateMachine/executeStateMachine.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { VueWebview } from '../../../webviews/main'
1616
import * as vscode from 'vscode'
1717
import { telemetry } from '../../../shared/telemetry/telemetry'
1818
import { ExecutionDetailProvider } from '../../executionDetails/executionDetailProvider'
19+
import { showExecuteStateMachineWebview } from '../../utils'
1920

2021
interface StateMachine {
2122
arn: string
@@ -88,18 +89,11 @@ export class ExecuteStateMachineWebview extends VueWebview {
8889
}
8990
}
9091

91-
const Panel = VueWebview.compilePanel(ExecuteStateMachineWebview)
92-
9392
export async function executeStateMachine(context: ExtContext, node: StateMachineNode): Promise<void> {
94-
const wv = new Panel(context.extensionContext, context.outputChannel, {
93+
await showExecuteStateMachineWebview({
9594
arn: node.details.stateMachineArn || '',
9695
name: node.details.name || '',
9796
region: node.regionCode,
9897
})
99-
100-
await wv.show({
101-
title: localize('AWS.executeStateMachine.title', 'Start Execution'),
102-
cssFiles: ['executeStateMachine.css'],
103-
})
10498
telemetry.stepfunctions_executeStateMachineView.emit()
10599
}

0 commit comments

Comments
 (0)