fix success alert not shown after object is uploaded (#6500)

This commit is contained in:
Kanagaraj M 2018-09-20 22:54:09 +05:30 committed by Nitish Tiwari
parent b62ed5dc90
commit 7c339e248a
4 changed files with 64 additions and 69 deletions

View File

@ -22,7 +22,7 @@ export let alertId = 0
export const set = alert => { export const set = alert => {
const id = alertId++ const id = alertId++
return (dispatch, getState) => { return (dispatch, getState) => {
if (alert.type !== "danger") { if (alert.type !== "danger" || alert.autoClear) {
setTimeout(() => { setTimeout(() => {
dispatch({ dispatch({
type: CLEAR, type: CLEAR,

View File

@ -123,9 +123,6 @@ describe("Objects actions", () => {
objects: { currentPrefix: "" } objects: { currentPrefix: "" }
}) })
const expectedActions = [ const expectedActions = [
{
type: "alert/CLEAR"
},
{ {
type: "objects/SET_LIST", type: "objects/SET_LIST",
objects: [{ name: "test1" }, { name: "test2" }], objects: [{ name: "test1" }, { name: "test2" }],
@ -157,9 +154,6 @@ describe("Objects actions", () => {
objects: { currentPrefix: "" } objects: { currentPrefix: "" }
}) })
const expectedActions = [ const expectedActions = [
{
type: "alert/CLEAR"
},
{ {
type: "objects/APPEND_LIST", type: "objects/APPEND_LIST",
objects: [{ name: "test1" }, { name: "test2" }], objects: [{ name: "test1" }, { name: "test2" }],
@ -183,15 +177,13 @@ describe("Objects actions", () => {
objects: { currentPrefix: "" } objects: { currentPrefix: "" }
}) })
const expectedActions = [ const expectedActions = [
{
type: "alert/CLEAR"
},
{ {
type: "alert/SET", type: "alert/SET",
alert: { alert: {
type: "danger", type: "danger",
message: "listobjects is denied", message: "listobjects is denied",
id: alertActions.alertId id: alertActions.alertId,
autoClear: true
} }
}, },
{ {
@ -252,7 +244,6 @@ describe("Objects actions", () => {
}) })
const expectedActions = [ const expectedActions = [
{ type: "objects/SET_CURRENT_PREFIX", prefix: "abc/" }, { type: "objects/SET_CURRENT_PREFIX", prefix: "abc/" },
{ type: "alert/CLEAR" },
{ type: "objects/CHECKED_LIST_RESET" } { type: "objects/CHECKED_LIST_RESET" }
] ]
store.dispatch(actionsObjects.selectPrefix("abc/")) store.dispatch(actionsObjects.selectPrefix("abc/"))

View File

@ -64,43 +64,47 @@ export const fetchObjects = append => {
buckets: { currentBucket }, buckets: { currentBucket },
objects: { currentPrefix, marker } objects: { currentPrefix, marker }
} = getState() } = getState()
dispatch(alertActions.clear())
if (currentBucket) { if (currentBucket) {
return web return web
.ListObjects({ .ListObjects({
bucketName: currentBucket, bucketName: currentBucket,
prefix: currentPrefix, prefix: currentPrefix,
marker: append ? marker : "" marker: append ? marker : ""
}) })
.then(res => { .then(res => {
let objects = [] let objects = []
if (res.objects) { if (res.objects) {
objects = res.objects.map(object => { objects = res.objects.map(object => {
return { return {
...object, ...object,
name: object.name.replace(currentPrefix, "") name: object.name.replace(currentPrefix, "")
} }
}) })
} }
if (append) { if (append) {
dispatch(appendList(objects, res.nextmarker, res.istruncated)) dispatch(appendList(objects, res.nextmarker, res.istruncated))
} else { } else {
dispatch(setList(objects, res.nextmarker, res.istruncated)) dispatch(setList(objects, res.nextmarker, res.istruncated))
dispatch(setSortBy("")) dispatch(setSortBy(""))
dispatch(setSortOrder(false)) dispatch(setSortOrder(false))
} }
dispatch(setPrefixWritable(res.writable)) dispatch(setPrefixWritable(res.writable))
}) })
.catch(err => { .catch(err => {
if (web.LoggedIn()) { if (web.LoggedIn()) {
dispatch(alertActions.set({ type: "danger", message: err.message })) dispatch(
dispatch(resetList()) alertActions.set({
} type: "danger",
else { message: err.message,
history.push("/login") autoClear: true
} })
}) )
} dispatch(resetList())
} else {
history.push("/login")
}
})
}
} }
} }

File diff suppressed because one or more lines are too long