Skip to content

Commit

Permalink
fix(DWP): reset redux state when DWP resolves or rejects (#15766)
Browse files Browse the repository at this point in the history
* fix(DWP): reset redux state when DWP resolves or rejects

* chore(lint): fixed lint and added PR to changelog

* fix(linter): removed unused depenency in tests
  • Loading branch information
asalem1 authored Nov 5, 2019
1 parent 7b758a4 commit 0d89697
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Bug Fixes

1. [15731](https://github.com/influxdata/influxdb/pull/15731): Ensure array cursor iterator stats accumulate all cursor stats
1. [15766](https://github.com/influxdata/influxdb/pull/15766): Reset delete with predicate state after submission

## v2.0.0-alpha.19 [2019-10-30]

Expand Down
13 changes: 12 additions & 1 deletion ui/src/shared/actions/predicates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export type Action =
| SetFilter
| DeleteFilter
| SetDeletionStatus
| SetPredicateToDefault

interface SetIsSerious {
type: 'SET_IS_SERIOUS'
Expand Down Expand Up @@ -88,6 +89,14 @@ export const setDeletionStatus = (
deletionStatus: status,
})

interface SetPredicateToDefault {
type: 'SET_PREDICATE_DEFAULT'
}

export const resetPredicateState = (): SetPredicateToDefault => ({
type: 'SET_PREDICATE_DEFAULT',
})

export const deleteWithPredicate = params => async (
dispatch: Dispatch<Action>
) => {
Expand All @@ -97,10 +106,12 @@ export const deleteWithPredicate = params => async (
throw new Error(resp.data.message)
}

dispatch(notify(predicateDeleteSucceeded()))
dispatch(setDeletionStatus(RemoteDataState.Done))
dispatch(notify(predicateDeleteSucceeded()))
dispatch(resetPredicateState())
} catch {
dispatch(notify(predicateDeleteFailed()))
dispatch(setDeletionStatus(RemoteDataState.Error))
dispatch(resetPredicateState())
}
}
17 changes: 16 additions & 1 deletion ui/src/shared/reducers/predicates.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import {Filter} from 'src/types'

// Actions
import {
deleteFilter,
resetPredicateState,
setBucketName,
setFilter,
setIsSerious,
setTimeRange,
deleteFilter,
} from 'src/shared/actions/predicates'

describe('Shared.Reducers.notifications', () => {
Expand Down Expand Up @@ -50,4 +51,18 @@ describe('Shared.Reducers.notifications', () => {
result = predicatesReducer(initialState, deleteFilter(0))
expect(initialState.filters).toEqual([])
})
it('should reset the state after a filter DWP has been successfully submitted', () => {
const state = Object.assign({}, initialState)
const filter: Filter = {key: 'mean', equality: '=', value: '100'}
initialState.isSerious = predicatesReducer(
initialState,
setIsSerious(true)
).isSerious
initialState.filters = predicatesReducer(
initialState,
setFilter(filter, 0)
).filters
const result = predicatesReducer(initialState, resetPredicateState())
expect(result).toEqual(state)
})
})
9 changes: 9 additions & 0 deletions ui/src/shared/reducers/predicates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ export const predicatesReducer = (
case 'SET_DELETION_STATUS':
return {...state, deletionStatus: action.deletionStatus}

case 'SET_PREDICATE_DEFAULT':
return {
bucketName: '',
timeRange: [recently - HOUR_MS, recently],
filters: [],
isSerious: false,
deletionStatus: RemoteDataState.NotStarted,
}

default:
return state
}
Expand Down

0 comments on commit 0d89697

Please sign in to comment.