diff --git a/packages/grafnode-components/src/components/Sidebar/index.js b/packages/grafnode-components/src/components/Sidebar/index.js index 24aeba60e..1dc35a590 100644 --- a/packages/grafnode-components/src/components/Sidebar/index.js +++ b/packages/grafnode-components/src/components/Sidebar/index.js @@ -25,6 +25,10 @@ const Sidebar = ({collections, actions, dispatch, activeRequestTabId}) => { const handleConfirm = (values) => { console.log(values); + dispatch({ + name: values.collectionName, + type: actions.COLLECTION_CREATE + }); setModalOpen(false); }; diff --git a/packages/grafnode-run/src/providers/Store/actions.js b/packages/grafnode-run/src/providers/Store/actions.js index 069d2e52c..16b51c6e5 100644 --- a/packages/grafnode-run/src/providers/Store/actions.js +++ b/packages/grafnode-run/src/providers/Store/actions.js @@ -1,5 +1,6 @@ const SIDEBAR_COLLECTION_CLICK = "SIDEBAR_COLLECTION_CLICK"; const SIDEBAR_COLLECTION_ITEM_CLICK = "SIDEBAR_COLLECTION_ITEM_CLICK"; +const COLLECTION_CREATE = "COLLECTION_CREATE"; const REQUEST_TAB_CLICK = "REQUEST_TAB_CLICK"; const REQUEST_TAB_CLOSE = "REQUEST_TAB_CLOSE"; const REQUEST_URL_CHANGED = "REQUEST_URL_CHANGED"; @@ -14,6 +15,7 @@ const ADD_NEW_GQL_REQUEST = "ADD_NEW_GQL_REQUEST"; export default { SIDEBAR_COLLECTION_CLICK, SIDEBAR_COLLECTION_ITEM_CLICK, + COLLECTION_CREATE, REQUEST_TAB_CLICK, REQUEST_TAB_CLOSE, REQUEST_URL_CHANGED, diff --git a/packages/grafnode-run/src/providers/Store/reducer.js b/packages/grafnode-run/src/providers/Store/reducer.js index 74c7f8c65..cc9afbde0 100644 --- a/packages/grafnode-run/src/providers/Store/reducer.js +++ b/packages/grafnode-run/src/providers/Store/reducer.js @@ -52,6 +52,18 @@ const reducer = (state, action) => { }); } + case actions.COLLECTION_CREATE: { + return produce(state, (draft) => { + // todo: collection names must be unique across a user account + draft.collections = draft.collections || []; + draft.collections.push({ + id: nanoid(), + name: action.name, + items: [] + }); + }); + } + case actions.REQUEST_TAB_CLICK: { return produce(state, (draft) => { draft.activeRequestTabId = action.requestTab.id;