2021-12-03 20:37:38 +01:00
|
|
|
import produce from 'immer';
|
2022-03-13 16:57:59 +01:00
|
|
|
import union from 'lodash/union';
|
2022-03-15 20:30:35 +01:00
|
|
|
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;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-01-18 17:25:22 +01:00
|
|
|
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);
|
2022-01-18 17:25:22 +01:00
|
|
|
|
|
|
|
if(collection) {
|
|
|
|
let flattenedItems = flattenItems(collection.items);
|
|
|
|
let item = findItem(flattenedItems, action.requestTab.id);
|
|
|
|
|
|
|
|
if(item) {
|
|
|
|
item.request.body.graphql.query = action.query;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-01-18 15:58:18 +01:00
|
|
|
case actions.ADD_NEW_GQL_REQUEST: {
|
|
|
|
return produce(state, (draft) => {
|
2022-03-22 13:48:20 +01:00
|
|
|
const uid = uuid();
|
2022-01-18 15:58:18 +01:00
|
|
|
draft.requestTabs.push({
|
2022-03-13 22:13:36 +01:00
|
|
|
uid: uid,
|
2022-01-18 15:58:18 +01:00
|
|
|
name: 'New Tab',
|
2022-03-14 18:46:49 +01:00
|
|
|
type: 'graphql-request',
|
2022-01-18 15:58:18 +01:00
|
|
|
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: '{}'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2022-03-13 22:13:36 +01:00
|
|
|
collectionUid: null
|
2022-01-04 18:00:15 +01:00
|
|
|
});
|
2022-03-13 22:13:36 +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;
|