/* 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 RefreshIcon from "@material-ui/icons/Refresh"; import Breadcrumb from "components/Breadcrumb"; import SideMenu from "components/SideMenu"; import { useTranslation } from "react-i18next"; import { SelectType, TablePanel } from "components/TablePanel"; import Button from "components/Button"; import { SubAccountLink } from "API"; import { Link, useHistory } from "react-router-dom"; import { Pagination } from "@material-ui/lab"; import HelpPanel from "components/HelpPanel"; import { appSyncRequestMutation, appSyncRequestQuery } from "assets/js/request"; import { listSubAccountLinks } from "graphql/queries"; import LoadingText from "components/LoadingText"; import { deleteSubAccountLink } from "graphql/mutations"; import Modal from "components/Modal"; import { formatLocalTime } from "assets/js/utils"; const PAGE_SIZE = 10; const CrossAccountList: React.FC = () => { const { t } = useTranslation(); const history = useHistory(); const breadCrumbList = [ { name: t("name"), link: "/" }, { name: t("resource:crossAccount.name") }, ]; const [loadingData, setLoadingData] = useState(false); const [disabledDelete, setDisabledDelete] = useState(false); const [loadingDelete, setLoadingDelete] = useState(false); const [totoalCount, setTotoalCount] = useState(0); const [curPage, setCurPage] = useState(1); const [crossAccountList, setCrossAccountList] = useState( [] ); const [curAccount, setCurAccount] = useState(); const [openDeleteModel, setOpenDeleteModel] = useState(false); const [selectedAccount, setSelectedAccount] = useState(); // Get Member Account List const getCrossAccountList = async () => { try { setCrossAccountList([]); setSelectedAccount([]); setLoadingData(true); const resData: any = await appSyncRequestQuery(listSubAccountLinks, { page: curPage, count: PAGE_SIZE, }); console.info("resData:", resData); const dataLogAccountList: SubAccountLink[] = resData.data.listSubAccountLinks.subAccountLinks; setTotoalCount(resData.data.listSubAccountLinks?.total || 0); setCrossAccountList(dataLogAccountList); setLoadingData(false); } catch (error) { console.error(error); } }; const removeCrossAccount = async () => { setCurAccount(selectedAccount?.[0]); setOpenDeleteModel(true); }; const confirmRemoveCrossAccount = async () => { try { setLoadingDelete(true); const removeRes = await appSyncRequestMutation(deleteSubAccountLink, { id: curAccount?.id, }); console.info("removeRes:", removeRes); setLoadingDelete(false); setOpenDeleteModel(false); getCrossAccountList(); } catch (error) { setLoadingDelete(false); console.error(error); } }; const handlePageChange = (event: any, value: number) => { setCurPage(value); }; // Disable delete button when no row selected. useEffect(() => { if (selectedAccount && selectedAccount.length > 0) { setDisabledDelete(false); } else { setDisabledDelete(true); } }, [selectedAccount]); useEffect(() => { getCrossAccountList(); }, []); return (
{ setSelectedAccount(item); }} loading={loadingData} selectType={SelectType.RADIO} columnDefinitions={[ { // width: 110, id: "ID", header: t("resource:crossAccount.list.accountName"), cell: (e: SubAccountLink) => { return ( {e.subAccountName} ); }, }, { id: "Name", header: t("resource:crossAccount.list.accountId"), cell: (e: SubAccountLink) => { return e.subAccountId; }, }, { id: "Role", header: t("resource:crossAccount.list.iamRole"), cell: (e: SubAccountLink) => { return e.subAccountRoleArn; }, }, { width: 170, id: "created", header: t("resource:crossAccount.list.created"), cell: (e: SubAccountLink) => { return formatLocalTime(e?.createdDt || ""); }, }, ]} items={crossAccountList} actions={
} pagination={ } />
{ setOpenDeleteModel(false); }} actions={
} >
{t("resource:crossAccount.list.removeLinkTips")} {`${curAccount?.subAccountName}`} {"?"}
); }; export default CrossAccountList;