From d640dafb06151a2e9a39a8fc6169f9e921070524 Mon Sep 17 00:00:00 2001 From: Anoop M D Date: Sun, 16 Oct 2022 04:03:00 +0530 Subject: [PATCH] chore: collection uid check before pushing collections into state --- .../ReduxStore/slices/collections/index.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js b/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js index 2b19a56d6..fe7cdcbfd 100644 --- a/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js +++ b/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js @@ -1,6 +1,7 @@ import path from 'path'; import { uuid } from 'utils/common'; import find from 'lodash/find'; +import map from 'lodash/map'; import concat from 'lodash/concat'; import filter from 'lodash/filter'; import each from 'lodash/each'; @@ -30,21 +31,33 @@ export const collectionsSlice = createSlice({ initialState, reducers: { loadCollections: (state, action) => { + const collectionUids = map(state.collections, (c) => c.uid); each(action.payload.collections, (c) => collapseCollection(c)); each(action.payload.collections, (c) => addDepth(c.items)); - each(action.payload.collections, (c) => state.collections.push(c)); + each(action.payload.collections, (c) => { + if(!collectionUids.includes(c.uid)) { + state.collections.push(c); + collectionUids.push(c.uid); + } + }); }, collectionImported: (state, action) => { + const collectionUids = map(state.collections, (c) => c.uid); const { collection } = action.payload; collapseCollection(collection); addDepth(collection.items); - state.collections.push(collection); + if(!collectionUids.includes(c.uid)) { + state.collections.push(collection); + } }, createCollection: (state, action) => { + const collectionUids = map(state.collections, (c) => c.uid); const collection = action.payload; collapseCollection(collection); addDepth(collection.items); - state.collections.push(collection); + if(!collectionUids.includes(c.uid)) { + state.collections.push(collection); + } }, renameCollection: (state, action) => { const collection = findCollectionByUid(state.collections, action.payload.collectionUid);