github.com/minio/console@v1.4.1/web-app/src/screens/Console/Buckets/ListBuckets/AddBucket/BucketNamingRules.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, { Fragment, useState } from "react"; 18 import { Grid, ExpandOptionsButton, ProgressBar } from "mds"; 19 20 import { AppState } from "../../../../../store"; 21 import { useSelector } from "react-redux"; 22 import ValidRule from "./ValidRule"; 23 import InvalidRule from "./InvalidRule"; 24 import NARule from "./NARule"; 25 26 const BucketNamingRules = ({ errorList }: { errorList: boolean[] }) => { 27 const lengthRuleText = 28 "Bucket names must be between 3 (min) and 63 (max) characters long."; 29 const characterRuleText = 30 "Bucket names can consist only of lowercase letters, numbers, dots (.), and hyphens (-)."; 31 const periodRuleText = 32 "Bucket names must not contain two adjacent periods, or a period adjacent to a hyphen."; 33 const ipRuleText = 34 "Bucket names must not be formatted as an IP address (for example, 192.168.5.4)."; 35 const prefixRuleText = "Bucket names must not start with the prefix xn--."; 36 const suffixRuleText = 37 "Bucket names must not end with the suffix -s3alias. This suffix is reserved for access point alias names."; 38 const uniqueRuleText = "Bucket names must be unique within a partition."; 39 40 const bucketName = useSelector((state: AppState) => state.addBucket.name); 41 42 const [showNamingRules, setShowNamingRules] = useState<boolean>(false); 43 44 const addLoading = useSelector((state: AppState) => state.addBucket.loading); 45 46 const [ 47 lengthRule, 48 validCharacters, 49 noAdjacentPeriods, 50 notIPFormat, 51 noPrefix, 52 noSuffix, 53 uniqueName, 54 ] = errorList; 55 56 const toggleNamingRules = () => { 57 setShowNamingRules(!showNamingRules); 58 }; 59 60 return ( 61 <Fragment> 62 <ExpandOptionsButton 63 id={"toggle-naming-rules"} 64 type="button" 65 open={showNamingRules} 66 label={`${showNamingRules ? "Hide" : "View"} Bucket Naming Rules`} 67 onClick={() => { 68 toggleNamingRules(); 69 }} 70 /> 71 {showNamingRules && ( 72 <Grid container sx={{ fontSize: 14, paddingTop: 12 }}> 73 <Grid item xs={6}> 74 {bucketName.length === 0 ? ( 75 <NARule ruleText={lengthRuleText} /> 76 ) : lengthRule ? ( 77 <ValidRule ruleText={lengthRuleText} /> 78 ) : ( 79 <InvalidRule ruleText={lengthRuleText} /> 80 )} 81 {bucketName.length === 0 ? ( 82 <NARule ruleText={characterRuleText} /> 83 ) : validCharacters ? ( 84 <ValidRule ruleText={characterRuleText} /> 85 ) : ( 86 <InvalidRule ruleText={characterRuleText} /> 87 )} 88 {bucketName.length === 0 ? ( 89 <NARule ruleText={periodRuleText} /> 90 ) : noAdjacentPeriods ? ( 91 <ValidRule ruleText={periodRuleText} /> 92 ) : ( 93 <InvalidRule ruleText={periodRuleText} /> 94 )} 95 {bucketName.length === 0 ? ( 96 <NARule ruleText={ipRuleText} /> 97 ) : notIPFormat ? ( 98 <ValidRule ruleText={ipRuleText} /> 99 ) : ( 100 <InvalidRule ruleText={ipRuleText} /> 101 )} 102 </Grid> 103 <Grid item xs={6}> 104 {bucketName.length === 0 ? ( 105 <NARule ruleText={prefixRuleText} /> 106 ) : noPrefix ? ( 107 <ValidRule ruleText={prefixRuleText} /> 108 ) : ( 109 <InvalidRule ruleText={prefixRuleText} /> 110 )} 111 112 {bucketName.length === 0 ? ( 113 <NARule ruleText={suffixRuleText} /> 114 ) : noSuffix ? ( 115 <ValidRule ruleText={suffixRuleText} /> 116 ) : ( 117 <InvalidRule ruleText={suffixRuleText} /> 118 )} 119 120 {bucketName.length === 0 ? ( 121 <NARule ruleText={uniqueRuleText} /> 122 ) : uniqueName ? ( 123 <ValidRule ruleText={uniqueRuleText} /> 124 ) : ( 125 <InvalidRule ruleText={uniqueRuleText} /> 126 )} 127 </Grid> 128 </Grid> 129 )} 130 131 {addLoading && ( 132 <Grid item xs={12}> 133 <ProgressBar /> 134 </Grid> 135 )} 136 </Fragment> 137 ); 138 }; 139 140 export default BucketNamingRules;