Introduce dashboard ui reducer
parent
717fd1ed3f
commit
9d7b20f903
|
@ -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);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,8 @@
|
|||
export function loadDashboards(dashboards) {
|
||||
return {
|
||||
type: 'LOAD_DASHBOARDS',
|
||||
payload: {
|
||||
dashboards,
|
||||
},
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue