From 6feca9937ee8b16d76144ccb36408d4bd4f5b13d Mon Sep 17 00:00:00 2001 From: Anoop M D Date: Sat, 15 Oct 2022 03:07:50 +0530 Subject: [PATCH] feat: export collections --- packages/bruno-app/package.json | 1 + .../Sidebar/Collections/Collection/index.js | 15 ++++++++++++++- .../bruno-app/src/utils/collections/export.js | 10 ++++++++++ packages/bruno-app/src/utils/collections/index.js | 1 - 4 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 packages/bruno-app/src/utils/collections/export.js diff --git a/packages/bruno-app/package.json b/packages/bruno-app/package.json index f3b474ddd..7ec6ca914 100644 --- a/packages/bruno-app/package.json +++ b/packages/bruno-app/package.json @@ -19,6 +19,7 @@ "codemirror": "^5.65.2", "codemirror-graphql": "^1.2.5", "escape-html": "^1.0.3", + "file-saver": "^2.0.5", "formik": "^2.2.9", "graphiql": "^1.5.9", "graphql": "^16.2.0", diff --git a/packages/bruno-app/src/components/Sidebar/Collections/Collection/index.js b/packages/bruno-app/src/components/Sidebar/Collections/Collection/index.js index bc3f48c33..c8e599443 100644 --- a/packages/bruno-app/src/components/Sidebar/Collections/Collection/index.js +++ b/packages/bruno-app/src/components/Sidebar/Collections/Collection/index.js @@ -1,6 +1,7 @@ import React, { useState, forwardRef, useRef, useEffect } from 'react'; import classnames from 'classnames'; import filter from 'lodash/filter'; +import cloneDeep from 'lodash/cloneDeep'; import { IconChevronRight, IconDots } from '@tabler/icons'; import Dropdown from 'components/Dropdown'; import { collectionClicked } from 'providers/ReduxStore/slices/collections'; @@ -10,7 +11,8 @@ import NewFolder from 'components/Sidebar/NewFolder'; import CollectionItem from './CollectionItem'; import RemoveCollectionFromWorkspace from './RemoveCollectionFromWorkspace'; import { doesCollectionHaveItemsMatchingSearchText } from 'utils/collections/search'; -import { isItemAFolder, isItemARequest } from 'utils/collections'; +import { isItemAFolder, isItemARequest, transformCollectionToSaveToIdb } from 'utils/collections'; +import exportCollection from 'utils/collections/export'; import RenameCollection from './RenameCollection'; import DeleteCollection from './DeleteCollection'; @@ -60,6 +62,11 @@ const Collection = ({collection, searchText}) => { const requestItems = filter(collection.items, (i) => isItemARequest(i)); const folderItems = filter(collection.items, (i) => isItemAFolder(i)); + const handleExportClick = () => { + const collectionCopy = cloneDeep(collection); + exportCollection(transformCollectionToSaveToIdb(collectionCopy)); + }; + return ( {showNewRequestModal && setShowNewRequestModal(false)}/>} @@ -96,6 +103,12 @@ const Collection = ({collection, searchText}) => { }}> Rename +
{ + menuDropdownTippyRef.current.hide(); + handleExportClick(true); + }}> + Export +
{ menuDropdownTippyRef.current.hide(); setShowRemoveCollectionFromWSModal(true); diff --git a/packages/bruno-app/src/utils/collections/export.js b/packages/bruno-app/src/utils/collections/export.js new file mode 100644 index 000000000..a9434ef44 --- /dev/null +++ b/packages/bruno-app/src/utils/collections/export.js @@ -0,0 +1,10 @@ +import * as FileSaver from 'file-saver'; + +const exportCollection = (collection) => { + const fileName = `${collection.name}.json`; + const fileBlob = new Blob([JSON.stringify(collection, null, 2)], { type: "application/json" }) + + FileSaver.saveAs(fileBlob, fileName); +}; + +export default exportCollection; \ No newline at end of file diff --git a/packages/bruno-app/src/utils/collections/index.js b/packages/bruno-app/src/utils/collections/index.js index 9e74df43d..242fcfcab 100644 --- a/packages/bruno-app/src/utils/collections/index.js +++ b/packages/bruno-app/src/utils/collections/index.js @@ -4,7 +4,6 @@ import isString from 'lodash/isString'; import map from 'lodash/map'; import filter from 'lodash/filter'; import sortBy from 'lodash/sortBy'; -import cloneDeep from 'lodash/cloneDeep'; const replaceTabsWithSpaces = (str, numSpaces = 2) => { if(!str || !str.length || !isString(str)) {