Introduce dashTime reducer v1

pull/2083/head
Andrew Watkins 2017-10-05 11:41:47 -07:00
parent 3ec34cd1a4
commit 08ecae96a6
3 changed files with 50 additions and 0 deletions

View File

@ -0,0 +1,22 @@
import reducer from 'src/dashboards/reducers/dashTimeV1'
import {setDashTimeV1} from 'src/dashboards/actions/index'
describe.only('Dashboards.Reducers.DashTimeV1', () => {
it('can load initial state', () => {
const noopAction = () => ({type: 'NOOP'})
const actual = reducer(undefined, noopAction)
const expected = {dashTimeV1: []}
expect(actual).to.deep.equal(expected)
})
it('can set a dashboard time', () => {
const dashboardID = 1
const timeRange = {upper: null, lower: 'now() - 15m'}
const actual = reducer(undefined, setDashTimeV1(dashboardID, timeRange))
const expected = [{dashboardID, timeRange}]
expect(actual.dashTimeV1).to.deep.equal(expected)
})
})

View File

@ -28,6 +28,14 @@ export const loadDashboards = (dashboards, dashboardID) => ({
}, },
}) })
export const setDashTimeV1 = (dashboardID, timeRange) => ({
type: 'SET_DASHBOARD_TIME_RANGE_V1',
payload: {
dashboardID,
timeRange,
},
})
export const setTimeRange = timeRange => ({ export const setTimeRange = timeRange => ({
type: 'SET_DASHBOARD_TIME_RANGE', type: 'SET_DASHBOARD_TIME_RANGE',
payload: { payload: {

View File

@ -0,0 +1,20 @@
const initialState = {
dashTimeV1: [],
}
const dashTimeV1 = (state = initialState, action) => {
switch (action.type) {
case 'SET_DASHBOARD_TIME_RANGE_V1': {
const {dashboardID, timeRange} = action.payload
const newState = {
dashTimeV1: [...state.dashTimeV1, {dashboardID, timeRange}],
}
return {...state, ...newState}
}
}
return state
}
export default dashTimeV1