/* 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 { EKSDeployKind, Tag } from "API"; import { appSyncRequestMutation } from "assets/js/request"; import Breadcrumb from "components/Breadcrumb"; import Button from "components/Button"; import CreateStep from "components/CreateStep"; import HelpPanel from "components/HelpPanel"; import SideMenu from "components/SideMenu"; import { importEKSCluster } from "graphql/mutations"; import React, { useEffect, useState } from "react"; import { useTranslation } from "react-i18next"; import { useDispatch } from "react-redux"; import { useHistory } from "react-router-dom"; import { ActionType } from "reducer/appReducer"; import CreateTags from "./steps/CreateTags"; import SpecifyDomain from "./steps/SpecifyEKSDomain"; import SpecifyEksSource from "./steps/SpecifyEksSource"; export interface EKSClusterLogSourceType { aosDomainId: string; eksClusterName: string; deploymentKind: EKSDeployKind; accountId: string; tags: Tag[]; } export const DEFAULT_EMPTY_EKS_CLUSTER_LOG_SOURCE: EKSClusterLogSourceType = { aosDomainId: "", eksClusterName: "", deploymentKind: EKSDeployKind.DaemonSet, accountId: "", tags: [], }; const ImportEksCluster: React.FC = () => { const { t } = useTranslation(); const breadCrumbList = [ { name: t("name"), link: "/" }, { name: t("ekslog:name"), link: "/containers/eks-log", }, { name: t("ekslog:create.name"), }, ]; const history = useHistory(); const dispatch = useDispatch(); const [curStep, setCurStep] = useState(0); const [curEksClusterLogSourceInfo, setCurEksClusterLogSourceInfo] = useState(DEFAULT_EMPTY_EKS_CLUSTER_LOG_SOURCE); const [domainListIsLoading, setDomainListIsLoading] = useState(false); const [loadingCreate, setLoadingCreate] = useState(false); const [eksEmptyError, setEksEmptyError] = useState(false); const [esDomainEmptyError, setEsDomainEmptyError] = useState(false); const [confirmNetwork, setConfirmNetwork] = useState(false); const [confirmNetworkError, setConfirmNetworkError] = useState(false); useEffect(() => { dispatch({ type: ActionType.CLOSE_SIDE_MENU }); }, []); const validateEksSourceInput = () => { if ( !curEksClusterLogSourceInfo.eksClusterName || curEksClusterLogSourceInfo.eksClusterName.length <= 0 ) { setEksEmptyError(true); setCurStep(0); return false; } return true; }; const validateOpenSearchInput = () => { if ( !curEksClusterLogSourceInfo.aosDomainId || curEksClusterLogSourceInfo.aosDomainId.length <= 0 ) { setEsDomainEmptyError(true); setCurStep(1); return false; } return true; }; const confirmImportEksCluster = async () => { try { setLoadingCreate(true); const createRes = await appSyncRequestMutation( importEKSCluster, curEksClusterLogSourceInfo ); console.info("createRes:", createRes); setLoadingCreate(false); history.push({ pathname: "/containers/eks-log", }); } catch (error) { setLoadingCreate(false); console.error(error); } }; return (
{curStep === 0 && ( { setEksEmptyError(false); setCurEksClusterLogSourceInfo( (prev: EKSClusterLogSourceType) => { return { ...prev, eksClusterName: "", accountId: id, }; } ); }} changeEksClusterSource={(clusterName: string) => { if (clusterName) { setEksEmptyError(false); } setCurEksClusterLogSourceInfo( (prev: EKSClusterLogSourceType) => { return { ...prev, eksClusterName: clusterName, }; } ); }} changeEksLogAgentPattern={(pattern: EKSDeployKind) => { setCurEksClusterLogSourceInfo( (prev: EKSClusterLogSourceType) => { return { ...prev, deploymentKind: pattern, }; } ); }} /> )} {curStep === 1 && ( { setConfirmNetwork(confirm); setConfirmNetworkError(false); }} eksClusterLogSource={curEksClusterLogSourceInfo} changeOpenSearchCluster={(clusterId) => { if (clusterId) { setEsDomainEmptyError(false); } setCurEksClusterLogSourceInfo((prev) => { return { ...prev, aosDomainId: clusterId || "", }; }); }} changeLoadingDomain={(loading: boolean) => { setDomainListIsLoading(loading); }} esDomainEmptyError={esDomainEmptyError} /> )} {curStep === 2 && ( { setCurEksClusterLogSourceInfo((prev) => { return { ...prev, tags: tags, }; }); }} /> )}
{curStep > 0 && ( )} {curStep < 2 && ( )} {curStep === 2 && ( )}
); }; export default ImportEksCluster;