github.com/minio/console@v1.4.1/web-app/src/screens/Console/Configurations/SiteReplication/LookupStatus/GroupEntityStatus.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 GroupEntityStatusProps = Partial<StatsResponseType> & {
    23    lookupValue?: string;
    24  };
    25  const UserEntityStatus = ({
    26    groupStats = {},
    27    sites = {},
    28    lookupValue = "",
    29  }: GroupEntityStatusProps) => {
    30    const rowsForStatus = ["Info", "Policy mapping"];
    31  
    32    const groupSites: Record<string, any> = groupStats[lookupValue] || {};
    33  
    34    if (!lookupValue) return null;
    35  
    36    const siteKeys = Object.keys(sites);
    37    const notFound = isEntityNotFound(sites, groupSites, "HasGroup");
    38    const resultMatrix: any = [];
    39    if (notFound) {
    40      return <EntityNotFound entityType={"Group"} 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        /**
    48         * ----------------------------------
    49         * | <blank cell>  | sit-0 | site-1 |
    50         * -----------------------------------
    51         */
    52        row.push(sites[siteKeys[sCol]].name);
    53      }
    54      resultMatrix.push(row);
    55      for (let fi = 0; fi < rowsForStatus.length; fi++) {
    56        /**
    57         * -------------------------------------------------
    58         * | Feature Name  | site-0-status | site-1-status |
    59         * --------------------------------------------------
    60         */
    61        const sfRow = [];
    62        const feature = rowsForStatus[fi];
    63        let sbStatus: string | boolean = "";
    64  
    65        for (let si = 0; si < siteKeys.length; si++) {
    66          const bucketSiteDeploymentId = sites[siteKeys[si]].deploymentID;
    67  
    68          const rSite = groupSites[bucketSiteDeploymentId];
    69  
    70          if (si === 0) {
    71            sfRow.push(feature);
    72          }
    73  
    74          switch (fi) {
    75            case 0:
    76              sbStatus = syncStatus(rSite.GroupDescMismatch, rSite.HasGroup);
    77              sfRow.push(sbStatus);
    78              break;
    79            case 1:
    80              sbStatus = syncStatus(rSite.PolicyMismatch, rSite.HasPolicyMapping);
    81              sfRow.push(sbStatus);
    82              break;
    83          }
    84        }
    85  
    86        resultMatrix.push(sfRow);
    87      }
    88    }
    89  
    90    return (
    91      <LookupStatusTable
    92        matrixData={resultMatrix}
    93        entityName={lookupValue}
    94        entityType={"Group"}
    95      />
    96    );
    97  };
    98  
    99  export default UserEntityStatus;