|
| 1 | +/*! |
| 2 | + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +import * as nls from 'vscode-nls' |
| 7 | +const localize = nls.loadMessageBundle() |
| 8 | + |
| 9 | +import { createCommonButtons } from '../../shared/ui/buttons' |
| 10 | +import { createInputBox, InputBoxPrompter } from '../../shared/ui/inputPrompter' |
| 11 | +import { Wizard } from '../../shared/wizards/wizard' |
| 12 | +import { validate } from '@aws-sdk/util-arn-parser' |
| 13 | +import { isExpressExecution } from '../utils' |
| 14 | + |
| 15 | +function createExecutionArnPrompter(): InputBoxPrompter { |
| 16 | + function validateArn(value: string): string | undefined { |
| 17 | + if (!value) { |
| 18 | + return localize( |
| 19 | + 'AWS.stepFunctions.viewExecutionDetails.executionArn.validation.empty', |
| 20 | + 'Execution ARN cannot be empty' |
| 21 | + ) |
| 22 | + } |
| 23 | + |
| 24 | + if (!validate(value)) { |
| 25 | + return localize( |
| 26 | + 'AWS.stepFunctions.viewExecutionDetails.executionArn.validation.invalid', |
| 27 | + 'Invalid ARN format. Please provide a valid Step Functions execution ARN' |
| 28 | + ) |
| 29 | + } |
| 30 | + |
| 31 | + return undefined |
| 32 | + } |
| 33 | + |
| 34 | + const prompter = createInputBox({ |
| 35 | + title: localize('AWS.stepFunctions.viewExecutionDetails.executionArn.title', 'Enter Execution ARN'), |
| 36 | + placeholder: |
| 37 | + 'arn:aws:states:us-east-1:123456789012:execution:MyStateMachine:12345678-1234-1234-1234-123456789012', |
| 38 | + validateInput: validateArn, |
| 39 | + buttons: createCommonButtons(), |
| 40 | + }) |
| 41 | + |
| 42 | + return prompter |
| 43 | +} |
| 44 | + |
| 45 | +function createStartTimePrompter(): InputBoxPrompter { |
| 46 | + function validateStartTime(value: string): string | undefined { |
| 47 | + if (!value) { |
| 48 | + return localize( |
| 49 | + 'AWS.stepFunctions.viewExecutionDetails.startTime.validation.empty', |
| 50 | + 'Start time cannot be empty for express executions' |
| 51 | + ) |
| 52 | + } |
| 53 | + |
| 54 | + // Checking if the value is a numeric string (Unix timestamp) |
| 55 | + if (/^\d+$/.test(value)) { |
| 56 | + const timestamp = Number(value) |
| 57 | + const date = new Date(timestamp) |
| 58 | + if (!isNaN(date.getTime())) { |
| 59 | + return undefined |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + // parsing ISO date format |
| 64 | + const date = new Date(value) |
| 65 | + if (isNaN(date.getTime())) { |
| 66 | + return localize( |
| 67 | + 'AWS.stepFunctions.viewExecutionDetails.startTime.validation.invalid', |
| 68 | + 'Invalid time format. Use Unix timestamp or ISO 8601 format (YYYY-MM-DDTHH:mm:ss.sssZ)' |
| 69 | + ) |
| 70 | + } |
| 71 | + |
| 72 | + return undefined |
| 73 | + } |
| 74 | + |
| 75 | + const prompter = createInputBox({ |
| 76 | + title: localize('AWS.stepFunctions.viewExecutionDetails.startTime.title', 'Enter Start Time'), |
| 77 | + placeholder: localize( |
| 78 | + 'AWS.stepFunctions.viewExecutionDetails.startTime.placeholder', |
| 79 | + 'Start time of the express execution (e.g., 2023-12-01T10:00:00.000Z)' |
| 80 | + ), |
| 81 | + validateInput: validateStartTime, |
| 82 | + buttons: createCommonButtons(), |
| 83 | + }) |
| 84 | + |
| 85 | + return prompter |
| 86 | +} |
| 87 | + |
| 88 | +export interface ViewExecutionDetailsWizardState { |
| 89 | + readonly executionArn: string |
| 90 | + readonly startTime?: string |
| 91 | +} |
| 92 | + |
| 93 | +export class ViewExecutionDetailsWizard extends Wizard<ViewExecutionDetailsWizardState> { |
| 94 | + public constructor() { |
| 95 | + super() |
| 96 | + const form = this.form |
| 97 | + |
| 98 | + form.executionArn.bindPrompter(() => createExecutionArnPrompter()) |
| 99 | + |
| 100 | + form.startTime.bindPrompter(() => createStartTimePrompter(), { |
| 101 | + showWhen: (state) => { |
| 102 | + if (!state.executionArn) { |
| 103 | + return false |
| 104 | + } |
| 105 | + return isExpressExecution(state.executionArn) |
| 106 | + }, |
| 107 | + }) |
| 108 | + } |
| 109 | +} |
0 commit comments