Skip to content

Commit 7ea9aaa

Browse files
author
Diler Zaza
committed
Implemented common context for both WebviewContext and ExecutionDetailsContext
1 parent ddde043 commit 7ea9aaa

File tree

3 files changed

+13
-33
lines changed

3 files changed

+13
-33
lines changed

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

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

7-
import {
8-
Command,
9-
Message,
10-
MessageType,
11-
WebviewContext,
12-
ExecutionDetailsContext,
13-
ApiCallRequestMessage,
14-
UnsupportedMessage,
15-
} from './types'
7+
import { Command, Message, MessageType, BaseContext, ApiCallRequestMessage, UnsupportedMessage } from './types'
168
import { StepFunctionApiHandler } from './stepFunctionApiHandler'
179
import globals from '../../shared/extensionGlobals'
1810
import { getLogger } from '../../shared/logger/logger'
@@ -21,7 +13,7 @@ import { getLogger } from '../../shared/logger/logger'
2113
* Handler for managing webview stage load, which updates load notifications.
2214
* @param context The context object containing the necessary information for the webview.
2315
*/
24-
export async function loadStageMessageHandler(context: WebviewContext | ExecutionDetailsContext) {
16+
export async function loadStageMessageHandler(context: BaseContext) {
2517
context.loaderNotification?.progress.report({ increment: 25 })
2618
setTimeout(() => {
2719
context.loaderNotification?.resolve()
@@ -33,10 +25,7 @@ export async function loadStageMessageHandler(context: WebviewContext | Executio
3325
* @param request The request message containing the API to call and the parameters
3426
* @param context The webview context used for returning the API response to the webview
3527
*/
36-
export function apiCallMessageHandler(
37-
request: ApiCallRequestMessage,
38-
context: WebviewContext | ExecutionDetailsContext
39-
) {
28+
export function apiCallMessageHandler(request: ApiCallRequestMessage, context: BaseContext) {
4029
const logger = getLogger('stepfunctions')
4130
const apiHandler = new StepFunctionApiHandler(globals.awsContext.getCredentialDefaultRegion(), context)
4231
apiHandler.performApiCall(request).catch((error) => logger.error('%s API call failed: %O', request.apiName, error))
@@ -49,10 +38,7 @@ export function apiCallMessageHandler(
4938
* @param command The command received from the webview
5039
* @param messageType The type of the message received
5140
*/
52-
export async function handleUnsupportedMessage(
53-
context: WebviewContext | ExecutionDetailsContext,
54-
originalMessage: Message
55-
) {
41+
export async function handleUnsupportedMessage(context: BaseContext, originalMessage: Message) {
5642
await context.panel.webview.postMessage({
5743
messageType: MessageType.RESPONSE,
5844
command: Command.UNSUPPORTED_COMMAND,

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,14 @@
66
import * as StepFunctions from '@aws-sdk/client-sfn'
77
import { IamClient, IamRole } from '../../shared/clients/iam'
88
import { StepFunctionsClient } from '../../shared/clients/stepFunctions'
9-
import {
10-
ApiAction,
11-
ApiCallRequestMessage,
12-
Command,
13-
MessageType,
14-
WebviewContext,
15-
ExecutionDetailsContext,
16-
} from './types'
9+
import { ApiAction, ApiCallRequestMessage, Command, MessageType, BaseContext } from './types'
1710
import { telemetry } from '../../shared/telemetry/telemetry'
1811
import { ListRolesRequest } from '@aws-sdk/client-iam'
1912

2013
export class StepFunctionApiHandler {
2114
public constructor(
2215
region: string,
23-
private readonly context: WebviewContext | ExecutionDetailsContext,
16+
private readonly context: BaseContext,
2417
private readonly clients = {
2518
sfn: new StepFunctionsClient(region),
2619
iam: new IamClient(region),

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,24 @@ export enum WorkflowMode {
1616
Readonly = 'readonly',
1717
}
1818

19-
export type WebviewContext = {
19+
export interface BaseContext {
20+
panel: vscode.WebviewPanel
21+
loaderNotification: undefined | LoaderNotification
22+
}
23+
24+
export interface WebviewContext extends BaseContext {
2025
stateMachineName: string
2126
mode: WorkflowMode
22-
panel: vscode.WebviewPanel
2327
textDocument: vscode.TextDocument
2428
disposables: vscode.Disposable[]
2529
workSpacePath: string
2630
defaultTemplatePath: string
2731
defaultTemplateName: string
2832
fileStates: Record<string, FileWatchInfo>
29-
loaderNotification: undefined | LoaderNotification
3033
fileId: string
3134
}
3235

33-
export type ExecutionDetailsContext = {
34-
panel: vscode.WebviewPanel
35-
loaderNotification: undefined | LoaderNotification
36+
export interface ExecutionDetailsContext extends BaseContext {
3637
executionArn: string
3738
}
3839

0 commit comments

Comments
 (0)