diff --git a/ui/spec/dashboards/reducers/uiSpec.js b/ui/spec/dashboards/reducers/uiSpec.js new file mode 100644 index 0000000000..5ab2140805 --- /dev/null +++ b/ui/spec/dashboards/reducers/uiSpec.js @@ -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); + }); +}); diff --git a/ui/src/dashboards/actions/index.js b/ui/src/dashboards/actions/index.js new file mode 100644 index 0000000000..2db6612061 --- /dev/null +++ b/ui/src/dashboards/actions/index.js @@ -0,0 +1,8 @@ +export function loadDashboards(dashboards) { + return { + type: 'LOAD_DASHBOARDS', + payload: { + dashboards, + }, + } +} diff --git a/ui/src/dashboards/reducers/ui.js b/ui/src/dashboards/reducers/ui.js new file mode 100644 index 0000000000..e0a63363ce --- /dev/null +++ b/ui/src/dashboards/reducers/ui.js @@ -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; +} diff --git a/ui/src/store/configureStore.js b/ui/src/store/configureStore.js index 286e96e47b..85b4a6e11a 100644 --- a/ui/src/store/configureStore.js +++ b/ui/src/store/configureStore.js @@ -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;