minio/browser/app/js/objects/reducer.js

128 lines
3.1 KiB
JavaScript
Raw Normal View History

2018-02-09 21:34:14 -05:00
/*
* Copyright (c) 2015-2021 MinIO, Inc.
2018-02-09 21:34:14 -05:00
*
* This file is part of MinIO Object Storage stack
2018-02-09 21:34:14 -05: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
*
* 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
*/
import * as actionsObjects from "./actions"
import { SORT_ORDER_ASC } from "../constants"
2018-02-09 21:34:14 -05:00
const removeObject = (list, objectToRemove, lookup) => {
const idx = list.findIndex(object => lookup(object) === objectToRemove)
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: [],
filter: "",
listLoading: false,
2018-02-09 21:34:14 -05:00
sortBy: "",
sortOrder: SORT_ORDER_ASC,
2018-02-09 21:34:14 -05:00
currentPrefix: "",
prefixWritable: false,
shareObject: {
show: false,
object: "",
url: ""
},
checkedList: []
2018-02-09 21:34:14 -05:00
},
action
2018-02-09 21:34:14 -05:00
) => {
switch (action.type) {
case actionsObjects.SET_LIST:
return {
...state,
list: action.objects
2018-02-09 21:34:14 -05:00
}
case actionsObjects.RESET_LIST:
return {
...state,
list: []
}
case actionsObjects.SET_FILTER:
return {
...state,
filter: action.filter
}
case actionsObjects.SET_LIST_LOADING:
2018-02-09 21:34:14 -05:00
return {
...state,
listLoading: action.listLoading
2018-02-09 21:34:14 -05:00
}
case actionsObjects.REMOVE:
return {
...state,
list: removeObject(state.list, action.object, object => object.name)
}
2018-02-09 21:34:14 -05:00
case actionsObjects.SET_SORT_BY:
return {
...state,
sortBy: action.sortBy
2018-02-09 21:34:14 -05:00
}
case actionsObjects.SET_SORT_ORDER:
return {
...state,
sortOrder: action.sortOrder
2018-02-09 21:34:14 -05:00
}
case actionsObjects.SET_CURRENT_PREFIX:
return {
...state,
currentPrefix: action.prefix
2018-02-09 21:34:14 -05:00
}
case actionsObjects.SET_PREFIX_WRITABLE:
return {
...state,
prefixWritable: action.prefixWritable
}
case actionsObjects.SET_SHARE_OBJECT:
return {
...state,
shareObject: {
show: action.show,
object: action.object,
url: action.url,
showExpiryDate: action.showExpiryDate
}
}
case actionsObjects.CHECKED_LIST_ADD:
return {
...state,
checkedList: [...state.checkedList, action.object]
}
case actionsObjects.CHECKED_LIST_REMOVE:
return {
...state,
checkedList: removeObject(
state.checkedList,
action.object,
object => object
)
}
case actionsObjects.CHECKED_LIST_RESET:
return {
...state,
checkedList: []
}
2018-02-09 21:34:14 -05:00
default:
return state
}
}