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