2018-02-09 21:34:14 -05:00
|
|
|
/*
|
2021-04-19 13:30:42 -04:00
|
|
|
* Copyright (c) 2015-2021 MinIO, Inc.
|
2018-02-09 21:34:14 -05:00
|
|
|
*
|
2021-04-19 13:30:42 -04:00
|
|
|
* This file is part of MinIO Object Storage stack
|
2018-02-09 21:34:14 -05:00
|
|
|
*
|
2021-04-19 13:30:42 -04:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2018-02-09 21:34:14 -05:00
|
|
|
*
|
2021-04-19 13:30:42 -04:00
|
|
|
* This program is distributed in the hope that it will be useful
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2018-02-09 21:34:14 -05:00
|
|
|
*/
|
|
|
|
|
2018-02-13 01:30:02 -05:00
|
|
|
import * as actionsObjects from "./actions"
|
2019-06-25 19:31:50 -04:00
|
|
|
import { SORT_ORDER_ASC } from "../constants"
|
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: [],
|
2020-09-18 02:01:37 -04:00
|
|
|
filter: "",
|
2019-06-25 19:31:50 -04:00
|
|
|
listLoading: false,
|
2018-02-09 21:34:14 -05:00
|
|
|
sortBy: "",
|
2019-06-25 19:31:50 -04:00
|
|
|
sortOrder: SORT_ORDER_ASC,
|
2018-02-09 21:34:14 -05:00
|
|
|
currentPrefix: "",
|
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,
|
2019-06-25 19:31:50 -04:00
|
|
|
list: action.objects
|
2018-02-09 21:34:14 -05:00
|
|
|
}
|
2018-09-04 16:02:02 -04:00
|
|
|
case actionsObjects.RESET_LIST:
|
|
|
|
return {
|
|
|
|
...state,
|
2019-06-25 19:31:50 -04:00
|
|
|
list: []
|
2018-09-04 16:02:02 -04:00
|
|
|
}
|
2020-09-18 02:01:37 -04:00
|
|
|
case actionsObjects.SET_FILTER:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
filter: action.filter
|
|
|
|
}
|
2019-06-25 19:31:50 -04:00
|
|
|
case actionsObjects.SET_LIST_LOADING:
|
2018-02-09 21:34:14 -05:00
|
|
|
return {
|
|
|
|
...state,
|
2019-06-25 19:31:50 -04:00
|
|
|
listLoading: action.listLoading
|
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,
|
2019-06-25 19:31:50 -04:00
|
|
|
currentPrefix: action.prefix
|
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,
|
2020-05-02 02:55:53 -04:00
|
|
|
url: action.url,
|
|
|
|
showExpiryDate: action.showExpiryDate
|
2018-03-22 15:25:56 -04:00
|
|
|
}
|
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
|
|
|
|
}
|
|
|
|
}
|