Add dashboard timeRange to reducer
parent
0ed15c74f7
commit
4ef173aac9
|
@ -3,46 +3,49 @@ import reducer from 'src/dashboards/reducers/ui'
|
||||||
import {
|
import {
|
||||||
loadDashboards,
|
loadDashboards,
|
||||||
setDashboard,
|
setDashboard,
|
||||||
} from 'src/dashboards/actions';
|
setTimeRange,
|
||||||
|
} from 'src/dashboards/actions'
|
||||||
|
|
||||||
const noopAction = () => {
|
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', () => {
|
describe('DataExplorer.Reducers.UI', () => {
|
||||||
it('can load the dashboards', () => {
|
it('can load the dashboards', () => {
|
||||||
const dashboard = {id: 2, cells: [], name: "d2"}
|
const actual = reducer(state, loadDashboards(dashboards, d1.id))
|
||||||
const dashboards = [
|
|
||||||
{id: 1, cells: [], name: "d1"},
|
|
||||||
dashboard,
|
|
||||||
]
|
|
||||||
|
|
||||||
const actual = reducer(state, loadDashboards(dashboards, dashboard.id))
|
|
||||||
const expected = {
|
const expected = {
|
||||||
dashboards,
|
dashboards,
|
||||||
dashboard,
|
dashboard: d1,
|
||||||
|
timeRange,
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(actual).to.deep.equal(expected)
|
expect(actual).to.deep.equal(expected)
|
||||||
});
|
})
|
||||||
|
|
||||||
it('can set a dashboard', () => {
|
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 loadedState = reducer(state, loadDashboards(dashboards, d1.id))
|
||||||
const actual = reducer(loadedState, setDashboard(d2.id))
|
const actual = reducer(loadedState, setDashboard(d2.id))
|
||||||
const expected = {
|
const expected = {
|
||||||
dashboards,
|
dashboards,
|
||||||
dashboard: d2,
|
dashboard: d2,
|
||||||
|
timeRange,
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(actual).to.deep.equal(expected)
|
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)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
|
@ -19,6 +19,15 @@ export function setDashboard(dashboardID) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function setTimeRange(timeRange) {
|
||||||
|
return {
|
||||||
|
type: 'SET_DASHBOARD_TIME_RANGE',
|
||||||
|
payload: {
|
||||||
|
timeRange,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function getDashboards(dashboardID) {
|
export function getDashboards(dashboardID) {
|
||||||
return (dispatch) => {
|
return (dispatch) => {
|
||||||
getDashboardsAPI().then(({data: {dashboards}}) => {
|
getDashboardsAPI().then(({data: {dashboards}}) => {
|
||||||
|
|
|
@ -5,6 +5,10 @@ import {EMPTY_DASHBOARD} from 'src/dashboards/constants'
|
||||||
const initialState = {
|
const initialState = {
|
||||||
dashboards: [],
|
dashboards: [],
|
||||||
dashboard: EMPTY_DASHBOARD,
|
dashboard: EMPTY_DASHBOARD,
|
||||||
|
timeRange: {
|
||||||
|
upper: null,
|
||||||
|
lower: 'now() - 15m',
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function ui(state = initialState, action) {
|
export default function ui(state = initialState, action) {
|
||||||
|
@ -27,6 +31,12 @@ export default function ui(state = initialState, action) {
|
||||||
|
|
||||||
return {...state, ...newState}
|
return {...state, ...newState}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case 'SET_DASHBOARD_TIME_RANGE': {
|
||||||
|
const {timeRange} = action.payload
|
||||||
|
|
||||||
|
return {...state, timeRange};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return state;
|
return state;
|
||||||
|
|
Loading…
Reference in New Issue