bruno/renderer/providers/Store/reducer.js

64 lines
1.5 KiB
JavaScript
Raw Permalink Normal View History

2021-12-03 20:37:38 +01:00
import produce from 'immer';
import union from 'lodash/union';
import find from 'lodash/find';
2021-12-03 20:37:38 +01:00
import actions from './actions';
import {
flattenItems,
findItem,
2022-01-23 13:38:01 +01:00
cloneItem,
2022-03-13 18:22:14 +01:00
updateRequestTabAsChanged,
findCollectionByUid
2021-12-03 20:37:38 +01:00
} from './utils';
const reducer = (state, action) => {
switch (action.type) {
2022-02-03 18:55:38 +01:00
case actions.IDB_CONNECTION_READY: {
return produce(state, (draft) => {
draft.idbConnection = action.connection;
});
}
case actions.REQUEST_GQL_QUERY_CHANGED: {
return produce(state, (draft) => {
2022-03-13 18:22:14 +01:00
const collection = findCollectionByUid(draft.collections, action.collectionUid);
if(collection) {
let flattenedItems = flattenItems(collection.items);
let item = findItem(flattenedItems, action.requestTab.id);
if(item) {
item.request.body.graphql.query = action.query;
}
}
});
}
case actions.ADD_NEW_GQL_REQUEST: {
return produce(state, (draft) => {
2022-03-22 13:48:20 +01:00
const uid = uuid();
draft.requestTabs.push({
uid: uid,
name: 'New Tab',
2022-03-14 18:46:49 +01:00
type: 'graphql-request',
request: {
2022-03-14 18:46:49 +01:00
method: 'GET',
2022-01-04 18:00:15 +01:00
url: 'https://api.spacex.land/graphql/',
body: {
graphql: {
query: '{}'
}
}
},
collectionUid: null
2022-01-04 18:00:15 +01:00
});
draft.activeRequestTabUid = uid;
2022-01-04 18:00:15 +01:00
});
}
2021-12-03 20:37:38 +01:00
default: {
return state;
}
}
}
export default reducer;