Skip to content

Commit 0ebd669

Browse files
author
Zelin Zhou
committed
feat: fill existing ExecutionInput when start new execution from ExecutionDetails tab.
1 parent 9a7cd5b commit 0ebd669

File tree

5 files changed

+35
-6
lines changed

5 files changed

+35
-6
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
ExecutionDetailsContext,
1212
ApiCallRequestMessage,
1313
InitResponseMessage,
14+
StartExecutionMessage,
1415
} from '../messageHandlers/types'
1516
import {
1617
loadStageMessageHandler,
@@ -39,7 +40,7 @@ export async function handleMessage(message: Message, context: ExecutionDetailsC
3940
break
4041
}
4142
case Command.START_EXECUTION:
42-
void startExecutionMessageHandler(context)
43+
void startExecutionMessageHandler(message as StartExecutionMessage, context)
4344
break
4445
case Command.EDIT_STATE_MACHINE:
4546
void editStateMachineMessageHandler(context)
@@ -85,7 +86,7 @@ async function initMessageHandler(context: ExecutionDetailsContext) {
8586
}
8687
}
8788

88-
async function startExecutionMessageHandler(context: ExecutionDetailsContext) {
89+
async function startExecutionMessageHandler(message: StartExecutionMessage, context: ExecutionDetailsContext) {
8990
const logger = getLogger('stepfunctions')
9091
try {
9192
// Parsing execution ARN to get state machine info
@@ -100,6 +101,7 @@ async function startExecutionMessageHandler(context: ExecutionDetailsContext) {
100101
arn: stateMachineArn,
101102
name: stateMachineName,
102103
region: region,
104+
executionInput: message.executionInput,
103105
})
104106
} catch (error) {
105107
logger.error('Start execution failed: %O', error)

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ export interface SyncFileRequestMessage extends SaveFileRequestMessage {
105105
fileContents: string
106106
}
107107

108+
export interface StartExecutionMessage extends Message {
109+
executionInput?: string
110+
}
111+
108112
export enum ApiAction {
109113
IAMListRoles = 'iam:ListRoles',
110114
SFNTestState = 'sfn:TestState',

packages/core/src/stepFunctions/utils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,19 +177,21 @@ export const openWorkflowStudioWithDefinition = async (
177177
* Shows the Execute State Machine webview with the provided state machine data
178178
* @param extensionContext The extension context
179179
* @param outputChannel The output channel for logging
180-
* @param stateMachineData Object containing arn, name, and region of the state machine
180+
* @param stateMachineData Object containing arn, name, region, and optional executionInput of the state machine
181181
* @returns The webview instance
182182
*/
183183
export const showExecuteStateMachineWebview = async (stateMachineData: {
184184
arn: string
185185
name: string
186186
region: string
187+
executionInput?: string
187188
}) => {
188189
const Panel = VueWebview.compilePanel(ExecuteStateMachineWebview)
189190
const wv = new Panel(globals.context, globals.outputChannel, {
190191
arn: stateMachineData.arn,
191192
name: stateMachineData.name,
192193
region: stateMachineData.region,
194+
executionInput: stateMachineData.executionInput,
193195
})
194196

195197
await wv.show({

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ interface StateMachine {
2222
arn: string
2323
name: string
2424
region: string
25+
executionInput?: string
2526
}
2627

2728
export class ExecuteStateMachineWebview extends VueWebview {
@@ -89,11 +90,16 @@ export class ExecuteStateMachineWebview extends VueWebview {
8990
}
9091
}
9192

92-
export async function executeStateMachine(context: ExtContext, node: StateMachineNode): Promise<void> {
93+
export async function executeStateMachine(
94+
context: ExtContext,
95+
node: StateMachineNode,
96+
executionInput?: string
97+
): Promise<void> {
9398
await showExecuteStateMachineWebview({
9499
arn: node.details.stateMachineArn || '',
95100
name: node.details.name || '',
96101
region: node.regionCode,
102+
executionInput,
97103
})
98104
telemetry.stepfunctions_executeStateMachineView.emit()
99105
}

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,15 @@ const defaultInitialData = {
5555
name: '',
5656
region: '',
5757
arn: '',
58+
executionInput: '',
5859
}
5960
6061
export default defineComponent({
6162
async created() {
6263
this.initialData = (await client.init()) ?? this.initialData
64+
if (this.initialData.executionInput) {
65+
this.executionInput = this.formatJson(this.initialData.executionInput)
66+
}
6367
},
6468
data: () => ({
6569
initialData: defaultInitialData,
@@ -89,7 +93,9 @@ export default defineComponent({
8993
break
9094
case 'textarea':
9195
this.placeholderJson = defaultJsonPlaceholder
92-
this.executionInput = ''
96+
if (!this.initialData.executionInput) {
97+
this.executionInput = ''
98+
}
9399
this.fileInputVisible = false
94100
break
95101
}
@@ -104,7 +110,7 @@ export default defineComponent({
104110
reader.onload = (event) => {
105111
if (event.target) {
106112
const result = event.target.result
107-
this.executionInput = result as string
113+
this.executionInput = this.formatJson(result as string)
108114
}
109115
} // desired file content
110116
reader.onerror = (error) => {
@@ -115,6 +121,15 @@ export default defineComponent({
115121
this.textAreaVisible = true
116122
}
117123
},
124+
formatJson: function (jsonString: string): string {
125+
try {
126+
const parsed = JSON.parse(jsonString)
127+
return JSON.stringify(parsed, null, 2)
128+
} catch (error) {
129+
console.warn('Failed to format JSON:', error)
130+
return jsonString
131+
}
132+
},
118133
sendInput: function () {
119134
client.executeStateMachine(this.executionInput || '{}')
120135
},

0 commit comments

Comments
 (0)