github.com/minio/console@v1.4.1/web-app/src/screens/Console/Configurations/SiteReplication/LookupStatus/PolicyEntityStatus.tsx (about) 1 // This file is part of MinIO Console Server 2 // Copyright (c) 2022 MinIO, Inc. 3 // 4 // This program is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Affero General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // This program is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Affero General Public License for more details. 13 // 14 // You should have received a copy of the GNU Affero General Public License 15 // along with this program. If not, see <http://www.gnu.org/licenses/>. 16 17 import React from "react"; 18 import { StatsResponseType } from "../SiteReplicationStatus"; 19 import LookupStatusTable from "./LookupStatusTable"; 20 import { EntityNotFound, isEntityNotFound, syncStatus } from "./Utils"; 21 22 type PolicyEntityStatusProps = Partial<StatsResponseType> & { 23 lookupValue?: string; 24 }; 25 const PolicyEntityStatus = ({ 26 policyStats = {}, 27 sites = {}, 28 lookupValue = "", 29 }: PolicyEntityStatusProps) => { 30 const rowsForStatus = ["Policy"]; 31 32 const policySites: Record<string, any> = policyStats[lookupValue] || {}; 33 34 if (!lookupValue) return null; 35 36 const siteKeys = Object.keys(sites); 37 const notFound = isEntityNotFound(sites, policySites, "HasPolicy"); 38 const resultMatrix: any = []; 39 if (notFound) { 40 return <EntityNotFound entityType={"Policy"} entityValue={lookupValue} />; 41 } else { 42 const row = []; 43 for (let sCol = 0; sCol < siteKeys.length; sCol++) { 44 if (sCol === 0) { 45 row.push(""); 46 } 47 row.push(sites[siteKeys[sCol]].name); 48 } 49 resultMatrix.push(row); 50 for (let fi = 0; fi < rowsForStatus.length; fi++) { 51 const sfRow = []; 52 const feature = rowsForStatus[fi]; 53 let sbStatus: string | boolean = ""; 54 55 for (let si = 0; si < siteKeys.length; si++) { 56 const bucketSiteDeploymentId = sites[siteKeys[si]].deploymentID; 57 58 const rSite = policySites[bucketSiteDeploymentId]; 59 60 if (si === 0) { 61 sfRow.push(feature); 62 } 63 64 switch (fi) { 65 case 0: 66 sbStatus = syncStatus(rSite.PolicyMismatch, rSite.HasPolicy); 67 sfRow.push(sbStatus); 68 break; 69 } 70 } 71 72 resultMatrix.push(sfRow); 73 } 74 } 75 76 return ( 77 <LookupStatusTable 78 matrixData={resultMatrix} 79 entityName={lookupValue} 80 entityType={"Policy"} 81 /> 82 ); 83 }; 84 85 export default PolicyEntityStatus;