Add timeShift actions + spec to kapa queryConfig

pull/10616/head
Andrew Watkins 2017-11-10 11:10:19 -08:00
parent e89f15934d
commit 6ef7fa8090
3 changed files with 29 additions and 0 deletions

View File

@ -325,4 +325,18 @@ describe('Chronograf.Reducers.Kapacitor.queryConfigs', () => {
expect(nextState[queryID].groupBy.time).to.equal(time) expect(nextState[queryID].groupBy.time).to.equal(time)
}) })
}) })
describe('KAPA_TIME_SHIFT', () => {
it('can shift the time', () => {
const initialState = {
[queryID]: buildInitialState(queryID),
}
const shift = {quantity: 1, unit: 'd', duration: '1d'}
const action = timeShift(queryID, shift)
const nextState = reducer(initialState, action)
expect(nextState[queryID].shift).to.deep.equal([shift])
})
})
}) })

View File

@ -69,3 +69,11 @@ export const removeFuncs = (queryID, fields) => ({
fields, fields,
}, },
}) })
export const timeShift = (queryID, shift) => ({
type: 'KAPA_TIME_SHIFT',
payload: {
queryID,
shift,
},
})

View File

@ -125,6 +125,13 @@ const queryConfigs = (state = {}, action) => {
// fields with no functions cannot have a group by time // fields with no functions cannot have a group by time
return {...state, [queryID]: nextQuery} return {...state, [queryID]: nextQuery}
} }
case 'KAPA_TIME_SHIFT': {
const {queryID, shift} = action.payload
const nextQuery = timeShift(state[queryID], shift)
return {...state, [queryID]: nextQuery}
}
} }
return state return state
} }