Refactor make bucket and upload components (#5521)

This commit is contained in:
Kanagaraj M
2018-02-15 08:04:59 +05:30
committed by Harshavardhana
parent 9bfa07ecf5
commit 44f8f7059c
29 changed files with 1329 additions and 213 deletions

View File

@@ -22,15 +22,6 @@ import * as actionsObjects from "./actions"
import ObjectsList from "./ObjectsList"
export class ObjectsListContainer extends React.Component {
componentWillReceiveProps(nextProps) {
const { currentBucket, currentPrefix, loadObjects } = this.props
if (
currentBucket != nextProps.currentBucket ||
currentPrefix != nextProps.currentPrefix
) {
loadObjects()
}
}
render() {
const { objects, isTruncated, currentBucket, loadObjects } = this.props
return (

View File

@@ -36,22 +36,4 @@ describe("ObjectsList", () => {
{ name: "test2.jpg" }
])
})
it("should call loadObjects when currentBucket is changed", () => {
const loadObjects = jest.fn()
const wrapper = shallow(
<ObjectsListContainer currentBucket="test1" loadObjects={loadObjects} />
)
wrapper.setProps({ currentBucket: "test2" })
expect(loadObjects).toHaveBeenCalled()
})
it("should call loadObjects when currentPrefix is changed", () => {
const loadObjects = jest.fn()
const wrapper = shallow(
<ObjectsListContainer currentPrefix="abc/" loadObjects={loadObjects} />
)
wrapper.setProps({ currentPrefix: "abc/xyz/" })
expect(loadObjects).toHaveBeenCalled()
})
})

View File

@@ -158,7 +158,8 @@ describe("Objects actions", () => {
it("should update browser url and creates objects/SET_CURRENT_PREFIX action when selectPrefix is called", () => {
const store = mockStore({
buckets: { currentBucket: "test" }
buckets: { currentBucket: "test" },
objects: { currentPrefix: "" }
})
const expectedActions = [
{ type: "objects/SET_CURRENT_PREFIX", prefix: "abc/" }

View File

@@ -21,9 +21,11 @@ import {
sortObjectsBySize,
sortObjectsByDate
} from "../utils"
import { getCurrentBucket } from "../buckets/selectors"
export const SET_LIST = "objects/SET_LIST"
export const APPEND_LIST = "objects/APPEND_LIST"
export const RESET = "objects/RESET"
export const SET_SORT_BY = "objects/SET_SORT_BY"
export const SET_SORT_ORDER = "objects/SET_SORT_ORDER"
export const SET_CURRENT_PREFIX = "objects/SET_CURRENT_PREFIX"
@@ -52,7 +54,7 @@ export const fetchObjects = append => {
.ListObjects({
bucketName: currentBucket,
prefix: currentPrefix,
marker: marker
marker: append ? marker : ""
})
.then(res => {
let objects = []
@@ -113,7 +115,8 @@ export const setSortOrder = sortOrder => ({
export const selectPrefix = prefix => {
return function(dispatch, getState) {
dispatch(setCurrentPrefix(prefix))
const currentBucket = getState().buckets.currentBucket
dispatch(fetchObjects())
const currentBucket = getCurrentBucket(getState())
history.replace(`/${currentBucket}/${prefix}`)
}
}

View File

@@ -0,0 +1,19 @@
/*
* 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.
*/
import { createSelector } from "reselect"
export const getCurrentPrefix = state => state.objects.currentPrefix