github.com/minio/console@v1.4.1/web-app/src/screens/Console/Configurations/SiteReplication/EntityReplicationLookup.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, { useState } from "react"; 18 import { 19 Box, 20 breakPoints, 21 Button, 22 ClustersIcon, 23 Grid, 24 Loader, 25 Select, 26 InputBox, 27 } from "mds"; 28 import useApi from "../../Common/Hooks/useApi"; 29 import { StatsResponseType } from "./SiteReplicationStatus"; 30 import BucketEntityStatus from "./LookupStatus/BucketEntityStatus"; 31 import PolicyEntityStatus from "./LookupStatus/PolicyEntityStatus"; 32 import GroupEntityStatus from "./LookupStatus/GroupEntityStatus"; 33 import UserEntityStatus from "./LookupStatus/UserEntityStatus"; 34 import TooltipWrapper from "../../Common/TooltipWrapper/TooltipWrapper"; 35 36 const EntityReplicationLookup = () => { 37 const [entityType, setEntityType] = useState<string>("bucket"); 38 const [entityValue, setEntityValue] = useState<string>(""); 39 40 const [stats, setStats] = useState<StatsResponseType>({}); 41 const [statsLoaded, setStatsLoaded] = useState<boolean>(false); 42 43 const [isStatsLoading, invokeSiteStatsApi] = useApi( 44 (res: any) => { 45 setStats(res); 46 setStatsLoaded(true); 47 }, 48 (err: any) => { 49 setStats({}); 50 setStatsLoaded(true); 51 }, 52 ); 53 54 const { 55 bucketStats = {}, 56 sites = {}, 57 userStats = {}, 58 policyStats = {}, 59 groupStats = {}, 60 } = stats || {}; 61 62 const getStats = (entityType: string = "", entityValue: string = "") => { 63 setStatsLoaded(false); 64 if (entityType && entityValue) { 65 let url = `api/v1/admin/site-replication/status?buckets=false&entityType=${entityType}&entityValue=${entityValue}&groups=false&policies=false&users=false`; 66 invokeSiteStatsApi("GET", url); 67 } 68 }; 69 70 return ( 71 <Box> 72 <Box 73 sx={{ 74 display: "grid", 75 alignItems: "center", 76 gridTemplateColumns: ".7fr .9fr 1.2fr .3fr", 77 [`@media (max-width: ${breakPoints.sm}px)`]: { 78 gridTemplateColumns: "1fr", 79 }, 80 [`@media (max-width: ${breakPoints.md}px)`]: { 81 gridTemplateColumns: "1.2fr .7fr .7fr .3fr", 82 }, 83 gap: "15px", 84 }} 85 > 86 <Box sx={{ width: "240px", flexGrow: "0" }}> 87 View Replication Status for a: 88 </Box> 89 <Box 90 sx={{ 91 marginLeft: -25, 92 [`@media (max-width: ${breakPoints.sm}px)`]: { 93 marginLeft: 0, 94 }, 95 }} 96 > 97 <Select 98 id="replicationEntityLookup" 99 name="replicationEntityLookup" 100 onChange={(value) => { 101 setEntityType(value); 102 setStatsLoaded(false); 103 }} 104 label="" 105 value={entityType} 106 options={[ 107 { 108 label: "Bucket", 109 value: "bucket", 110 }, 111 { 112 label: "User", 113 value: "user", 114 }, 115 { 116 label: "Group", 117 value: "group", 118 }, 119 { 120 label: "Policy", 121 value: "policy", 122 }, 123 ]} 124 disabled={false} 125 /> 126 </Box> 127 128 <Box 129 sx={{ 130 flex: 2, 131 }} 132 > 133 <InputBox 134 id="replicationLookupEntityValue" 135 name="replicationLookupEntityValue" 136 onChange={(e: React.ChangeEvent<HTMLInputElement>) => { 137 setEntityValue(e.target.value); 138 setStatsLoaded(false); 139 }} 140 placeholder={`test-${entityType}`} 141 label="" 142 value={entityValue} 143 /> 144 </Box> 145 <Box 146 sx={{ 147 maxWidth: "80px", 148 }} 149 > 150 <TooltipWrapper tooltip={"View across sites"}> 151 <Button 152 id={"view-across-sites"} 153 type={"button"} 154 onClick={() => { 155 getStats(entityType, entityValue); 156 }} 157 label={`View`} 158 icon={<ClustersIcon />} 159 collapseOnSmall={false} 160 disabled={!entityValue || !entityType} 161 /> 162 </TooltipWrapper> 163 </Box> 164 </Box> 165 166 {isStatsLoading ? ( 167 <Grid 168 item 169 xs={12} 170 sx={{ 171 display: "flex", 172 alignItems: "center", 173 justifyContent: "center", 174 marginTop: 45, 175 }} 176 > 177 <Loader style={{ width: 25, height: 25 }} /> 178 </Grid> 179 ) : null} 180 181 {statsLoaded ? ( 182 <Box> 183 {!isStatsLoading && entityType === "bucket" && entityValue ? ( 184 <BucketEntityStatus 185 bucketStats={bucketStats} 186 sites={sites} 187 lookupValue={entityValue} 188 /> 189 ) : null} 190 191 {!isStatsLoading && entityType === "user" && entityValue ? ( 192 <UserEntityStatus 193 userStats={userStats} 194 sites={sites} 195 lookupValue={entityValue} 196 /> 197 ) : null} 198 199 {!isStatsLoading && entityType === "group" && entityValue ? ( 200 <GroupEntityStatus 201 groupStats={groupStats} 202 sites={sites} 203 lookupValue={entityValue} 204 /> 205 ) : null} 206 207 {!isStatsLoading && entityType === "policy" && entityValue ? ( 208 <PolicyEntityStatus 209 policyStats={policyStats} 210 sites={sites} 211 lookupValue={entityValue} 212 /> 213 ) : null} 214 </Box> 215 ) : null} 216 </Box> 217 ); 218 }; 219 220 export default EntityReplicationLookup;