More goodness

This commit is contained in:
Maxime Beauchemin
2016-08-16 21:00:23 -07:00
parent 7a3ed6e1bc
commit ab43bbbc21
14 changed files with 265 additions and 111 deletions

View File

@@ -12,11 +12,12 @@ const defaultQueryEditor = {
};
export const initialState = {
queryEditors: [defaultQueryEditor],
alerts: [],
queries: [],
queryEditors: [defaultQueryEditor],
tabHistory: [defaultQueryEditor.id],
tables: [],
workspaceQueries: [],
tabHistory: [defaultQueryEditor.id],
};
@@ -46,6 +47,9 @@ function removeFromArr(state, arrKey, obj, idKey = 'id') {
}
function addToArr(state, arrKey, obj) {
if (!(obj.id)) {
obj.id = shortid.generate();
}
const newState = {};
newState[arrKey] = [...state[arrKey], Object.assign({}, obj)];
return Object.assign({}, state, newState);
@@ -137,6 +141,12 @@ export const sqlLabReducer = function (state, action) {
[actions.REMOVE_WORKSPACE_QUERY]() {
return removeFromArr(state, 'workspaceQueries', action.query);
},
[actions.ADD_ALERT]() {
return addToArr(state, 'alerts', action.alert);
},
[actions.REMOVE_ALERT]() {
return removeFromArr(state, 'alerts', action.alert);
},
};
if (action.type in actionHandlers) {
return actionHandlers[action.type]();