Fix failing unit tests in browser (#5688)

* format js files using prettier

Used the following command to format the files
prettier --write "browser/app/js/**/*.js"

* fix failing unit tests in browser
This commit is contained in:
Kanagaraj M
2018-03-23 00:55:56 +05:30
committed by Harshavardhana
parent cb3818be27
commit c0e45f9098
95 changed files with 839 additions and 890 deletions

View File

@@ -23,7 +23,7 @@ export const Bucket = ({ bucket, isActive, selectBucket }) => {
<div
className={classNames({
buckets__item: true,
"buckets__item--active": isActive,
"buckets__item--active": isActive
})}
onClick={e => {
e.preventDefault()

View File

@@ -22,13 +22,13 @@ import Bucket from "./Bucket"
const mapStateToProps = (state, ownProps) => {
return {
isActive: getCurrentBucket(state) === ownProps.bucket,
isActive: getCurrentBucket(state) === ownProps.bucket
}
}
const mapDispatchToProps = dispatch => {
return {
selectBucket: bucket => dispatch(actionsBuckets.selectBucket(bucket)),
selectBucket: bucket => dispatch(actionsBuckets.selectBucket(bucket))
}
}

View File

@@ -26,18 +26,18 @@ export class BucketDropdown extends React.Component {
constructor(props) {
super(props)
this.state = {
showBucketDropdown: false,
showBucketDropdown: false
}
}
toggleDropdown() {
if (this.state.showBucketDropdown) {
this.setState({
showBucketDropdown: false,
showBucketDropdown: false
})
} else {
this.setState({
showBucketDropdown: true,
showBucketDropdown: true
})
}
}
@@ -83,7 +83,7 @@ export class BucketDropdown extends React.Component {
const mapDispatchToProps = dispatch => {
return {
deleteBucket: bucket => dispatch(actionsBuckets.deleteBucket(bucket)),
showBucketPolicy: () => dispatch(actionsBuckets.showBucketPolicy()),
showBucketPolicy: () => dispatch(actionsBuckets.showBucketPolicy())
}
}

View File

@@ -25,7 +25,7 @@ export const BucketPolicyModal = ({
showBucketPolicy,
currentBucket,
hideBucketPolicy,
policies,
policies
}) => {
return (
<Modal
@@ -53,13 +53,13 @@ const mapStateToProps = state => {
return {
currentBucket: state.buckets.currentBucket,
showBucketPolicy: state.buckets.showBucketPolicy,
policies: state.buckets.policies,
policies: state.buckets.policies
}
}
const mapDispatchToProps = dispatch => {
return {
hideBucketPolicy: () => dispatch(actionsBuckets.hideBucketPolicy()),
hideBucketPolicy: () => dispatch(actionsBuckets.hideBucketPolicy())
}
}

View File

@@ -37,7 +37,7 @@ const mapDispatchToProps = dispatch => {
return {
onChange: filter => {
dispatch(actionsBuckets.setFilter(filter))
},
}
}
}

View File

@@ -23,7 +23,7 @@ export class MakeBucketModal extends React.Component {
constructor(props) {
super(props)
this.state = {
bucketName: "",
bucketName: ""
}
}
onSubmit(e) {
@@ -37,7 +37,7 @@ export class MakeBucketModal extends React.Component {
}
hideModal() {
this.setState({
bucketName: "",
bucketName: ""
})
this.props.hideMakeBucketModal()
}
@@ -62,7 +62,7 @@ export class MakeBucketModal extends React.Component {
value={this.state.bucketName}
onChange={e =>
this.setState({
bucketName: e.target.value,
bucketName: e.target.value
})
}
autoFocus
@@ -78,14 +78,14 @@ export class MakeBucketModal extends React.Component {
const mapStateToProps = state => {
return {
showMakeBucketModal: state.buckets.showMakeBucketModal,
showMakeBucketModal: state.buckets.showMakeBucketModal
}
}
const mapDispatchToProps = dispatch => {
return {
makeBucket: bucket => dispatch(actionsBuckets.makeBucket(bucket)),
hideMakeBucketModal: () => dispatch(actionsBuckets.hideMakeBucketModal()),
hideMakeBucketModal: () => dispatch(actionsBuckets.hideMakeBucketModal())
}
}

View File

@@ -28,7 +28,7 @@ export class Policy extends React.Component {
.SetBucketPolicy({
bucketName: currentBucket,
prefix: prefix,
policy: "none",
policy: "none"
})
.then(() => {
fetchPolicies(currentBucket)
@@ -79,7 +79,7 @@ export class Policy extends React.Component {
const mapStateToProps = state => {
return {
currentBucket: state.buckets.currentBucket,
currentBucket: state.buckets.currentBucket
}
}
@@ -90,9 +90,9 @@ const mapDispatchToProps = dispatch => {
dispatch(
actionsAlert.set({
type: type,
message: message,
}),
),
message: message
})
)
}
}

View File

@@ -42,7 +42,7 @@ export class PolicyInput extends React.Component {
let policyAlreadyExists = this.props.policies.some(
elem =>
this.prefix.value === elem.prefix && this.policy.value === elem.policy,
this.prefix.value === elem.prefix && this.policy.value === elem.policy
)
if (policyAlreadyExists) {
showAlert("danger", "Policy for this prefix already exists.")
@@ -53,7 +53,7 @@ export class PolicyInput extends React.Component {
.SetBucketPolicy({
bucketName: currentBucket,
prefix: this.prefix.value,
policy: this.policy.value,
policy: this.policy.value
})
.then(() => {
fetchPolicies(currentBucket)
@@ -99,7 +99,7 @@ export class PolicyInput extends React.Component {
const mapStateToProps = state => {
return {
currentBucket: state.buckets.currentBucket,
policies: state.buckets.policies,
policies: state.buckets.policies
}
}
@@ -111,9 +111,9 @@ const mapDispatchToProps = dispatch => {
dispatch(
actionsAlert.set({
type: type,
message: message,
}),
),
message: message
})
)
}
}

View File

@@ -26,16 +26,16 @@ describe("Bucket", () => {
it("should call selectBucket when clicked", () => {
const selectBucket = jest.fn()
const wrapper = shallow(
<Bucket bucket={"test"} selectBucket={selectBucket} />,
<Bucket bucket={"test"} selectBucket={selectBucket} />
)
wrapper.find("li").simulate("click", {
preventDefault: jest.fn(),
wrapper.find("div").simulate("click", {
preventDefault: jest.fn()
})
expect(selectBucket).toHaveBeenCalledWith("test")
})
it("should highlight the selected bucket", () => {
const wrapper = shallow(<Bucket bucket={"test"} isActive={true} />)
expect(wrapper.find("li").hasClass("active")).toBeTruthy()
expect(wrapper.find("div").hasClass("buckets__item--active")).toBeTruthy()
})
})

View File

@@ -26,8 +26,8 @@ describe("BucketContainer", () => {
beforeEach(() => {
store = mockStore({
buckets: {
currentBucket: "Test",
},
currentBucket: "Test"
}
})
store.dispatch = jest.fn()
})
@@ -41,8 +41,8 @@ describe("BucketContainer", () => {
expect(wrapper.props()).toEqual(
expect.objectContaining({
isActive: expect.any(Boolean),
selectBucket: expect.any(Function),
}),
selectBucket: expect.any(Function)
})
)
})

View File

@@ -35,13 +35,13 @@ describe("BucketDropdown", () => {
it("should call showBucketPolicy when Edit Policy link is clicked", () => {
const showBucketPolicy = jest.fn()
const wrapper = shallow(
<BucketDropdown showBucketPolicy={showBucketPolicy} />,
<BucketDropdown showBucketPolicy={showBucketPolicy} />
)
wrapper
.find("li a")
.find("MenuItem")
.at(0)
.simulate("click", {
stopPropagation: jest.fn(),
stopPropagation: jest.fn()
})
expect(showBucketPolicy).toHaveBeenCalled()
})
@@ -49,13 +49,13 @@ describe("BucketDropdown", () => {
it("should call deleteBucket when Delete link is clicked", () => {
const deleteBucket = jest.fn()
const wrapper = shallow(
<BucketDropdown bucket={"test"} deleteBucket={deleteBucket} />,
<BucketDropdown bucket={"test"} deleteBucket={deleteBucket} />
)
wrapper
.find("li a")
.find("MenuItem")
.at(1)
.simulate("click", {
stopPropagation: jest.fn(),
stopPropagation: jest.fn()
})
expect(deleteBucket).toHaveBeenCalledWith("test")
})

View File

@@ -23,19 +23,19 @@ jest.mock("../../web", () => ({
LoggedIn: jest
.fn(() => false)
.mockReturnValueOnce(true)
.mockReturnValueOnce(true),
.mockReturnValueOnce(true)
}))
describe("BucketList", () => {
it("should render without crashing", () => {
const fetchBuckets = jest.fn()
shallow(<BucketList visibleBuckets={[]} fetchBuckets={fetchBuckets} />)
shallow(<BucketList filteredBuckets={[]} fetchBuckets={fetchBuckets} />)
})
it("should call fetchBuckets before component is mounted", () => {
const fetchBuckets = jest.fn()
const wrapper = shallow(
<BucketList visibleBuckets={[]} fetchBuckets={fetchBuckets} />,
<BucketList filteredBuckets={[]} fetchBuckets={fetchBuckets} />
)
expect(fetchBuckets).toHaveBeenCalled()
})
@@ -46,10 +46,10 @@ describe("BucketList", () => {
history.push("/bk1/pre1")
const wrapper = shallow(
<BucketList
visibleBuckets={[]}
filteredBuckets={[]}
setBucketList={setBucketList}
selectBucket={selectBucket}
/>,
/>
)
expect(setBucketList).toHaveBeenCalledWith(["bk1"])
expect(selectBucket).toHaveBeenCalledWith("bk1", "pre1")

View File

@@ -27,15 +27,15 @@ describe("BucketPolicyModal", () => {
it("should call hideBucketPolicy when close button is clicked", () => {
const hideBucketPolicy = jest.fn()
const wrapper = shallow(
<BucketPolicyModal hideBucketPolicy={hideBucketPolicy} policies={[]} />,
<BucketPolicyModal hideBucketPolicy={hideBucketPolicy} policies={[]} />
)
wrapper.find("button").simulate("click")
wrapper.find("i.close").simulate("click")
expect(hideBucketPolicy).toHaveBeenCalled()
})
it("should include the PolicyInput and Policy components when there are any policies", () => {
const wrapper = shallow(
<BucketPolicyModal policies={[{ prefix: "test", policy: READ_ONLY }]} />,
<BucketPolicyModal policies={[{ prefix: "test", policy: READ_ONLY }]} />
)
expect(wrapper.find("Connect(PolicyInput)").length).toBe(1)
expect(wrapper.find("Connect(Policy)").length).toBe(1)

View File

@@ -28,8 +28,8 @@ describe("BucketSearch", () => {
const wrapper = shallow(<BucketSearch onChange={onChange} />)
wrapper.find("input").simulate("change", {
target: {
value: "test",
},
value: "test"
}
})
expect(onChange).toHaveBeenCalledWith("test")
})

View File

@@ -26,24 +26,24 @@ describe("MakeBucketModal", () => {
it("should call hideMakeBucketModal when close button is clicked", () => {
const hideMakeBucketModal = jest.fn()
const wrapper = shallow(
<MakeBucketModal hideMakeBucketModal={hideMakeBucketModal} />,
<MakeBucketModal hideMakeBucketModal={hideMakeBucketModal} />
)
wrapper.find("button").simulate("click")
wrapper.find("i.close").simulate("click")
expect(hideMakeBucketModal).toHaveBeenCalled()
})
it("bucketName should be cleared before hiding the modal", () => {
const hideMakeBucketModal = jest.fn()
const wrapper = shallow(
<MakeBucketModal hideMakeBucketModal={hideMakeBucketModal} />,
<MakeBucketModal hideMakeBucketModal={hideMakeBucketModal} />
)
wrapper.find("input").simulate("change", {
target: {
value: "test",
},
value: "test"
}
})
expect(wrapper.state("bucketName")).toBe("test")
wrapper.find("button").simulate("click")
wrapper.find("i.close").simulate("click")
expect(wrapper.state("bucketName")).toBe("")
})
@@ -54,15 +54,15 @@ describe("MakeBucketModal", () => {
<MakeBucketModal
makeBucket={makeBucket}
hideMakeBucketModal={hideMakeBucketModal}
/>,
/>
)
wrapper.find("input").simulate("change", {
target: {
value: "test",
},
value: "test"
}
})
wrapper.find("form").simulate("submit", {
preventDefault: jest.fn(),
preventDefault: jest.fn()
})
expect(makeBucket).toHaveBeenCalledWith("test")
})
@@ -74,15 +74,15 @@ describe("MakeBucketModal", () => {
<MakeBucketModal
makeBucket={makeBucket}
hideMakeBucketModal={hideMakeBucketModal}
/>,
/>
)
wrapper.find("input").simulate("change", {
target: {
value: "test",
},
value: "test"
}
})
wrapper.find("form").simulate("submit", {
preventDefault: jest.fn(),
preventDefault: jest.fn()
})
expect(hideMakeBucketModal).toHaveBeenCalled()
expect(wrapper.state("bucketName")).toBe("")

View File

@@ -23,13 +23,13 @@ import web from "../../web"
jest.mock("../../web", () => ({
SetBucketPolicy: jest.fn(() => {
return Promise.resolve()
}),
})
}))
describe("Policy", () => {
it("should render without crashing", () => {
shallow(
<Policy currentBucket={"bucket"} prefix={"foo"} policy={READ_ONLY} />,
<Policy currentBucket={"bucket"} prefix={"foo"} policy={READ_ONLY} />
)
})
@@ -41,16 +41,16 @@ describe("Policy", () => {
prefix={"foo"}
policy={READ_ONLY}
fetchPolicies={fetchPolicies}
/>,
/>
)
wrapper.find("button").simulate("click", {
preventDefault: jest.fn(),
preventDefault: jest.fn()
})
expect(web.SetBucketPolicy).toHaveBeenCalledWith({
bucketName: "bucket",
prefix: "foo",
policy: "none",
policy: "none"
})
setImmediate(() => {
@@ -60,13 +60,13 @@ describe("Policy", () => {
it("should change the empty string to '*' while displaying prefixes", () => {
const wrapper = shallow(
<Policy currentBucket={"bucket"} prefix={""} policy={READ_ONLY} />,
<Policy currentBucket={"bucket"} prefix={""} policy={READ_ONLY} />
)
expect(
wrapper
.find(".pmbl-item")
.find("input")
.at(0)
.text(),
.prop("value")
).toEqual("*")
})
})

View File

@@ -23,21 +23,21 @@ import web from "../../web"
jest.mock("../../web", () => ({
SetBucketPolicy: jest.fn(() => {
return Promise.resolve()
}),
})
}))
describe("PolicyInput", () => {
it("should render without crashing", () => {
const fetchPolicies = jest.fn()
shallow(
<PolicyInput currentBucket={"bucket"} fetchPolicies={fetchPolicies} />,
<PolicyInput currentBucket={"bucket"} fetchPolicies={fetchPolicies} />
)
})
it("should call fetchPolicies after the component has mounted", () => {
const fetchPolicies = jest.fn()
const wrapper = shallow(
<PolicyInput currentBucket={"bucket"} fetchPolicies={fetchPolicies} />,
<PolicyInput currentBucket={"bucket"} fetchPolicies={fetchPolicies} />
)
setImmediate(() => {
expect(fetchPolicies).toHaveBeenCalled()
@@ -51,22 +51,22 @@ describe("PolicyInput", () => {
currentBucket={"bucket"}
policies={[]}
fetchPolicies={fetchPolicies}
/>,
/>
)
wrapper.instance().prefix = {
value: "baz",
value: "baz"
}
wrapper.instance().policy = {
value: READ_ONLY,
value: READ_ONLY
}
wrapper.find("button").simulate("click", {
preventDefault: jest.fn(),
preventDefault: jest.fn()
})
expect(web.SetBucketPolicy).toHaveBeenCalledWith({
bucketName: "bucket",
prefix: "baz",
policy: READ_ONLY,
policy: READ_ONLY
})
setImmediate(() => {
@@ -81,21 +81,21 @@ describe("PolicyInput", () => {
currentBucket={"bucket"}
policies={[]}
fetchPolicies={fetchPolicies}
/>,
/>
)
wrapper.instance().prefix = {
value: "*",
value: "*"
}
wrapper.instance().policy = {
value: READ_ONLY,
value: READ_ONLY
}
wrapper.find("button").simulate("click", {
preventDefault: jest.fn(),
preventDefault: jest.fn()
})
expect(wrapper.instance().prefix).toEqual({
value: "",
value: ""
})
})
})

View File

@@ -24,12 +24,12 @@ jest.mock("../../web", () => ({
return Promise.resolve({
buckets: [
{
name: "test1",
name: "test1"
},
{
name: "test2",
},
],
name: "test2"
}
]
})
}),
MakeBucket: jest.fn(() => {
@@ -37,11 +37,11 @@ jest.mock("../../web", () => ({
}),
DeleteBucket: jest.fn(() => {
return Promise.resolve()
}),
})
}))
jest.mock("../../objects/actions", () => ({
selectPrefix: () => dispatch => {},
selectPrefix: () => dispatch => {}
}))
const middlewares = [thunk]
@@ -53,12 +53,12 @@ describe("Buckets actions", () => {
const expectedActions = [
{
type: "buckets/SET_LIST",
buckets: ["test1", "test2"],
buckets: ["test1", "test2"]
},
{
type: "buckets/SET_CURRENT_BUCKET",
bucket: "test1",
},
bucket: "test1"
}
]
return store.dispatch(actionsBuckets.fetchBuckets()).then(() => {
const actions = store.getActions()
@@ -72,12 +72,12 @@ describe("Buckets actions", () => {
const expectedActions = [
{
type: "buckets/SET_LIST",
buckets: ["test1", "test2"],
buckets: ["test1", "test2"]
},
{
type: "buckets/SET_CURRENT_BUCKET",
bucket: "test2",
},
bucket: "test2"
}
]
window.location
return store.dispatch(actionsBuckets.fetchBuckets()).then(() => {
@@ -92,12 +92,12 @@ describe("Buckets actions", () => {
const expectedActions = [
{
type: "buckets/SET_LIST",
buckets: ["test1", "test2"],
buckets: ["test1", "test2"]
},
{
type: "buckets/SET_CURRENT_BUCKET",
bucket: "test1",
},
bucket: "test1"
}
]
window.location
return store.dispatch(actionsBuckets.fetchBuckets()).then(() => {
@@ -111,8 +111,8 @@ describe("Buckets actions", () => {
const expectedActions = [
{
type: "buckets/SET_CURRENT_BUCKET",
bucket: "test1",
},
bucket: "test1"
}
]
store.dispatch(actionsBuckets.selectBucket("test1"))
const actions = store.getActions()
@@ -124,8 +124,8 @@ describe("Buckets actions", () => {
const expectedActions = [
{
type: "buckets/SHOW_MAKE_BUCKET_MODAL",
show: true,
},
show: true
}
]
store.dispatch(actionsBuckets.showMakeBucketModal())
const actions = store.getActions()
@@ -137,8 +137,8 @@ describe("Buckets actions", () => {
const expectedActions = [
{
type: "buckets/SHOW_MAKE_BUCKET_MODAL",
show: false,
},
show: false
}
]
store.dispatch(actionsBuckets.hideMakeBucketModal())
const actions = store.getActions()
@@ -150,8 +150,8 @@ describe("Buckets actions", () => {
const expectedActions = [
{
type: "buckets/SHOW_BUCKET_POLICY",
show: true,
},
show: true
}
]
store.dispatch(actionsBuckets.showBucketPolicy())
const actions = store.getActions()
@@ -163,8 +163,8 @@ describe("Buckets actions", () => {
const expectedActions = [
{
type: "buckets/SHOW_BUCKET_POLICY",
show: false,
},
show: false
}
]
store.dispatch(actionsBuckets.hideBucketPolicy())
const actions = store.getActions()
@@ -176,8 +176,8 @@ describe("Buckets actions", () => {
const expectedActions = [
{
type: "buckets/SET_POLICIES",
policies: ["test1", "test2"],
},
policies: ["test1", "test2"]
}
]
store.dispatch(actionsBuckets.setPolicies(["test1", "test2"]))
const actions = store.getActions()
@@ -189,8 +189,8 @@ describe("Buckets actions", () => {
const expectedActions = [
{
type: "buckets/ADD",
bucket: "test",
},
bucket: "test"
}
]
store.dispatch(actionsBuckets.addBucket("test"))
const actions = store.getActions()
@@ -202,8 +202,8 @@ describe("Buckets actions", () => {
const expectedActions = [
{
type: "buckets/REMOVE",
bucket: "test",
},
bucket: "test"
}
]
store.dispatch(actionsBuckets.removeBucket("test"))
const actions = store.getActions()
@@ -215,12 +215,12 @@ describe("Buckets actions", () => {
const expectedActions = [
{
type: "buckets/ADD",
bucket: "test1",
bucket: "test1"
},
{
type: "buckets/SET_CURRENT_BUCKET",
bucket: "test1",
},
bucket: "test1"
}
]
return store.dispatch(actionsBuckets.makeBucket("test1")).then(() => {
const actions = store.getActions()
@@ -239,26 +239,26 @@ describe("Buckets actions", () => {
alert: {
id: 0,
message: "Bucket 'test3' has been deleted.",
type: "info",
},
type: "info"
}
},
{
type: "buckets/REMOVE",
bucket: "test3",
bucket: "test3"
},
{
type: "buckets/SET_LIST",
buckets: ["test1", "test2"],
buckets: ["test1", "test2"]
},
{
type: "buckets/SET_CURRENT_BUCKET",
bucket: "test1",
},
bucket: "test1"
}
]
return store.dispatch(actionsBuckets.deleteBucket("test3")).then(() => {
const actions = store.getActions()
expect(actions).toEqual(expectedActions)
})
},
}
)
})

View File

@@ -26,14 +26,14 @@ describe("buckets reducer", () => {
filter: "",
currentBucket: "",
showBucketPolicy: false,
showMakeBucketModal: false,
showMakeBucketModal: false
})
})
it("should handle SET_LIST", () => {
const newState = reducer(undefined, {
type: actions.SET_LIST,
buckets: ["bk1", "bk2"],
buckets: ["bk1", "bk2"]
})
expect(newState.list).toEqual(["bk1", "bk2"])
})
@@ -41,12 +41,12 @@ describe("buckets reducer", () => {
it("should handle ADD", () => {
const newState = reducer(
{
list: ["test1", "test2"],
list: ["test1", "test2"]
},
{
type: actions.ADD,
bucket: "test3",
},
bucket: "test3"
}
)
expect(newState.list).toEqual(["test3", "test1", "test2"])
})
@@ -54,12 +54,12 @@ describe("buckets reducer", () => {
it("should handle REMOVE", () => {
const newState = reducer(
{
list: ["test1", "test2"],
list: ["test1", "test2"]
},
{
type: actions.REMOVE,
bucket: "test2",
},
bucket: "test2"
}
)
expect(newState.list).toEqual(["test1"])
})
@@ -67,7 +67,7 @@ describe("buckets reducer", () => {
it("should handle SET_FILTER", () => {
const newState = reducer(undefined, {
type: actions.SET_FILTER,
filter: "test",
filter: "test"
})
expect(newState.filter).toEqual("test")
})
@@ -75,7 +75,7 @@ describe("buckets reducer", () => {
it("should handle SET_CURRENT_BUCKET", () => {
const newState = reducer(undefined, {
type: actions.SET_CURRENT_BUCKET,
bucket: "test",
bucket: "test"
})
expect(newState.currentBucket).toEqual("test")
})
@@ -83,7 +83,7 @@ describe("buckets reducer", () => {
it("should handle SET_POLICIES", () => {
const newState = reducer(undefined, {
type: actions.SET_POLICIES,
policies: ["test1", "test2"],
policies: ["test1", "test2"]
})
expect(newState.policies).toEqual(["test1", "test2"])
})
@@ -91,7 +91,7 @@ describe("buckets reducer", () => {
it("should handle SHOW_BUCKET_POLICY", () => {
const newState = reducer(undefined, {
type: actions.SHOW_BUCKET_POLICY,
show: true,
show: true
})
expect(newState.showBucketPolicy).toBeTruthy()
})
@@ -99,7 +99,7 @@ describe("buckets reducer", () => {
it("should handle SHOW_MAKE_BUCKET_MODAL", () => {
const newState = reducer(undefined, {
type: actions.SHOW_MAKE_BUCKET_MODAL,
show: true,
show: true
})
expect(newState.showMakeBucketModal).toBeTruthy()
})

View File

@@ -52,14 +52,14 @@ export const fetchBuckets = () => {
export const setList = buckets => {
return {
type: SET_LIST,
buckets,
buckets
}
}
export const setFilter = filter => {
return {
type: SET_FILTER,
filter,
filter
}
}
@@ -73,7 +73,7 @@ export const selectBucket = (bucket, prefix) => {
export const setCurrentBucket = bucket => {
return {
type: SET_CURRENT_BUCKET,
bucket,
bucket
}
}
@@ -81,7 +81,7 @@ export const makeBucket = bucket => {
return function(dispatch) {
return web
.MakeBucket({
bucketName: bucket,
bucketName: bucket
})
.then(() => {
dispatch(addBucket(bucket))
@@ -91,9 +91,9 @@ export const makeBucket = bucket => {
dispatch(
alertActions.set({
type: "danger",
message: err.message,
}),
),
message: err.message
})
)
)
}
}
@@ -102,14 +102,14 @@ export const deleteBucket = bucket => {
return function(dispatch) {
return web
.DeleteBucket({
bucketName: bucket,
bucketName: bucket
})
.then(() => {
dispatch(
alertActions.set({
type: "info",
message: "Bucket '" + bucket + "' has been deleted.",
}),
message: "Bucket '" + bucket + "' has been deleted."
})
)
dispatch(removeBucket(bucket))
dispatch(fetchBuckets())
@@ -118,8 +118,8 @@ export const deleteBucket = bucket => {
dispatch(
alertActions.set({
type: "danger",
message: err.message,
}),
message: err.message
})
)
})
}
@@ -127,29 +127,29 @@ export const deleteBucket = bucket => {
export const addBucket = bucket => ({
type: ADD,
bucket,
bucket
})
export const removeBucket = bucket => ({
type: REMOVE,
bucket,
bucket
})
export const showMakeBucketModal = () => ({
type: SHOW_MAKE_BUCKET_MODAL,
show: true,
show: true
})
export const hideMakeBucketModal = () => ({
type: SHOW_MAKE_BUCKET_MODAL,
show: false,
show: false
})
export const fetchPolicies = bucket => {
return function(dispatch) {
return web
.ListAllBucketPolicies({
bucketName: bucket,
bucketName: bucket
})
.then(res => {
let policies = res.policies
@@ -160,8 +160,8 @@ export const fetchPolicies = bucket => {
dispatch(
alertActions.set({
type: "danger",
message: err.message,
}),
message: err.message
})
)
})
}
@@ -169,15 +169,15 @@ export const fetchPolicies = bucket => {
export const setPolicies = policies => ({
type: SET_POLICIES,
policies,
policies
})
export const showBucketPolicy = () => ({
type: SHOW_BUCKET_POLICY,
show: true,
show: true
})
export const hideBucketPolicy = () => ({
type: SHOW_BUCKET_POLICY,
show: false,
show: false
})

View File

@@ -31,50 +31,50 @@ export default (
currentBucket: "",
showMakeBucketModal: false,
policies: [],
showBucketPolicy: false,
showBucketPolicy: false
},
action,
action
) => {
switch (action.type) {
case actionsBuckets.SET_LIST:
return {
...state,
list: action.buckets,
list: action.buckets
}
case actionsBuckets.ADD:
return {
...state,
list: [action.bucket, ...state.list],
list: [action.bucket, ...state.list]
}
case actionsBuckets.REMOVE:
return {
...state,
list: removeBucket(state.list, action),
list: removeBucket(state.list, action)
}
case actionsBuckets.SET_FILTER:
return {
...state,
filter: action.filter,
filter: action.filter
}
case actionsBuckets.SET_CURRENT_BUCKET:
return {
...state,
currentBucket: action.bucket,
currentBucket: action.bucket
}
case actionsBuckets.SHOW_MAKE_BUCKET_MODAL:
return {
...state,
showMakeBucketModal: action.show,
showMakeBucketModal: action.show
}
case actionsBuckets.SET_POLICIES:
return {
...state,
policies: action.policies,
policies: action.policies
}
case actionsBuckets.SHOW_BUCKET_POLICY:
return {
...state,
showBucketPolicy: action.show,
showBucketPolicy: action.show
}
default:
return state

View File

@@ -22,7 +22,7 @@ const bucketsFilterSelector = state => state.buckets.filter
export const getFilteredBuckets = createSelector(
bucketsSelector,
bucketsFilterSelector,
(buckets, filter) => buckets.filter(bucket => bucket.indexOf(filter) > -1),
(buckets, filter) => buckets.filter(bucket => bucket.indexOf(filter) > -1)
)
export const getCurrentBucket = state => state.buckets.currentBucket