Introduce data explorer ui reducer
parent
e4cc9fc45d
commit
569c8a8218
|
@ -0,0 +1,40 @@
|
|||
import reducer from 'src/data_explorer/reducers/ui';
|
||||
|
||||
import {
|
||||
addQuery,
|
||||
deleteQuery,
|
||||
} from 'src/data_explorer/actions/view';
|
||||
|
||||
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 = {
|
||||
queryIDs: [],
|
||||
};
|
||||
|
||||
expect(actual).to.deep.equal(expected);
|
||||
});
|
||||
|
||||
it('it can add a query', () => {
|
||||
const actual = reducer(state, addQuery());
|
||||
expect(actual.queryIDs.length).to.equal(1);
|
||||
});
|
||||
|
||||
it('it can delete a query', () => {
|
||||
const queryID = '123';
|
||||
state = {queryIDs: ['456', queryID]};
|
||||
|
||||
const actual = reducer(state, deleteQuery(queryID));
|
||||
const expected = {
|
||||
queryIDs: ['456'],
|
||||
};
|
||||
|
||||
expect(actual).to.deep.equal(expected);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,27 @@
|
|||
const initialState = {
|
||||
queryIDs: [],
|
||||
};
|
||||
|
||||
export default function ui(state = initialState, action) {
|
||||
switch (action.type) {
|
||||
case 'ADD_QUERY': {
|
||||
const {queryID} = action.payload;
|
||||
const newState = {
|
||||
queryIDs: state.queryIDs.concat(queryID),
|
||||
};
|
||||
|
||||
return {...state, ...newState};
|
||||
}
|
||||
|
||||
case 'DELETE_QUERY': {
|
||||
const {queryID} = action.payload;
|
||||
const newState = {
|
||||
queryIDs: state.queryIDs.filter(id => id !== queryID),
|
||||
};
|
||||
|
||||
return {...state, ...newState};
|
||||
}
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
Loading…
Reference in New Issue