import environments ui and collection root object for json export - updates (#2565)

* pr review changes

* collection root object in export json

* import environment updates
This commit is contained in:
lohit 2024-07-04 16:10:38 +05:30 committed by GitHub
parent 40f7be534a
commit e462eb6ecd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 84 additions and 54 deletions

View File

@ -4,9 +4,10 @@ import { useFormik } from 'formik';
import { addEnvironment } from 'providers/ReduxStore/slices/collections/actions'; import { addEnvironment } from 'providers/ReduxStore/slices/collections/actions';
import * as Yup from 'yup'; import * as Yup from 'yup';
import { useDispatch } from 'react-redux'; 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 dispatch = useDispatch();
const inputRef = useRef(); const inputRef = useRef();
const formik = useFormik({ const formik = useFormik({
@ -24,8 +25,9 @@ const CreateEnvironment = ({ collection }) => {
dispatch(addEnvironment(values.name, collection.uid)) dispatch(addEnvironment(values.name, collection.uid))
.then(() => { .then(() => {
toast.success('Environment created in collection'); 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,6 +42,14 @@ const CreateEnvironment = ({ collection }) => {
}; };
return ( return (
<Portal>
<Modal
size="sm"
title={'Create Environment'}
confirmText="Create"
handleConfirm={onSubmit}
handleCancel={onClose}
>
<form className="bruno-form" onSubmit={formik.handleSubmit}> <form className="bruno-form" onSubmit={formik.handleSubmit}>
<div> <div>
<label htmlFor="name" className="block font-semibold"> <label htmlFor="name" className="block font-semibold">
@ -59,13 +69,14 @@ const CreateEnvironment = ({ collection }) => {
onChange={formik.handleChange} onChange={formik.handleChange}
value={formik.values.name || ''} value={formik.values.name || ''}
/> />
<SharedButton className="py-2.5 ml-1" onClick={onSubmit}>
Create
</SharedButton>
</div> </div>
{formik.touched.name && formik.errors.name ? <div className="text-red-500">{formik.errors.name}</div> : null} {formik.touched.name && formik.errors.name ? (
<div className="text-red-500">{formik.errors.name}</div>
) : null}
</div> </div>
</form> </form>
</Modal>
</Portal>
); );
}; };

View File

@ -1,4 +1,6 @@
import React from 'react'; import React from 'react';
import Portal from 'components/Portal';
import Modal from 'components/Modal';
import toast from 'react-hot-toast'; import toast from 'react-hot-toast';
import { useDispatch } from 'react-redux'; import { useDispatch } from 'react-redux';
import importPostmanEnvironment from 'utils/importers/postman-environment'; 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 { toastError } from 'utils/common/error';
import { IconDatabaseImport } from '@tabler/icons'; import { IconDatabaseImport } from '@tabler/icons';
const ImportEnvironment = ({ collection }) => { const ImportEnvironment = ({ collection, onClose }) => {
const dispatch = useDispatch(); const dispatch = useDispatch();
const handleImportPostmanEnvironment = () => { const handleImportPostmanEnvironment = () => {
@ -29,10 +31,15 @@ const ImportEnvironment = ({ collection }) => {
.catch(() => toast.error('An error occurred while importing the environment')); .catch(() => toast.error('An error occurred while importing the environment'));
}); });
}) })
.then(() => {
onClose();
})
.catch((err) => toastError(err, 'Postman Import environment failed')); .catch((err) => toastError(err, 'Postman Import environment failed'));
}; };
return ( return (
<Portal>
<Modal size="sm" title="Import Environment" hideFooter={true} handleConfirm={onClose} handleCancel={onClose}>
<button <button
type="button" type="button"
onClick={handleImportPostmanEnvironment} onClick={handleImportPostmanEnvironment}
@ -41,6 +48,8 @@ const ImportEnvironment = ({ collection }) => {
<IconDatabaseImport size={64} /> <IconDatabaseImport size={64} />
<span className="mt-2 block text-sm font-semibold">Import your Postman environments</span> <span className="mt-2 block text-sm font-semibold">Import your Postman environments</span>
</button> </button>
</Modal>
</Portal>
); );
}; };

View File

@ -45,28 +45,20 @@ const DefaultTab = ({ setTab }) => {
const EnvironmentSettings = ({ collection, onClose }) => { const EnvironmentSettings = ({ collection, onClose }) => {
const [isModified, setIsModified] = useState(false); const [isModified, setIsModified] = useState(false);
const { environments } = collection; const { environments } = collection;
const [openCreateModal, setOpenCreateModal] = useState(false);
const [openImportModal, setOpenImportModal] = useState(false);
const [selectedEnvironment, setSelectedEnvironment] = useState(null); const [selectedEnvironment, setSelectedEnvironment] = useState(null);
const [tab, setTab] = useState('default'); const [tab, setTab] = useState('default');
if (!environments || !environments.length) { if (!environments || !environments.length) {
return ( return (
<StyledWrapper> <StyledWrapper>
<Modal <Modal size="md" title="Environments" handleCancel={onClose} hideCancel={true} hideFooter={true}>
size="md"
title="Environments"
confirmText={'Go back'}
handleConfirm={() => setTab('default')}
handleCancel={onClose}
hideCancel={true}
>
{tab === 'create' ? ( {tab === 'create' ? (
<CreateEnvironment collection={collection} /> <CreateEnvironment collection={collection} onClose={() => setTab('default')} />
) : tab === 'import' ? ( ) : tab === 'import' ? (
<ImportEnvironment collection={collection} /> <ImportEnvironment collection={collection} onClose={() => setTab('default')} />
) : ( ) : (
<DefaultTab setTab={setTab} /> <></>
)} )}
<DefaultTab setTab={setTab} />
</Modal> </Modal>
</StyledWrapper> </StyledWrapper>
); );

View File

@ -12,8 +12,8 @@ const FolderSettings = ({ collection, folder }) => {
const dispatch = useDispatch(); const dispatch = useDispatch();
let tab = 'headers'; let tab = 'headers';
const { folderLevelSettingsSelectedTab } = collection; const { folderLevelSettingsSelectedTab } = collection;
if (folderLevelSettingsSelectedTab?.[folder.uid]) { if (folderLevelSettingsSelectedTab?.[folder?.uid]) {
tab = folderLevelSettingsSelectedTab[folder.uid]; tab = folderLevelSettingsSelectedTab[folder?.uid];
} }
const setTab = (tab) => { const setTab = (tab) => {

View File

@ -417,7 +417,25 @@ export const transformCollectionToSaveToExportAsFile = (collection, options = {}
collectionToSave.items = []; collectionToSave.items = [];
collectionToSave.activeEnvironmentUid = collection.activeEnvironmentUid; collectionToSave.activeEnvironmentUid = collection.activeEnvironmentUid;
collectionToSave.environments = collection.environments || []; 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); collectionToSave.brunoConfig = cloneDeep(collection?.brunoConfig);