/* 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. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ import React, { useState, useEffect } from "react"; import ExtLink from "components/ExtLink"; import HeaderPanel from "components/HeaderPanel"; import ValueWithLabel from "components/ValueWithLabel"; import Tiles from "components/Tiles"; import { CreateLogMethod } from "assets/js/const"; import FormItem from "components/FormItem"; import { listResources } from "graphql/queries"; import { appSyncRequestQuery } from "assets/js/request"; import { ESVPCInfo, Resource, ResourceType } from "API"; import { SelectItem } from "components/Select/select"; import Select from "components/Select"; import MultiSelect from "components/MultiSelect"; import { ImportedDomainType } from "../ImportCluster"; import { AmplifyConfigType } from "types"; import { useSelector } from "react-redux"; import { AppStateProps, InfoBarTypes } from "reducer/appReducer"; import { buildSGLink, buildSubnetLink, buildVPCLink } from "assets/js/utils"; import Alert from "components/Alert"; import { useTranslation } from "react-i18next"; interface ConfigNetworkProps { importedCluster: ImportedDomainType; changeVpc: (domain: string) => void; changeSubnet: (subnets: string) => void; changeSecurityGroup: (securityGroup: string) => void; changeVPCList: (list: SelectItem[]) => void; changeSubnetList: (list: SelectItem[]) => void; changeSGList: (list: SelectItem[]) => void; changeVPCAlert: (show: boolean) => void; changeCreationMethod: (method: string) => void; esVPCInfo: ESVPCInfo; } const ConfigNetwork: React.FC = ( props: ConfigNetworkProps ) => { const { importedCluster, changeVpc, changeSubnet, changeSecurityGroup, changeVPCList, changeSubnetList, changeSGList, changeVPCAlert, changeCreationMethod, esVPCInfo, } = props; const { t } = useTranslation(); const amplifyConfig: AmplifyConfigType = useSelector( (state: AppStateProps) => state.amplifyConfig ); const [loadingRes, setLoadingRes] = useState(false); const convertResourceToOptionList = ( resList: Resource[], type: ResourceType ): SelectItem[] => { const tmpOptionList: SelectItem[] = []; resList.forEach((element) => { if (type === ResourceType.VPC) { tmpOptionList.push({ name: `${element.id}(${element.name})`, value: element.id, }); } if (type === ResourceType.SecurityGroup) { tmpOptionList.push({ name: `${element.id}(${element.name})`, value: element.id, }); } if (type === ResourceType.Subnet) { tmpOptionList.push({ name: `${element.id}(${element.name})`, value: element.id, optTitle: element.description || "", }); } }); return tmpOptionList; }; const getResources = async (type: ResourceType, parentId?: string) => { try { setLoadingRes(true); const resData: any = await appSyncRequestQuery(listResources, { type: type, parentId: parentId, }); console.info("domainNames:", resData.data); const dataList = resData.data.listResources; const list = convertResourceToOptionList(dataList, type); if (type === ResourceType.VPC) { changeVPCList(list); } if (type === ResourceType.Subnet) { changeSubnetList(list); } if (type === ResourceType.SecurityGroup) { changeSGList(list); } setLoadingRes(false); } catch (error) { console.error(error); } }; useEffect(() => { getResources(ResourceType.VPC); }, []); return (
{esVPCInfo.vpcId}
{esVPCInfo?.securityGroupIds?.map((element, index) => { return (
{element}
); })}
{esVPCInfo?.subnetIds?.map((element, index) => { return (
{`${ esVPCInfo.availabilityZones?.[index] }:${" "}${element}`}
); })}
{ changeCreationMethod(event.target.value); }} items={[ { label: t("cluster:import.configNetwork.auto"), description: t("cluster:import.configNetwork.autoDesc"), value: CreateLogMethod.Automatic, }, { label: t("cluster:import.configNetwork.manual"), description: t("cluster:import.configNetwork.manualDesc"), value: CreateLogMethod.Manual, }, ]} />
{CreateLogMethod.Manual === importedCluster.creationMethod && (
{importedCluster.showVPCAlert && (
)} { changeSecurityGroup(event.target.value); }} placeholder={t("cluster:import.configNetwork.chooseSG")} />
)}
); }; export default ConfigNetwork;