2018-02-10 08:04:14 +05:30
|
|
|
/*
|
2021-04-19 10:30:42 -07:00
|
|
|
* Copyright (c) 2015-2021 MinIO, Inc.
|
2018-02-10 08:04:14 +05:30
|
|
|
*
|
2021-04-19 10:30:42 -07:00
|
|
|
* This file is part of MinIO Object Storage stack
|
2018-02-10 08:04:14 +05:30
|
|
|
*
|
2021-04-19 10:30:42 -07: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-10 08:04:14 +05:30
|
|
|
*
|
2021-04-19 10:30:42 -07: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-10 08:04:14 +05:30
|
|
|
*/
|
|
|
|
|
2018-02-13 12:00:02 +05:30
|
|
|
import * as actionsObjects from "./actions"
|
2019-06-26 05:01:50 +05:30
|
|
|
import { SORT_ORDER_ASC } from "../constants"
|
2018-02-10 08:04:14 +05:30
|
|
|
|
2018-02-21 07:30:43 +05:30
|
|
|
const removeObject = (list, objectToRemove, lookup) => {
|
|
|
|
const idx = list.findIndex(object => lookup(object) === objectToRemove)
|
2018-02-19 09:37:59 +05:30
|
|
|
if (idx == -1) {
|
|
|
|
return list
|
|
|
|
}
|
|
|
|
return [...list.slice(0, idx), ...list.slice(idx + 1)]
|
|
|
|
}
|
|
|
|
|
2018-02-10 08:04:14 +05:30
|
|
|
export default (
|
|
|
|
state = {
|
|
|
|
list: [],
|
2020-09-18 11:31:37 +05:30
|
|
|
filter: "",
|
2019-06-26 05:01:50 +05:30
|
|
|
listLoading: false,
|
2018-02-10 08:04:14 +05:30
|
|
|
sortBy: "",
|
2019-06-26 05:01:50 +05:30
|
|
|
sortOrder: SORT_ORDER_ASC,
|
2018-02-10 08:04:14 +05:30
|
|
|
currentPrefix: "",
|
2018-02-24 08:59:30 +05:30
|
|
|
prefixWritable: false,
|
2018-02-19 09:37:59 +05:30
|
|
|
shareObject: {
|
|
|
|
show: false,
|
|
|
|
object: "",
|
2018-03-23 00:55:56 +05:30
|
|
|
url: ""
|
2018-02-21 07:30:43 +05:30
|
|
|
},
|
2018-03-23 00:55:56 +05:30
|
|
|
checkedList: []
|
2018-02-10 08:04:14 +05:30
|
|
|
},
|
2018-03-23 00:55:56 +05:30
|
|
|
action
|
2018-02-10 08:04:14 +05:30
|
|
|
) => {
|
|
|
|
switch (action.type) {
|
|
|
|
case actionsObjects.SET_LIST:
|
|
|
|
return {
|
|
|
|
...state,
|
2019-06-26 05:01:50 +05:30
|
|
|
list: action.objects
|
2018-02-10 08:04:14 +05:30
|
|
|
}
|
2018-09-05 01:32:02 +05:30
|
|
|
case actionsObjects.RESET_LIST:
|
|
|
|
return {
|
|
|
|
...state,
|
2019-06-26 05:01:50 +05:30
|
|
|
list: []
|
2018-09-05 01:32:02 +05:30
|
|
|
}
|
2020-09-18 11:31:37 +05:30
|
|
|
case actionsObjects.SET_FILTER:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
filter: action.filter
|
|
|
|
}
|
2019-06-26 05:01:50 +05:30
|
|
|
case actionsObjects.SET_LIST_LOADING:
|
2018-02-10 08:04:14 +05:30
|
|
|
return {
|
|
|
|
...state,
|
2019-06-26 05:01:50 +05:30
|
|
|
listLoading: action.listLoading
|
2018-02-10 08:04:14 +05:30
|
|
|
}
|
2018-02-19 09:37:59 +05:30
|
|
|
case actionsObjects.REMOVE:
|
|
|
|
return {
|
|
|
|
...state,
|
2018-03-23 00:55:56 +05:30
|
|
|
list: removeObject(state.list, action.object, object => object.name)
|
2018-02-19 09:37:59 +05:30
|
|
|
}
|
2018-02-10 08:04:14 +05:30
|
|
|
case actionsObjects.SET_SORT_BY:
|
|
|
|
return {
|
|
|
|
...state,
|
2018-03-23 00:55:56 +05:30
|
|
|
sortBy: action.sortBy
|
2018-02-10 08:04:14 +05:30
|
|
|
}
|
|
|
|
case actionsObjects.SET_SORT_ORDER:
|
|
|
|
return {
|
|
|
|
...state,
|
2018-03-23 00:55:56 +05:30
|
|
|
sortOrder: action.sortOrder
|
2018-02-10 08:04:14 +05:30
|
|
|
}
|
|
|
|
case actionsObjects.SET_CURRENT_PREFIX:
|
|
|
|
return {
|
|
|
|
...state,
|
2019-06-26 05:01:50 +05:30
|
|
|
currentPrefix: action.prefix
|
2018-02-10 08:04:14 +05:30
|
|
|
}
|
2018-02-24 08:59:30 +05:30
|
|
|
case actionsObjects.SET_PREFIX_WRITABLE:
|
|
|
|
return {
|
|
|
|
...state,
|
2018-03-23 00:55:56 +05:30
|
|
|
prefixWritable: action.prefixWritable
|
2018-02-24 08:59:30 +05:30
|
|
|
}
|
2018-02-19 09:37:59 +05:30
|
|
|
case actionsObjects.SET_SHARE_OBJECT:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
shareObject: {
|
|
|
|
show: action.show,
|
|
|
|
object: action.object,
|
2020-05-02 09:55:53 +03:00
|
|
|
url: action.url,
|
|
|
|
showExpiryDate: action.showExpiryDate
|
2018-03-23 00:55:56 +05:30
|
|
|
}
|
2018-02-19 09:37:59 +05:30
|
|
|
}
|
2018-02-21 07:30:43 +05:30
|
|
|
case actionsObjects.CHECKED_LIST_ADD:
|
|
|
|
return {
|
|
|
|
...state,
|
2018-03-23 00:55:56 +05:30
|
|
|
checkedList: [...state.checkedList, action.object]
|
2018-02-21 07:30:43 +05:30
|
|
|
}
|
|
|
|
case actionsObjects.CHECKED_LIST_REMOVE:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
checkedList: removeObject(
|
|
|
|
state.checkedList,
|
|
|
|
action.object,
|
2018-03-23 00:55:56 +05:30
|
|
|
object => object
|
|
|
|
)
|
2018-02-21 07:30:43 +05:30
|
|
|
}
|
|
|
|
case actionsObjects.CHECKED_LIST_RESET:
|
|
|
|
return {
|
|
|
|
...state,
|
2018-03-23 00:55:56 +05:30
|
|
|
checkedList: []
|
2018-02-21 07:30:43 +05:30
|
|
|
}
|
2018-02-10 08:04:14 +05:30
|
|
|
default:
|
|
|
|
return state
|
|
|
|
}
|
|
|
|
}
|