Introduce dashTime reducer v1
parent
3ec34cd1a4
commit
08ecae96a6
|
@ -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)
|
||||
})
|
||||
})
|
|
@ -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 => ({
|
||||
type: 'SET_DASHBOARD_TIME_RANGE',
|
||||
payload: {
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue