Remove source immediately rather than wait for reload

pull/4672/head
Brandon Farmer 2018-10-30 11:35:34 -07:00
parent 39d1fad53e
commit 7387eec15e
2 changed files with 11 additions and 3 deletions

View File

@ -22,7 +22,8 @@
"tslint": "tslint -c ./tslint.json '{src,test}/**/*.ts?(x)'",
"tslint:fix": "tslint --fix -c ./tslint.json '{src,test}/**/*.ts?(x)'",
"tsc": "tsc -p ./tsconfig.json --noEmit --pretty",
"tsc:watch": "tsc -p ./tsconfig.json --noEmit --pretty -w"
"tsc:watch": "tsc -p ./tsconfig.json --noEmit --pretty -w",
"dev": "yarn clean && yarn start"
},
"author": "",
"devDependencies": {

View File

@ -137,18 +137,25 @@ export const deleteKapacitor = (kapacitor: Kapacitor) => ({
export type RemoveAndLoadSources = (
source: Source
) => (dispatch) => Promise<void>
// Async action creators
export const removeAndLoadSources = (source: Source) => async (
dispatch
dispatch,
getState
): Promise<void> => {
const {sources = []} = getState()
const filteredSources = sources.filter(s => s.id !== source.id)
dispatch(loadSources(filteredSources))
try {
try {
await deleteSource(source)
} catch (err) {
dispatch(loadSources(sources))
// A 404 means that either a concurrent write occurred or the source
// passed to this action creator doesn't exist (or is undefined)
if (err.status !== HTTP_NOT_FOUND) {
// eslint-disable-line no-magic-numbers
throw err
}
}