2018-02-09 21:34:14 -05:00
|
|
|
/*
|
|
|
|
* Minio Cloud Storage (C) 2018 Minio, Inc.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2018-02-13 01:30:02 -05:00
|
|
|
import * as actionsObjects from "./actions"
|
2018-02-09 21:34:14 -05:00
|
|
|
|
2018-02-20 21:00:43 -05:00
|
|
|
const removeObject = (list, objectToRemove, lookup) => {
|
|
|
|
const idx = list.findIndex(object => lookup(object) === objectToRemove)
|
2018-02-18 23:07:59 -05:00
|
|
|
if (idx == -1) {
|
|
|
|
return list
|
|
|
|
}
|
|
|
|
return [...list.slice(0, idx), ...list.slice(idx + 1)]
|
|
|
|
}
|
|
|
|
|
2018-02-09 21:34:14 -05:00
|
|
|
export default (
|
|
|
|
state = {
|
|
|
|
list: [],
|
|
|
|
sortBy: "",
|
|
|
|
sortOrder: false,
|
|
|
|
currentPrefix: "",
|
|
|
|
marker: "",
|
2018-02-18 23:07:59 -05:00
|
|
|
isTruncated: false,
|
2018-02-23 22:29:30 -05:00
|
|
|
prefixWritable: false,
|
2018-02-18 23:07:59 -05:00
|
|
|
shareObject: {
|
|
|
|
show: false,
|
|
|
|
object: "",
|
2018-03-22 15:25:56 -04:00
|
|
|
url: ""
|
2018-02-20 21:00:43 -05:00
|
|
|
},
|
2018-03-22 15:25:56 -04:00
|
|
|
checkedList: []
|
2018-02-09 21:34:14 -05:00
|
|
|
},
|
2018-03-22 15:25:56 -04:00
|
|
|
action
|
2018-02-09 21:34:14 -05:00
|
|
|
) => {
|
|
|
|
switch (action.type) {
|
|
|
|
case actionsObjects.SET_LIST:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
list: action.objects,
|
|
|
|
marker: action.marker,
|
2018-03-22 15:25:56 -04:00
|
|
|
isTruncated: action.isTruncated
|
2018-02-09 21:34:14 -05:00
|
|
|
}
|
|
|
|
case actionsObjects.APPEND_LIST:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
list: [...state.list, ...action.objects],
|
|
|
|
marker: action.marker,
|
2018-03-22 15:25:56 -04:00
|
|
|
isTruncated: action.isTruncated
|
2018-02-09 21:34:14 -05:00
|
|
|
}
|
2018-02-18 23:07:59 -05:00
|
|
|
case actionsObjects.REMOVE:
|
|
|
|
return {
|
|
|
|
...state,
|
2018-03-22 15:25:56 -04:00
|
|
|
list: removeObject(state.list, action.object, object => object.name)
|
2018-02-18 23:07:59 -05:00
|
|
|
}
|
2018-02-09 21:34:14 -05:00
|
|
|
case actionsObjects.SET_SORT_BY:
|
|
|
|
return {
|
|
|
|
...state,
|
2018-03-22 15:25:56 -04:00
|
|
|
sortBy: action.sortBy
|
2018-02-09 21:34:14 -05:00
|
|
|
}
|
|
|
|
case actionsObjects.SET_SORT_ORDER:
|
|
|
|
return {
|
|
|
|
...state,
|
2018-03-22 15:25:56 -04:00
|
|
|
sortOrder: action.sortOrder
|
2018-02-09 21:34:14 -05:00
|
|
|
}
|
|
|
|
case actionsObjects.SET_CURRENT_PREFIX:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
currentPrefix: action.prefix,
|
|
|
|
marker: "",
|
2018-03-22 15:25:56 -04:00
|
|
|
isTruncated: false
|
2018-02-09 21:34:14 -05:00
|
|
|
}
|
2018-02-23 22:29:30 -05:00
|
|
|
case actionsObjects.SET_PREFIX_WRITABLE:
|
|
|
|
return {
|
|
|
|
...state,
|
2018-03-22 15:25:56 -04:00
|
|
|
prefixWritable: action.prefixWritable
|
2018-02-23 22:29:30 -05:00
|
|
|
}
|
2018-02-18 23:07:59 -05:00
|
|
|
case actionsObjects.SET_SHARE_OBJECT:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
shareObject: {
|
|
|
|
show: action.show,
|
|
|
|
object: action.object,
|
2018-03-22 15:25:56 -04:00
|
|
|
url: action.url
|
|
|
|
}
|
2018-02-18 23:07:59 -05:00
|
|
|
}
|
2018-02-20 21:00:43 -05:00
|
|
|
case actionsObjects.CHECKED_LIST_ADD:
|
|
|
|
return {
|
|
|
|
...state,
|
2018-03-22 15:25:56 -04:00
|
|
|
checkedList: [...state.checkedList, action.object]
|
2018-02-20 21:00:43 -05:00
|
|
|
}
|
|
|
|
case actionsObjects.CHECKED_LIST_REMOVE:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
checkedList: removeObject(
|
|
|
|
state.checkedList,
|
|
|
|
action.object,
|
2018-03-22 15:25:56 -04:00
|
|
|
object => object
|
|
|
|
)
|
2018-02-20 21:00:43 -05:00
|
|
|
}
|
|
|
|
case actionsObjects.CHECKED_LIST_RESET:
|
|
|
|
return {
|
|
|
|
...state,
|
2018-03-22 15:25:56 -04:00
|
|
|
checkedList: []
|
2018-02-20 21:00:43 -05:00
|
|
|
}
|
2018-02-09 21:34:14 -05:00
|
|
|
default:
|
|
|
|
return state
|
|
|
|
}
|
|
|
|
}
|