github.com/minio/console@v1.4.1/web-app/src/screens/Console/Configurations/SiteReplication/LookupStatus/BucketEntityStatus.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 BucketEntityStatusProps = Partial<StatsResponseType> & {
    23    lookupValue?: string;
    24  };
    25  const BucketEntityStatus = ({
    26    bucketStats = {},
    27    sites = {},
    28    lookupValue = "",
    29  }: BucketEntityStatusProps) => {
    30    const rowsForStatus = [
    31      "Tags",
    32      "Policy",
    33      "Quota",
    34      "Retention",
    35      "Encryption",
    36      "Replication",
    37    ];
    38  
    39    const bucketSites: Record<string, any> = bucketStats[lookupValue] || {};
    40  
    41    if (!lookupValue) return null;
    42  
    43    const siteKeys = Object.keys(sites);
    44  
    45    const notFound = isEntityNotFound(sites, bucketSites, "HasBucket");
    46    const resultMatrix: any = [];
    47    if (notFound) {
    48      return <EntityNotFound entityType={"Bucket"} entityValue={lookupValue} />;
    49    } else {
    50      const row = [];
    51      for (let sCol = 0; sCol < siteKeys.length; sCol++) {
    52        if (sCol === 0) {
    53          row.push("");
    54        }
    55        /**
    56         * ----------------------------------
    57         * | <blank cell>  | sit-0 | site-1 |
    58         * -----------------------------------
    59         */
    60        row.push(sites[siteKeys[sCol]].name);
    61      }
    62      resultMatrix.push(row);
    63      for (let fi = 0; fi < rowsForStatus.length; fi++) {
    64        /**
    65         * -------------------------------------------------
    66         * | Feature Name  | site-0-status | site-1-status |
    67         * --------------------------------------------------
    68         */
    69        const sfRow = [];
    70        const feature = rowsForStatus[fi];
    71        let sbStatus: string | boolean = "";
    72  
    73        for (let si = 0; si < siteKeys.length; si++) {
    74          const bucketSiteDeploymentId = sites[siteKeys[si]].deploymentID;
    75  
    76          const rSite = bucketSites[bucketSiteDeploymentId];
    77  
    78          if (si === 0) {
    79            sfRow.push(feature);
    80          }
    81  
    82          switch (fi) {
    83            case 0:
    84              sbStatus = syncStatus(rSite.TagMismatch, rSite.HasTagsSet);
    85              sfRow.push(sbStatus);
    86              break;
    87            case 1:
    88              sbStatus = syncStatus(rSite.PolicyMismatch, rSite.HasPolicySet);
    89              sfRow.push(sbStatus);
    90              break;
    91            case 2:
    92              sbStatus = syncStatus(rSite.QuotaCfgMismatch, rSite.HasQuotaCfgSet);
    93              sfRow.push(sbStatus);
    94              break;
    95            case 3:
    96              sbStatus = syncStatus(
    97                rSite.OLockConfigMismatch,
    98                rSite.HasOLockConfigSet,
    99              );
   100              sfRow.push(sbStatus);
   101              break;
   102            case 4:
   103              sbStatus = syncStatus(rSite.SSEConfigMismatch, rSite.HasSSECfgSet);
   104              sfRow.push(sbStatus);
   105              break;
   106            case 5:
   107              sbStatus = syncStatus(
   108                rSite.ReplicationCfgMismatch,
   109                rSite.HasReplicationCfg,
   110              );
   111              sfRow.push(sbStatus);
   112              break;
   113          }
   114        }
   115  
   116        resultMatrix.push(sfRow);
   117      }
   118    }
   119  
   120    return (
   121      <LookupStatusTable
   122        matrixData={resultMatrix}
   123        entityName={lookupValue}
   124        entityType={"Bucket"}
   125      />
   126    );
   127  };
   128  
   129  export default BucketEntityStatus;