storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/browser/app/js/buckets/reducer.js (about) 1 /* 2 * MinIO Cloud Storage (C) 2018 MinIO, Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 import * as actionsBuckets from "./actions" 18 19 const removeBucket = (list, action) => { 20 const idx = list.findIndex(bucket => bucket === action.bucket) 21 if (idx == -1) { 22 return list 23 } 24 return [...list.slice(0, idx), ...list.slice(idx + 1)] 25 } 26 27 export default ( 28 state = { 29 list: [], 30 filter: "", 31 currentBucket: "", 32 showMakeBucketModal: false, 33 policies: [], 34 showBucketPolicy: false 35 }, 36 action 37 ) => { 38 switch (action.type) { 39 case actionsBuckets.SET_LIST: 40 return { 41 ...state, 42 list: action.buckets 43 } 44 case actionsBuckets.ADD: 45 return { 46 ...state, 47 list: [action.bucket, ...state.list] 48 } 49 case actionsBuckets.REMOVE: 50 return { 51 ...state, 52 list: removeBucket(state.list, action), 53 } 54 case actionsBuckets.SET_FILTER: 55 return { 56 ...state, 57 filter: action.filter 58 } 59 case actionsBuckets.SET_CURRENT_BUCKET: 60 return { 61 ...state, 62 currentBucket: action.bucket 63 } 64 case actionsBuckets.SHOW_MAKE_BUCKET_MODAL: 65 return { 66 ...state, 67 showMakeBucketModal: action.show 68 } 69 case actionsBuckets.SET_POLICIES: 70 return { 71 ...state, 72 policies: action.policies 73 } 74 case actionsBuckets.SHOW_BUCKET_POLICY: 75 return { 76 ...state, 77 showBucketPolicy: action.show 78 } 79 default: 80 return state 81 } 82 }