Skip to content

Commit 3ee7bf2

Browse files
l0minousDiler Zaza
andauthored
feat(stepfunctions): add View by Execution ARN command and provider (#7526)
## Problem Execution Details cannot be launched / View by Execution ARN isn't supported ## Solution - Added aws.stepfunctions.viewExecutionDetailsByExecutionARN command to package.json and package.nls.json - Implemented `ExecutionDetailProvider` to open execution details in a dedicated webview panel - Added ExecutionDetailProvider.openExecutionDetails call to activation.ts for viewExecutionDetailsByExecutionARN command --- - 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 <[email protected]>
1 parent a4a18df commit 3ee7bf2

File tree

8 files changed

+152
-5
lines changed

8 files changed

+152
-5
lines changed

packages/core/package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"AWS.stepFunctions.executeStateMachine.info.executing": "Starting execution of '{0}' in {1}...",
3333
"AWS.stepFunctions.executeStateMachine.info.started": "Execution started",
3434
"AWS.stepFunctions.executeStateMachine.error.failedToStart": "There was an error starting execution for '{0}', check AWS Toolkit logs for more information.",
35+
"AWS.stepfunctions.viewExecutionDetailsByExecutionARN": "View Execution Details by Execution ARN",
3536
"AWS.stepFunctions.asl.format.enable.desc": "Enables the default formatter used with Amazon States Language files",
3637
"AWS.stepFunctions.asl.maxItemsComputed.desc": "The maximum number of outline symbols and folding regions computed (limited for performance reasons).",
3738
"AWS.stepFunctions.workflowStudio.actions.progressMessage": "Opening asl file in Workflow Studio",

packages/core/src/stepFunctions/activation.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { ASLLanguageClient } from './asl/client'
2323
import { WorkflowStudioEditorProvider } from './workflowStudio/workflowStudioEditorProvider'
2424
import { StateMachineNode } from './explorer/stepFunctionsNodes'
2525
import { downloadStateMachineDefinition } from './commands/downloadStateMachineDefinition'
26+
import { ExecutionDetailProvider } from './executionDetails/executionDetailProvider'
2627

2728
/**
2829
* Activate Step Functions related functionality for the extension.
@@ -97,6 +98,9 @@ async function registerStepFunctionCommands(
9798
Commands.register('aws.stepfunctions.publishStateMachine', async (node?: any) => {
9899
const region: string | undefined = node?.regionCode
99100
await publishStateMachine(awsContext, outputChannel, region)
101+
}),
102+
Commands.register('aws.stepfunctions.viewExecutionDetailsByExecutionARN', async () => {
103+
await ExecutionDetailProvider.openExecutionDetails('')
100104
})
101105
)
102106
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/*!
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
export const isLocalDev = true
7+
export const localhost = 'http://127.0.0.1:3002'
8+
export const cdn = 'https://d5t62uwepi9lu.cloudfront.net'
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*!
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import * as vscode from 'vscode'
7+
import { getLogger } from '../../shared/logger/logger'
8+
import request from '../../shared/request'
9+
import { ToolkitError } from '../../shared/errors'
10+
import { i18n } from '../../shared/i18n-helper'
11+
import { ComponentType } from '../workflowStudio/types'
12+
import { isLocalDev, localhost, cdn } from '../constants/webviewResources'
13+
14+
/**
15+
* Provider for Execution Details panels.
16+
*
17+
* Execution Details displays information about state machine executions in a WebView panel.
18+
*/
19+
export class ExecutionDetailProvider {
20+
public static readonly viewType = 'stepfunctions.executionDetails'
21+
22+
/**
23+
* Opens execution details in a WebView panel.
24+
* @param executionArn The ARN of the execution to display details for
25+
* @param params Optional parameters to customize the WebView panel
26+
*/
27+
public static async openExecutionDetails(
28+
executionArn: string,
29+
params?: vscode.WebviewPanelOptions & vscode.WebviewOptions
30+
): Promise<void> {
31+
// Create and show the webview panel
32+
const panel = vscode.window.createWebviewPanel(
33+
ExecutionDetailProvider.viewType,
34+
`Execution: ${executionArn.split(':').pop() || executionArn}`,
35+
vscode.ViewColumn.Beside,
36+
{
37+
enableScripts: true,
38+
retainContextWhenHidden: true,
39+
...params,
40+
}
41+
)
42+
// Create the provider and initialize the panel
43+
const provider = new ExecutionDetailProvider()
44+
await provider.initializePanel(panel, executionArn)
45+
}
46+
47+
protected webviewHtml: string
48+
protected readonly logger = getLogger()
49+
50+
constructor() {
51+
this.webviewHtml = ''
52+
}
53+
54+
/**
55+
* Fetches the webview HTML from the CDN or local server.
56+
* @private
57+
*/
58+
private async fetchWebviewHtml(): Promise<void> {
59+
const source = isLocalDev ? localhost : cdn
60+
const response = await request.fetch('GET', `${source}/index.html`).response
61+
this.webviewHtml = await response.text()
62+
}
63+
64+
/**
65+
* Gets the webview content for Execution Details.
66+
* @private
67+
*/
68+
private getWebviewContent = async (): Promise<string> => {
69+
const htmlFileSplit = this.webviewHtml.split('<head>')
70+
71+
// Set asset source to CDN
72+
const source = isLocalDev ? localhost : cdn
73+
const baseTag = `<base href='${source}'/>`
74+
75+
// Set locale, dark mode
76+
const locale = vscode.env.language
77+
const localeTag = `<meta name='locale' content='${locale}'>`
78+
const theme = vscode.window.activeColorTheme.kind
79+
const isDarkMode = theme === vscode.ColorThemeKind.Dark || theme === vscode.ColorThemeKind.HighContrast
80+
const darkModeTag = `<meta name='dark-mode' content='${isDarkMode}'>`
81+
82+
// Set component type to ExecutionDetails
83+
const componentTypeTag = `<meta name="component-type" content="${ComponentType.ExecutionDetails}" />`
84+
85+
return `${htmlFileSplit[0]} <head> ${baseTag} ${localeTag} ${darkModeTag} ${componentTypeTag} ${htmlFileSplit[1]}`
86+
}
87+
88+
/**
89+
* Initializes a WebView panel with execution details.
90+
* @param panel The WebView panel to initialize
91+
* @param executionArn The ARN of the execution to display
92+
*/
93+
public async initializePanel(panel: vscode.WebviewPanel, executionArn: string): Promise<void> {
94+
try {
95+
if (!this.webviewHtml) {
96+
await this.fetchWebviewHtml()
97+
}
98+
99+
// Set up the content
100+
panel.webview.html = await this.getWebviewContent()
101+
102+
// Handle messages from the webview
103+
panel.webview.onDidReceiveMessage(async (message) => {
104+
this.logger.debug('Received message from execution details webview: %O', message)
105+
// Add message handlers as needed
106+
})
107+
} catch (err) {
108+
void vscode.window.showErrorMessage(i18n('AWS.stepFunctions.executionDetails.failed'))
109+
throw ToolkitError.chain(err, 'Could not open Execution Details', { code: 'OpenExecutionDetailsFailed' })
110+
}
111+
}
112+
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
import { IAM, StepFunctions } from 'aws-sdk'
66
import * as vscode from 'vscode'
77

8+
export enum ComponentType {
9+
WorkflowStudio = 'WorkflowStudio',
10+
ExecutionDetails = 'ExecutionDetails',
11+
}
12+
813
export enum WorkflowMode {
914
Editable = 'toolkit',
1015
Readonly = 'readonly',

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@ import { getTabSizeSetting } from '../../shared/utilities/editorUtilities'
1515
import { WorkflowStudioEditor } from './workflowStudioEditor'
1616
import { i18n } from '../../shared/i18n-helper'
1717
import { isInvalidJsonFile, isInvalidYamlFile } from '../utils'
18-
import { WorkflowMode } from './types'
18+
import { ComponentType, WorkflowMode } from './types'
19+
import { isLocalDev, localhost, cdn } from '../constants/webviewResources'
1920

20-
const isLocalDev = false
21-
const localhost = 'http://127.0.0.1:3002'
22-
const cdn = 'https://d5t62uwepi9lu.cloudfront.net'
2321
let clientId = ''
2422

2523
/**
@@ -133,7 +131,11 @@ export class WorkflowStudioEditorProvider implements vscode.CustomTextEditorProv
133131
const darkModeTag = `<meta name='dark-mode' content='${isDarkMode}'>`
134132

135133
const modeTag = `<meta name="workflow-mode" content="${mode}" />`
136-
return `${htmlFileSplit[0]} <head> ${baseTag} ${localeTag} ${darkModeTag} ${tabSizeTag} ${modeTag} ${htmlFileSplit[1]}`
134+
135+
// Set component type to WorkflowStudio
136+
const componentTypeTag = `<meta name="component-type" content="${ComponentType.WorkflowStudio}" />`
137+
138+
return `${htmlFileSplit[0]} <head> ${baseTag} ${localeTag} ${darkModeTag} ${tabSizeTag} ${modeTag} ${componentTypeTag} ${htmlFileSplit[1]}`
137139
}
138140

139141
/**
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Feature",
3+
"description": "Added view by execution ARN command to visualize an execution"
4+
}

packages/toolkit/package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3384,6 +3384,17 @@
33843384
}
33853385
}
33863386
},
3387+
{
3388+
"command": "aws.stepfunctions.viewExecutionDetailsByExecutionARN",
3389+
"title": "%AWS.command.stepFunctions.viewExecutionDetailsByExecutionARN%",
3390+
"category": "%AWS.title%",
3391+
"enablement": "isCloud9 || !aws.isWebExtHost",
3392+
"cloud9": {
3393+
"cn": {
3394+
"category": "%AWS.title.cn%"
3395+
}
3396+
}
3397+
},
33873398
{
33883399
"command": "aws.cdk.renderStateMachineGraph",
33893400
"title": "%AWS.command.cdk.previewStateMachine%",

0 commit comments

Comments
 (0)