From e462eb6ecd89be7a029fcbcdec47d9bf15b51230 Mon Sep 17 00:00:00 2001 From: lohit Date: Thu, 4 Jul 2024 16:10:38 +0530 Subject: [PATCH] import environments ui and collection root object for json export - updates (#2565) * pr review changes * collection root object in export json * import environment updates --- .../CreateEnvironment/index.js | 69 +++++++++++-------- .../ImportEnvironment/index.js | 27 +++++--- .../Environments/EnvironmentSettings/index.js | 18 ++--- .../src/components/FolderSettings/index.js | 4 +- .../bruno-app/src/utils/collections/index.js | 20 +++++- 5 files changed, 84 insertions(+), 54 deletions(-) diff --git a/packages/bruno-app/src/components/Environments/EnvironmentSettings/CreateEnvironment/index.js b/packages/bruno-app/src/components/Environments/EnvironmentSettings/CreateEnvironment/index.js index 6aca6c4c1e..3427955a23 100644 --- a/packages/bruno-app/src/components/Environments/EnvironmentSettings/CreateEnvironment/index.js +++ b/packages/bruno-app/src/components/Environments/EnvironmentSettings/CreateEnvironment/index.js @@ -4,9 +4,10 @@ import { useFormik } from 'formik'; import { addEnvironment } from 'providers/ReduxStore/slices/collections/actions'; import * as Yup from 'yup'; import { useDispatch } from 'react-redux'; -import { SharedButton } from 'components/Environments/EnvironmentSettings'; +import Portal from 'components/Portal'; +import Modal from 'components/Modal'; -const CreateEnvironment = ({ collection }) => { +const CreateEnvironment = ({ collection, onClose }) => { const dispatch = useDispatch(); const inputRef = useRef(); const formik = useFormik({ @@ -24,8 +25,9 @@ const CreateEnvironment = ({ collection }) => { dispatch(addEnvironment(values.name, collection.uid)) .then(() => { toast.success('Environment created in collection'); + onClose(); }) - .catch(() => toast.error('An error occurred while created the environment')); + .catch(() => toast.error('An error occurred while creating the environment')); } }); @@ -40,32 +42,41 @@ const CreateEnvironment = ({ collection }) => { }; return ( -
-
- -
- - - Create - -
- {formik.touched.name && formik.errors.name ?
{formik.errors.name}
: null} -
-
+ + +
+
+ +
+ +
+ {formik.touched.name && formik.errors.name ? ( +
{formik.errors.name}
+ ) : null} +
+
+
+
); }; diff --git a/packages/bruno-app/src/components/Environments/EnvironmentSettings/ImportEnvironment/index.js b/packages/bruno-app/src/components/Environments/EnvironmentSettings/ImportEnvironment/index.js index 8060ea01ee..d229ea3a2d 100644 --- a/packages/bruno-app/src/components/Environments/EnvironmentSettings/ImportEnvironment/index.js +++ b/packages/bruno-app/src/components/Environments/EnvironmentSettings/ImportEnvironment/index.js @@ -1,4 +1,6 @@ import React from 'react'; +import Portal from 'components/Portal'; +import Modal from 'components/Modal'; import toast from 'react-hot-toast'; import { useDispatch } from 'react-redux'; import importPostmanEnvironment from 'utils/importers/postman-environment'; @@ -6,7 +8,7 @@ import { importEnvironment } from 'providers/ReduxStore/slices/collections/actio import { toastError } from 'utils/common/error'; import { IconDatabaseImport } from '@tabler/icons'; -const ImportEnvironment = ({ collection }) => { +const ImportEnvironment = ({ collection, onClose }) => { const dispatch = useDispatch(); const handleImportPostmanEnvironment = () => { @@ -29,18 +31,25 @@ const ImportEnvironment = ({ collection }) => { .catch(() => toast.error('An error occurred while importing the environment')); }); }) + .then(() => { + onClose(); + }) .catch((err) => toastError(err, 'Postman Import environment failed')); }; return ( - + + + + + ); }; diff --git a/packages/bruno-app/src/components/Environments/EnvironmentSettings/index.js b/packages/bruno-app/src/components/Environments/EnvironmentSettings/index.js index 464c032b63..3a17e2ecd0 100644 --- a/packages/bruno-app/src/components/Environments/EnvironmentSettings/index.js +++ b/packages/bruno-app/src/components/Environments/EnvironmentSettings/index.js @@ -45,28 +45,20 @@ const DefaultTab = ({ setTab }) => { const EnvironmentSettings = ({ collection, onClose }) => { const [isModified, setIsModified] = useState(false); const { environments } = collection; - const [openCreateModal, setOpenCreateModal] = useState(false); - const [openImportModal, setOpenImportModal] = useState(false); const [selectedEnvironment, setSelectedEnvironment] = useState(null); const [tab, setTab] = useState('default'); if (!environments || !environments.length) { return ( - setTab('default')} - handleCancel={onClose} - hideCancel={true} - > + {tab === 'create' ? ( - + setTab('default')} /> ) : tab === 'import' ? ( - + setTab('default')} /> ) : ( - + <> )} + ); diff --git a/packages/bruno-app/src/components/FolderSettings/index.js b/packages/bruno-app/src/components/FolderSettings/index.js index 6dcd9cfd2e..eab7baf8dc 100644 --- a/packages/bruno-app/src/components/FolderSettings/index.js +++ b/packages/bruno-app/src/components/FolderSettings/index.js @@ -12,8 +12,8 @@ const FolderSettings = ({ collection, folder }) => { const dispatch = useDispatch(); let tab = 'headers'; const { folderLevelSettingsSelectedTab } = collection; - if (folderLevelSettingsSelectedTab?.[folder.uid]) { - tab = folderLevelSettingsSelectedTab[folder.uid]; + if (folderLevelSettingsSelectedTab?.[folder?.uid]) { + tab = folderLevelSettingsSelectedTab[folder?.uid]; } const setTab = (tab) => { diff --git a/packages/bruno-app/src/utils/collections/index.js b/packages/bruno-app/src/utils/collections/index.js index 6d992c8e68..4f0afceda2 100644 --- a/packages/bruno-app/src/utils/collections/index.js +++ b/packages/bruno-app/src/utils/collections/index.js @@ -417,7 +417,25 @@ export const transformCollectionToSaveToExportAsFile = (collection, options = {} collectionToSave.items = []; collectionToSave.activeEnvironmentUid = collection.activeEnvironmentUid; collectionToSave.environments = collection.environments || []; - collectionToSave.root = collection.root || {}; + collectionToSave.root = { + request: { + auth: collection?.root?.request?.auth, + headers: collection?.root?.request?.headers, + script: collection?.root?.request?.script, + vars: collection?.root?.request?.vars, + tests: collection?.root?.request?.tests + }, + docs: collection?.root?.request?.docs, + meta: { + name: collection?.root?.meta?.name || collection?.name + } + }; + + if (!collection?.root?.request?.auth?.mode) { + collectionToSave.root.request.auth = { + mode: 'none' + }; + } collectionToSave.brunoConfig = cloneDeep(collection?.brunoConfig);