Add dashboard timeRange to reducer

pull/10616/head
Andrew Watkins 2017-02-17 12:17:44 -06:00
parent 0ed15c74f7
commit 4ef173aac9
3 changed files with 43 additions and 21 deletions

View File

@ -3,46 +3,49 @@ import reducer from 'src/dashboards/reducers/ui'
import {
loadDashboards,
setDashboard,
} from 'src/dashboards/actions';
setTimeRange,
} from 'src/dashboards/actions'
const noopAction = () => {
return {type: 'NOOP'};
return {type: 'NOOP'}
}
let state = undefined;
let state = undefined
const timeRange = {upper: null, lower: 'now() - 15m'}
const d1 = {id: 1, cells: [], name: "d1"}
const d2 = {id: 2, cells: [], name: "d2"}
const dashboards = [d1, d2]
describe('DataExplorer.Reducers.UI', () => {
it('can load the dashboards', () => {
const dashboard = {id: 2, cells: [], name: "d2"}
const dashboards = [
{id: 1, cells: [], name: "d1"},
dashboard,
]
const actual = reducer(state, loadDashboards(dashboards, dashboard.id))
const actual = reducer(state, loadDashboards(dashboards, d1.id))
const expected = {
dashboards,
dashboard,
dashboard: d1,
timeRange,
}
expect(actual).to.deep.equal(expected)
});
})
it('can set a dashboard', () => {
const d1 = {id: 2, cells: [], name: "d2"}
const d2 = {id: 2, cells: [], name: "d2"}
const dashboards = [
d1,
d2,
]
const loadedState = reducer(state, loadDashboards(dashboards, d1.id))
const actual = reducer(loadedState, setDashboard(d2.id))
const expected = {
dashboards,
dashboard: d2,
timeRange,
}
expect(actual).to.deep.equal(expected)
});
});
})
it('can set the time range', () => {
const expected = {upper: null, lower: 'now() - 1h'}
const actual = reducer(state, setTimeRange(expected))
console.log('actual: ', actual)
expect(actual.timeRange).to.deep.equal(expected)
})
})

View File

@ -19,6 +19,15 @@ export function setDashboard(dashboardID) {
}
}
export function setTimeRange(timeRange) {
return {
type: 'SET_DASHBOARD_TIME_RANGE',
payload: {
timeRange,
},
}
}
export function getDashboards(dashboardID) {
return (dispatch) => {
getDashboardsAPI().then(({data: {dashboards}}) => {

View File

@ -5,6 +5,10 @@ import {EMPTY_DASHBOARD} from 'src/dashboards/constants'
const initialState = {
dashboards: [],
dashboard: EMPTY_DASHBOARD,
timeRange: {
upper: null,
lower: 'now() - 15m',
},
};
export default function ui(state = initialState, action) {
@ -27,6 +31,12 @@ export default function ui(state = initialState, action) {
return {...state, ...newState}
}
case 'SET_DASHBOARD_TIME_RANGE': {
const {timeRange} = action.payload
return {...state, timeRange};
}
}
return state;