diff --git a/ui/spec/dashboards/reducers/dashTimeV1Spec.js b/ui/spec/dashboards/reducers/dashTimeV1Spec.js new file mode 100644 index 000000000..54aaf8eea --- /dev/null +++ b/ui/spec/dashboards/reducers/dashTimeV1Spec.js @@ -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) + }) +}) diff --git a/ui/src/dashboards/actions/index.js b/ui/src/dashboards/actions/index.js index 24eca86ed..0abc37d6e 100644 --- a/ui/src/dashboards/actions/index.js +++ b/ui/src/dashboards/actions/index.js @@ -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: { diff --git a/ui/src/dashboards/reducers/dashTimeV1.js b/ui/src/dashboards/reducers/dashTimeV1.js new file mode 100644 index 000000000..15bfe4708 --- /dev/null +++ b/ui/src/dashboards/reducers/dashTimeV1.js @@ -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