Introduce dashboard ui reducer

pull/10616/head
Andrew Watkins 2017-02-17 10:02:35 -06:00
parent 717fd1ed3f
commit 9d7b20f903
4 changed files with 59 additions and 0 deletions

View File

@ -0,0 +1,31 @@
import reducer from 'src/dashboards/reducers/ui';
import {
loadDashboards,
} from 'src/dashboards/actions';
const noopAction = () => {
return {type: 'NOOP'};
}
let state = undefined;
describe('DataExplorer.Reducers.UI', () => {
it('it sets the default state for UI', () => {
const actual = reducer(state, noopAction());
const expected = {
dashboards: [],
};
expect(actual).to.deep.equal(expected);
});
it('can load the dashboards', () => {
const dashboards = [{cell: {}, name: "d1"}]
const actual = reducer(state, loadDashboards(dashboards));
const expected = {
dashboards,
}
expect(actual).to.deep.equal(expected);
});
});

View File

@ -0,0 +1,8 @@
export function loadDashboards(dashboards) {
return {
type: 'LOAD_DASHBOARDS',
payload: {
dashboards,
},
}
}

View File

@ -0,0 +1,18 @@
const initialState = {
dashboards: [],
};
export default function ui(state = initialState, action) {
switch (action.type) {
case 'LOAD_DASHBOARDS': {
const {dashboards} = action.payload;
const newState = {
dashboards,
};
return {...state, ...newState};
}
}
return state;
}

View File

@ -5,12 +5,14 @@ import makeQueryExecuter from 'src/shared/middleware/queryExecuter';
import * as dataExplorerReducers from 'src/data_explorer/reducers';
import * as sharedReducers from 'src/shared/reducers';
import rulesReducer from 'src/kapacitor/reducers/rules';
import dashboardUI from 'src/dashboards/reducers/ui';
import persistStateEnhancer from './persistStateEnhancer';
const rootReducer = combineReducers({
...sharedReducers,
...dataExplorerReducers,
rules: rulesReducer,
dashboardUI,
});
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;