github.com/minio/console@v1.4.1/web-app/src/screens/Console/Buckets/BucketDetails/EditAccessRule.tsx (about) 1 // This file is part of MinIO Console Server 2 // Copyright (c) 2021 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 { AddAccessRuleIcon, Button, FormLayout, Grid, Select } from "mds"; 19 import { api } from "api"; 20 import { errorToHandler } from "api/errors"; 21 import { modalStyleUtils } from "../../Common/FormComponents/common/styleLibrary"; 22 import { setErrorSnackMessage } from "../../../../systemSlice"; 23 import { useAppDispatch } from "../../../../store"; 24 import ModalWrapper from "../../Common/ModalWrapper/ModalWrapper"; 25 26 interface IEditAccessRule { 27 modalOpen: boolean; 28 onClose: () => any; 29 bucket: string; 30 toEdit: string; 31 initial: string; 32 } 33 34 const EditAccessRule = ({ 35 modalOpen, 36 onClose, 37 bucket, 38 toEdit, 39 initial, 40 }: IEditAccessRule) => { 41 const dispatch = useAppDispatch(); 42 const [selectedAccess, setSelectedAccess] = useState<any>(initial); 43 44 const accessOptions = [ 45 { label: "readonly", value: "readonly" }, 46 { label: "writeonly", value: "writeonly" }, 47 { label: "readwrite", value: "readwrite" }, 48 ]; 49 50 const resetForm = () => { 51 setSelectedAccess(initial); 52 }; 53 54 const createProcess = () => { 55 api.bucket 56 .setAccessRuleWithBucket(bucket, { 57 prefix: toEdit, 58 access: selectedAccess, 59 }) 60 .then(() => { 61 onClose(); 62 }) 63 .catch((err) => { 64 dispatch(setErrorSnackMessage(errorToHandler(err.error))); 65 onClose(); 66 }); 67 }; 68 69 return ( 70 <Fragment> 71 <ModalWrapper 72 modalOpen={modalOpen} 73 title={`Edit Anonymous Access Rule for ${`${bucket}/${toEdit || ""}`}`} 74 onClose={onClose} 75 titleIcon={<AddAccessRuleIcon />} 76 > 77 <FormLayout containerPadding={false} withBorders={false}> 78 <Select 79 id="access" 80 name="Access" 81 onChange={(value) => { 82 setSelectedAccess(value); 83 }} 84 label="Access" 85 value={selectedAccess} 86 options={accessOptions} 87 disabled={false} 88 /> 89 </FormLayout> 90 <Grid item xs={12} sx={modalStyleUtils.modalButtonBar}> 91 <Button 92 id={"clear"} 93 type="button" 94 variant="regular" 95 onClick={resetForm} 96 label={"Clear"} 97 /> 98 <Button 99 id={"save"} 100 type="submit" 101 variant="callAction" 102 onClick={createProcess} 103 label={"Save"} 104 /> 105 </Grid> 106 </ModalWrapper> 107 </Fragment> 108 ); 109 }; 110 111 export default EditAccessRule;