/* 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 { RouteComponentProps, useHistory } from "react-router-dom"; import SideMenu from "components/SideMenu"; import Breadcrumb from "components/Breadcrumb"; import PagePanel from "components/PagePanel"; import Button from "components/Button"; import HeaderPanel from "components/HeaderPanel"; import ValueWithLabel from "components/ValueWithLabel"; import LoadingText from "components/LoadingText"; import { appSyncRequestMutation, appSyncRequestQuery } from "assets/js/request"; import { getLogConf } from "graphql/queries"; import { deleteLogConf } from "graphql/mutations"; import Modal from "components/Modal"; import { DEFAULT_AGENT_VERSION, ResourceStatus } from "assets/js/const"; import { formatLocalTime } from "assets/js/utils"; import { useTranslation } from "react-i18next"; import ConfigDetailComps from "./ConfigDetailComps"; import { Alert } from "assets/js/alert"; import { ExLogConf } from "../common/LogConfigComp"; interface MatchParams { id: string; name: string; } const ConfigDetail: React.FC> = ( props: RouteComponentProps ) => { const id: string = props.match.params.id; const history = useHistory(); const { t } = useTranslation(); const [loadingData, setLoadingData] = useState(true); const [curLogConfig, setCurLogConfig] = useState(); const [openDeleteModel, setOpenDeleteModel] = useState(false); const [loadingDelete, setLoadingDelete] = useState(false); const breadCrumbList = [ { name: t("name"), link: "/" }, { name: t("resource:config.name"), link: "/resources/log-config", }, { name: curLogConfig?.confName || "" }, ]; // Show Remove Log Config Dialog const removeLogConfig = async () => { setOpenDeleteModel(true); }; // Confirm to Remove Log Config By Id const confimRemoveLogConfig = async () => { try { setLoadingDelete(true); const removeRes = await appSyncRequestMutation(deleteLogConf, { id: curLogConfig?.id, }); console.info("removeRes:", removeRes); setLoadingDelete(false); setOpenDeleteModel(false); history.push({ pathname: `/resources/log-config`, }); } catch (error) { setLoadingDelete(false); console.error(error); } }; const getLogConfigById = async () => { try { setLoadingData(true); const resData: any = await appSyncRequestQuery(getLogConf, { id: id, }); console.info("resData:", resData); const dataLogConfig: ExLogConf = resData.data.getLogConf; if (dataLogConfig.status === ResourceStatus.INACTIVE) { Alert(t("resource:config.detail.notExist")); return; } setCurLogConfig(dataLogConfig); setLoadingData(false); } catch (error) { setLoadingData(false); console.error(error); } }; useEffect(() => { getLogConfigById(); }, []); return (
{loadingData ? ( ) : (
} >
{curLogConfig?.confName}
{curLogConfig?.logType}
{DEFAULT_AGENT_VERSION}
{formatLocalTime(curLogConfig?.createdDt || "")}
)}
{ setOpenDeleteModel(false); }} actions={
} >
{t("resource:config.deleteTips")} {`${curLogConfig?.confName}`} {"?"}
); }; export default ConfigDetail;