// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance // with the License. A copy of the License is located at // // http://aws.amazon.com/apache2.0/ // // or in the "LICENSE.txt" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES // OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions and // limitations under the License. // Fameworks import React, {useCallback, useMemo} from 'react' import {Trans, useTranslation} from 'react-i18next' import {useSelector} from 'react-redux' import {findFirst} from '../../util' // State / Model import { setState, getState, useState, updateState, clearState, clearEmptyNest, ssmPolicy, } from '../../store' // UI Elements import { Autosuggest, Button, FormField, Input, SpaceBetween, Checkbox, TokenGroup, Select, InputProps, TextContent, } from '@cloudscape-design/components' // Components import {NonCancelableEventHandler} from '@cloudscape-design/components/internal/events' import TitleDescriptionHelpPanel from '../../components/help-panel/TitleDescriptionHelpPanel' import InfoLink from '../../components/InfoLink' import {subnetName} from './util' // Helper Functions function strToOption(str: any) { return {value: str, label: str} } type Extension = { name: string path: string description: string args: {name: string; default?: string}[] } type ActionsEditorProps = { basePath: string[] errorsPath: string[] } // Selectors const selectVpc = (state: any) => getState(state, ['app', 'wizard', 'vpc']) const selectAwsSubnets = (state: any) => getState(state, ['aws', 'subnets']) function LabeledIcon({label, icon}: any) { return (
{/* eslint-disable-next-line @next/next/no-img-element*/} {label}
{label}
) } function SubnetSelect({value, onChange, disabled}: any) { const subnets = useSelector(selectAwsSubnets) const vpc = useSelector(selectVpc) var filteredSubnets = subnets && subnets.filter((s: any) => { return vpc ? s.VpcId === vpc : true }) if (!subnets) { return
No Subnets Found.
} const itemToOption = (item: any) => { return { value: item.SubnetId, label: item.SubnetId, description: item.AvailabilityZone + ` - ${item.AvailabilityZoneId}` + (subnetName(item) ? ` (${subnetName(item)})` : ''), } } return ( { setState([...path, i], detail.value) }} /> ) } function ActionEditor({label, description, actionKey, errorPath, path}: any) { const script = useState([...path, 'Script']) || '' const args = useState([...path, 'Args']) || [] const addArg = (path: any) => { updateState(path, (old: any) => [...(old || []), '']) } const editScript = (path: any, val: any) => { if (val !== '') setState(path, val) else clearState(path) clearEmptyNest(path, 3) } return (
editScript([...path, 'Script'], detail.value) } />
{args.map((a: any, i: any) => ( ))}
) } function ActionsEditor({basePath, errorsPath}: ActionsEditorProps) { const {t} = useTranslation() const actionsPath = [...basePath, 'CustomActions'] const onStartPath = [...actionsPath, 'OnNodeStart'] const onConfiguredPath = [...actionsPath, 'OnNodeConfigured'] const onStartErrors = useState([...errorsPath, 'onStart']) const onConfiguredErrors = useState([...errorsPath, 'onConfigured']) return ( ) } function HeadNodeActionsEditor({basePath, errorsPath}: ActionsEditorProps) { const {t} = useTranslation() const actionsPath = [...basePath, 'CustomActions'] const onStartPath = [...actionsPath, 'OnNodeStart'] const onConfiguredPath = [...actionsPath, 'OnNodeConfigured'] const onUpdatedPath = [...actionsPath, 'OnNodeUpdated'] const onStartErrors = useState([...errorsPath, 'onStart']) const onConfiguredErrors = useState([...errorsPath, 'onConfigured']) const onUpdatedErrors = useState([...errorsPath, 'onUpdated']) return ( ) } function SecurityGroups({basePath}: any) { const {t} = useTranslation() const sgPath = [...basePath, 'Networking', 'AdditionalSecurityGroups'] const selectedSgs = useState(sgPath) || [] const sgSelected = useState(['app', 'wizard', 'sg-selected']) const sgs = useState(['aws', 'security_groups']) || [] const sgMap = sgs.reduce((acc: any, s: any) => { acc[s.GroupId] = s.GroupName return acc }, {}) const itemToOption = (item: any) => { return { value: item.GroupId, label: item.GroupId, description: item.GroupName, } } const removeSg = (i: any) => { setState(sgPath, [...selectedSgs.slice(0, i), ...selectedSgs.slice(i + 1)]) if (getState(sgPath).length === 0) clearState(sgPath) } return (
setRootVolume(detail.value)} /> {t('wizard.components.rootVolume.encrypted')}
: setState(policyPath, detail.value)} />
{policies.map( (p: any, i: any) => p.Policy !== ssmPolicy && (
{p.Policy}
), )} ) } type HelpTextInputProps = { name: string path: string[] errorsPath: string[] configKey: string description: string help: string placeholder: string type?: InputProps.Type onChange: NonCancelableEventHandler } function HelpTextInput({ name, path, errorsPath, configKey, description, help, placeholder, type = 'text', onChange, }: HelpTextInputProps) { let value = useState([...path, configKey]) let error = useState([...errorsPath, configKey]) return ( } /> } >
) } export { SubnetSelect, SecurityGroups, InstanceSelect, LabeledIcon, ActionsEditor, HeadNodeActionsEditor, CustomAMISettings, RootVolume, IamPoliciesEditor, HelpTextInput, }