Skip to content

Commit 4f2d74e

Browse files
author
Diler Zaza
committed
feat(stepfunctions): add provider file for new entry point and webview
1 parent 8f116c5 commit 4f2d74e

File tree

2 files changed

+155
-0
lines changed

2 files changed

+155
-0
lines changed

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: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
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 { getClientId } from '../../shared/telemetry/util'
10+
import { telemetry } from '../../shared/telemetry/telemetry'
11+
import globals from '../../shared/extensionGlobals'
12+
// import { getStringHash } from '../../shared/utilities/textUtilities'
13+
import { ToolkitError } from '../../shared/errors'
14+
import { getTabSizeSetting } from '../../shared/utilities/editorUtilities'
15+
import { i18n } from '../../shared/i18n-helper'
16+
import { WorkflowMode } from '../workflowStudio/types'
17+
18+
const isLocalDev = true
19+
const localhost = 'http://127.0.0.1:3002'
20+
const cdn = 'https://d5t62uwepi9lu.cloudfront.net'
21+
let clientId = ''
22+
23+
/**
24+
* Provider for Execution Details panels.
25+
*
26+
* Execution Details displays information about state machine executions in a WebView panel.
27+
*/
28+
export class ExecutionDetailProvider {
29+
public static readonly viewType = 'stepfunctions.executionDetails'
30+
31+
/**
32+
* Opens execution details in a WebView panel.
33+
* @param executionArn The ARN of the execution to display details for
34+
* @param params Optional parameters to customize the WebView panel
35+
*/
36+
public static async openExecutionDetails(
37+
executionArn: string,
38+
params?: vscode.WebviewPanelOptions & vscode.WebviewOptions
39+
): Promise<void> {
40+
await telemetry.stepfunctions_openWorkflowStudio.run(async () => {
41+
// Create and show the webview panel
42+
const panel = vscode.window.createWebviewPanel(
43+
ExecutionDetailProvider.viewType,
44+
`Execution: ${executionArn.split(':').pop() || executionArn}`,
45+
vscode.ViewColumn.Beside,
46+
{
47+
enableScripts: true,
48+
retainContextWhenHidden: true,
49+
...params,
50+
}
51+
)
52+
53+
// Create the provider and initialize the panel
54+
const provider = new ExecutionDetailProvider()
55+
await provider.initializePanel(panel, executionArn)
56+
})
57+
}
58+
59+
/**
60+
* Registers the command to open execution details.
61+
* @remarks This should only be called once per extension.
62+
*/
63+
public static register(): vscode.Disposable {
64+
return vscode.commands.registerCommand(
65+
'aws.stepFunctions.viewExecutionDetails',
66+
async (executionArn: string) => {
67+
await ExecutionDetailProvider.openExecutionDetails(executionArn)
68+
}
69+
)
70+
}
71+
72+
protected webviewHtml: string
73+
protected readonly logger = getLogger()
74+
75+
constructor() {
76+
this.webviewHtml = ''
77+
}
78+
79+
/**
80+
* Fetches the webview HTML from the CDN or local server.
81+
* @private
82+
*/
83+
private async fetchWebviewHtml(): Promise<void> {
84+
const source = isLocalDev ? localhost : cdn
85+
const response = await request.fetch('GET', `${source}/index.html`).response
86+
this.webviewHtml = await response.text()
87+
}
88+
89+
/**
90+
* Gets the webview content for Execution Details.
91+
* @private
92+
*/
93+
// executionArn: string
94+
private getWebviewContent = async (): Promise<string> => {
95+
const htmlFileSplit = this.webviewHtml.split('<head>')
96+
97+
// Set asset source to CDN
98+
const source = isLocalDev ? localhost : cdn
99+
const baseTag = `<base href='${source}'/>`
100+
101+
// Set locale, dark mode
102+
const locale = vscode.env.language
103+
const localeTag = `<meta name='locale' content='${locale}'>`
104+
const theme = vscode.window.activeColorTheme.kind
105+
const isDarkMode = theme === vscode.ColorThemeKind.Dark || theme === vscode.ColorThemeKind.HighContrast
106+
const tabSizeTag = `<meta name='tab-size' content='${getTabSizeSetting()}'>`
107+
const darkModeTag = `<meta name='dark-mode' content='${isDarkMode}'>`
108+
109+
// Set component type to ExecutionDetails
110+
const componentTypeTag = `<meta name="component-type" content="ExecutionDetails" />`
111+
112+
// Add execution ARN to load the specific execution
113+
// const executionArnTag = `<meta name="execution-arn" content="${executionArn}" />`
114+
115+
// Set to read-only mode as this is just displaying execution details
116+
const modeTag = `<meta name="workflow-mode" content="${WorkflowMode.Readonly}" />`
117+
// const modeTag = `<meta name="workflow-mode" content="${mode}" />`
118+
119+
return `${htmlFileSplit[0]} <head> ${baseTag} ${localeTag} ${darkModeTag} ${tabSizeTag} ${modeTag} ${componentTypeTag} ${htmlFileSplit[1]}`
120+
}
121+
122+
/**
123+
* Initializes a WebView panel with execution details.
124+
* @param panel The WebView panel to initialize
125+
* @param executionArn The ARN of the execution to display
126+
*/
127+
public async initializePanel(panel: vscode.WebviewPanel, executionArn: string): Promise<void> {
128+
try {
129+
if (!this.webviewHtml) {
130+
await this.fetchWebviewHtml()
131+
}
132+
133+
if (clientId === '') {
134+
clientId = getClientId(globals.globalState)
135+
}
136+
137+
// Set up the content
138+
// panel.webview.html = await this.getWebviewContent(executionArn)
139+
panel.webview.html = await this.getWebviewContent()
140+
141+
// Handle messages from the webview
142+
panel.webview.onDidReceiveMessage(async (message) => {
143+
this.logger.debug('Received message from execution details webview: %O', message)
144+
// Add message handlers as needed
145+
})
146+
} catch (err) {
147+
void vscode.window.showErrorMessage(i18n('AWS.stepFunctions.executionDetails.failed'))
148+
throw ToolkitError.chain(err, 'Could not open Execution Details', { code: 'OpenExecutionDetailsFailed' })
149+
}
150+
}
151+
}

0 commit comments

Comments
 (0)