forked from extern/bruno
clone functionality in collection
This commit is contained in:
parent
8ddec6bf0c
commit
fff3e6d88a
84
package-lock.json
generated
84
package-lock.json
generated
@ -14297,6 +14297,7 @@
|
|||||||
},
|
},
|
||||||
"node_modules/react-is": {
|
"node_modules/react-is": {
|
||||||
"version": "18.2.0",
|
"version": "18.2.0",
|
||||||
|
"dev": true,
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/react-pdf": {
|
"node_modules/react-pdf": {
|
||||||
@ -17670,7 +17671,7 @@
|
|||||||
},
|
},
|
||||||
"packages/bruno-electron": {
|
"packages/bruno-electron": {
|
||||||
"name": "bruno",
|
"name": "bruno",
|
||||||
"version": "v1.3.0",
|
"version": "v1.4.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@aws-sdk/credential-providers": "^3.425.0",
|
"@aws-sdk/credential-providers": "^3.425.0",
|
||||||
"@usebruno/js": "0.9.3",
|
"@usebruno/js": "0.9.3",
|
||||||
@ -21404,8 +21405,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@tabler/icons": {
|
"@tabler/icons": {
|
||||||
"version": "1.119.0",
|
"version": "1.119.0"
|
||||||
"requires": {}
|
|
||||||
},
|
},
|
||||||
"@tippyjs/react": {
|
"@tippyjs/react": {
|
||||||
"version": "4.2.6",
|
"version": "4.2.6",
|
||||||
@ -21957,8 +21957,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@usebruno/schema": {
|
"@usebruno/schema": {
|
||||||
"version": "file:packages/bruno-schema",
|
"version": "file:packages/bruno-schema"
|
||||||
"requires": {}
|
|
||||||
},
|
},
|
||||||
"@usebruno/testbench": {
|
"@usebruno/testbench": {
|
||||||
"version": "file:packages/bruno-testbench",
|
"version": "file:packages/bruno-testbench",
|
||||||
@ -22102,8 +22101,7 @@
|
|||||||
},
|
},
|
||||||
"@webpack-cli/configtest": {
|
"@webpack-cli/configtest": {
|
||||||
"version": "1.2.0",
|
"version": "1.2.0",
|
||||||
"dev": true,
|
"dev": true
|
||||||
"requires": {}
|
|
||||||
},
|
},
|
||||||
"@webpack-cli/info": {
|
"@webpack-cli/info": {
|
||||||
"version": "1.5.0",
|
"version": "1.5.0",
|
||||||
@ -22114,8 +22112,7 @@
|
|||||||
},
|
},
|
||||||
"@webpack-cli/serve": {
|
"@webpack-cli/serve": {
|
||||||
"version": "1.7.0",
|
"version": "1.7.0",
|
||||||
"dev": true,
|
"dev": true
|
||||||
"requires": {}
|
|
||||||
},
|
},
|
||||||
"@xtuc/ieee754": {
|
"@xtuc/ieee754": {
|
||||||
"version": "1.2.0",
|
"version": "1.2.0",
|
||||||
@ -22197,8 +22194,7 @@
|
|||||||
},
|
},
|
||||||
"ajv-keywords": {
|
"ajv-keywords": {
|
||||||
"version": "3.5.2",
|
"version": "3.5.2",
|
||||||
"dev": true,
|
"dev": true
|
||||||
"requires": {}
|
|
||||||
},
|
},
|
||||||
"amdefine": {
|
"amdefine": {
|
||||||
"version": "0.0.8"
|
"version": "0.0.8"
|
||||||
@ -23147,8 +23143,7 @@
|
|||||||
"chai-string": {
|
"chai-string": {
|
||||||
"version": "1.5.0",
|
"version": "1.5.0",
|
||||||
"resolved": "https://registry.npmjs.org/chai-string/-/chai-string-1.5.0.tgz",
|
"resolved": "https://registry.npmjs.org/chai-string/-/chai-string-1.5.0.tgz",
|
||||||
"integrity": "sha512-sydDC3S3pNAQMYwJrs6dQX0oBQ6KfIPuOZ78n7rocW0eJJlsHPh2t3kwW7xfwYA/1Bf6/arGtSUo16rxR2JFlw==",
|
"integrity": "sha512-sydDC3S3pNAQMYwJrs6dQX0oBQ6KfIPuOZ78n7rocW0eJJlsHPh2t3kwW7xfwYA/1Bf6/arGtSUo16rxR2JFlw=="
|
||||||
"requires": {}
|
|
||||||
},
|
},
|
||||||
"chalk": {
|
"chalk": {
|
||||||
"version": "4.1.2",
|
"version": "4.1.2",
|
||||||
@ -23583,8 +23578,7 @@
|
|||||||
},
|
},
|
||||||
"css-declaration-sorter": {
|
"css-declaration-sorter": {
|
||||||
"version": "6.3.1",
|
"version": "6.3.1",
|
||||||
"dev": true,
|
"dev": true
|
||||||
"requires": {}
|
|
||||||
},
|
},
|
||||||
"css-loader": {
|
"css-loader": {
|
||||||
"version": "6.7.3",
|
"version": "6.7.3",
|
||||||
@ -23703,8 +23697,7 @@
|
|||||||
},
|
},
|
||||||
"cssnano-utils": {
|
"cssnano-utils": {
|
||||||
"version": "3.1.0",
|
"version": "3.1.0",
|
||||||
"dev": true,
|
"dev": true
|
||||||
"requires": {}
|
|
||||||
},
|
},
|
||||||
"csso": {
|
"csso": {
|
||||||
"version": "4.2.0",
|
"version": "4.2.0",
|
||||||
@ -24931,8 +24924,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"goober": {
|
"goober": {
|
||||||
"version": "2.1.11",
|
"version": "2.1.11"
|
||||||
"requires": {}
|
|
||||||
},
|
},
|
||||||
"gopd": {
|
"gopd": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
@ -25326,8 +25318,7 @@
|
|||||||
},
|
},
|
||||||
"icss-utils": {
|
"icss-utils": {
|
||||||
"version": "5.1.0",
|
"version": "5.1.0",
|
||||||
"dev": true,
|
"dev": true
|
||||||
"requires": {}
|
|
||||||
},
|
},
|
||||||
"idb": {
|
"idb": {
|
||||||
"version": "7.1.1"
|
"version": "7.1.1"
|
||||||
@ -25927,8 +25918,7 @@
|
|||||||
},
|
},
|
||||||
"jest-pnp-resolver": {
|
"jest-pnp-resolver": {
|
||||||
"version": "1.2.3",
|
"version": "1.2.3",
|
||||||
"dev": true,
|
"dev": true
|
||||||
"requires": {}
|
|
||||||
},
|
},
|
||||||
"jest-regex-util": {
|
"jest-regex-util": {
|
||||||
"version": "29.2.0",
|
"version": "29.2.0",
|
||||||
@ -26647,8 +26637,7 @@
|
|||||||
"merge-refs": {
|
"merge-refs": {
|
||||||
"version": "1.2.2",
|
"version": "1.2.2",
|
||||||
"resolved": "https://registry.npmjs.org/merge-refs/-/merge-refs-1.2.2.tgz",
|
"resolved": "https://registry.npmjs.org/merge-refs/-/merge-refs-1.2.2.tgz",
|
||||||
"integrity": "sha512-RwcT7GsQR3KbuLw1rRuodq4Nt547BKEBkliZ0qqsrpyNne9bGTFtsFIsIpx82huWhcl3kOlOlH4H0xkPk/DqVw==",
|
"integrity": "sha512-RwcT7GsQR3KbuLw1rRuodq4Nt547BKEBkliZ0qqsrpyNne9bGTFtsFIsIpx82huWhcl3kOlOlH4H0xkPk/DqVw=="
|
||||||
"requires": {}
|
|
||||||
},
|
},
|
||||||
"merge-stream": {
|
"merge-stream": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
@ -26658,8 +26647,7 @@
|
|||||||
"version": "1.4.1"
|
"version": "1.4.1"
|
||||||
},
|
},
|
||||||
"meros": {
|
"meros": {
|
||||||
"version": "1.2.1",
|
"version": "1.2.1"
|
||||||
"requires": {}
|
|
||||||
},
|
},
|
||||||
"methods": {
|
"methods": {
|
||||||
"version": "1.1.2"
|
"version": "1.1.2"
|
||||||
@ -27536,23 +27524,19 @@
|
|||||||
},
|
},
|
||||||
"postcss-discard-comments": {
|
"postcss-discard-comments": {
|
||||||
"version": "5.1.2",
|
"version": "5.1.2",
|
||||||
"dev": true,
|
"dev": true
|
||||||
"requires": {}
|
|
||||||
},
|
},
|
||||||
"postcss-discard-duplicates": {
|
"postcss-discard-duplicates": {
|
||||||
"version": "5.1.0",
|
"version": "5.1.0",
|
||||||
"dev": true,
|
"dev": true
|
||||||
"requires": {}
|
|
||||||
},
|
},
|
||||||
"postcss-discard-empty": {
|
"postcss-discard-empty": {
|
||||||
"version": "5.1.1",
|
"version": "5.1.1",
|
||||||
"dev": true,
|
"dev": true
|
||||||
"requires": {}
|
|
||||||
},
|
},
|
||||||
"postcss-discard-overridden": {
|
"postcss-discard-overridden": {
|
||||||
"version": "5.1.0",
|
"version": "5.1.0",
|
||||||
"dev": true,
|
"dev": true
|
||||||
"requires": {}
|
|
||||||
},
|
},
|
||||||
"postcss-js": {
|
"postcss-js": {
|
||||||
"version": "3.0.3",
|
"version": "3.0.3",
|
||||||
@ -27634,8 +27618,7 @@
|
|||||||
},
|
},
|
||||||
"postcss-modules-extract-imports": {
|
"postcss-modules-extract-imports": {
|
||||||
"version": "3.0.0",
|
"version": "3.0.0",
|
||||||
"dev": true,
|
"dev": true
|
||||||
"requires": {}
|
|
||||||
},
|
},
|
||||||
"postcss-modules-local-by-default": {
|
"postcss-modules-local-by-default": {
|
||||||
"version": "4.0.0",
|
"version": "4.0.0",
|
||||||
@ -27668,8 +27651,7 @@
|
|||||||
},
|
},
|
||||||
"postcss-normalize-charset": {
|
"postcss-normalize-charset": {
|
||||||
"version": "5.1.0",
|
"version": "5.1.0",
|
||||||
"dev": true,
|
"dev": true
|
||||||
"requires": {}
|
|
||||||
},
|
},
|
||||||
"postcss-normalize-display-values": {
|
"postcss-normalize-display-values": {
|
||||||
"version": "5.1.0",
|
"version": "5.1.0",
|
||||||
@ -28145,11 +28127,11 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"react-inspector": {
|
"react-inspector": {
|
||||||
"version": "6.0.2",
|
"version": "6.0.2"
|
||||||
"requires": {}
|
|
||||||
},
|
},
|
||||||
"react-is": {
|
"react-is": {
|
||||||
"version": "18.2.0"
|
"version": "18.2.0",
|
||||||
|
"dev": true
|
||||||
},
|
},
|
||||||
"react-pdf": {
|
"react-pdf": {
|
||||||
"version": "7.5.1",
|
"version": "7.5.1",
|
||||||
@ -28311,8 +28293,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"redux-thunk": {
|
"redux-thunk": {
|
||||||
"version": "2.4.2",
|
"version": "2.4.2"
|
||||||
"requires": {}
|
|
||||||
},
|
},
|
||||||
"regenerate": {
|
"regenerate": {
|
||||||
"version": "1.4.2",
|
"version": "1.4.2",
|
||||||
@ -28549,8 +28530,7 @@
|
|||||||
},
|
},
|
||||||
"rollup-plugin-peer-deps-external": {
|
"rollup-plugin-peer-deps-external": {
|
||||||
"version": "2.2.4",
|
"version": "2.2.4",
|
||||||
"dev": true,
|
"dev": true
|
||||||
"requires": {}
|
|
||||||
},
|
},
|
||||||
"rollup-plugin-postcss": {
|
"rollup-plugin-postcss": {
|
||||||
"version": "4.0.2",
|
"version": "4.0.2",
|
||||||
@ -29108,8 +29088,7 @@
|
|||||||
},
|
},
|
||||||
"style-loader": {
|
"style-loader": {
|
||||||
"version": "3.3.1",
|
"version": "3.3.1",
|
||||||
"dev": true,
|
"dev": true
|
||||||
"requires": {}
|
|
||||||
},
|
},
|
||||||
"styled-components": {
|
"styled-components": {
|
||||||
"version": "5.3.6",
|
"version": "5.3.6",
|
||||||
@ -29138,8 +29117,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"styled-jsx": {
|
"styled-jsx": {
|
||||||
"version": "5.0.7",
|
"version": "5.0.7"
|
||||||
"requires": {}
|
|
||||||
},
|
},
|
||||||
"stylehacks": {
|
"stylehacks": {
|
||||||
"version": "5.1.1",
|
"version": "5.1.1",
|
||||||
@ -29812,8 +29790,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"use-sync-external-store": {
|
"use-sync-external-store": {
|
||||||
"version": "1.2.0",
|
"version": "1.2.0"
|
||||||
"requires": {}
|
|
||||||
},
|
},
|
||||||
"utf8-byte-length": {
|
"utf8-byte-length": {
|
||||||
"version": "1.0.4",
|
"version": "1.0.4",
|
||||||
@ -29974,8 +29951,7 @@
|
|||||||
},
|
},
|
||||||
"acorn-import-assertions": {
|
"acorn-import-assertions": {
|
||||||
"version": "1.8.0",
|
"version": "1.8.0",
|
||||||
"dev": true,
|
"dev": true
|
||||||
"requires": {}
|
|
||||||
},
|
},
|
||||||
"schema-utils": {
|
"schema-utils": {
|
||||||
"version": "3.1.1",
|
"version": "3.1.1",
|
||||||
|
@ -0,0 +1,155 @@
|
|||||||
|
import React, { useRef, useEffect } from 'react';
|
||||||
|
import { useDispatch } from 'react-redux';
|
||||||
|
import { useFormik } from 'formik';
|
||||||
|
import * as Yup from 'yup';
|
||||||
|
import { browseDirectory } from 'providers/ReduxStore/slices/collections/actions';
|
||||||
|
import { cloneCollection } from 'providers/ReduxStore/slices/collections/actions';
|
||||||
|
import toast from 'react-hot-toast';
|
||||||
|
import Tooltip from 'components/Tooltip';
|
||||||
|
import Modal from 'components/Modal';
|
||||||
|
|
||||||
|
const CloneCollection = ({ onClose, collection }) => {
|
||||||
|
const inputRef = useRef();
|
||||||
|
const dispatch = useDispatch();
|
||||||
|
|
||||||
|
const formik = useFormik({
|
||||||
|
enableReinitialize: true,
|
||||||
|
initialValues: {
|
||||||
|
collectionName: '',
|
||||||
|
collectionFolderName: '',
|
||||||
|
collectionLocation: ''
|
||||||
|
},
|
||||||
|
validationSchema: Yup.object({
|
||||||
|
collectionName: Yup.string()
|
||||||
|
.min(1, 'must be at least 1 character')
|
||||||
|
.max(50, 'must be 50 characters or less')
|
||||||
|
.required('collection name is required'),
|
||||||
|
collectionFolderName: Yup.string()
|
||||||
|
.min(1, 'must be at least 1 character')
|
||||||
|
.max(50, 'must be 50 characters or less')
|
||||||
|
.matches(/^[\w\-. ]+$/, 'Folder name contains invalid characters')
|
||||||
|
.required('folder name is required'),
|
||||||
|
collectionLocation: Yup.string().min(1, 'location is required').required('location is required')
|
||||||
|
}),
|
||||||
|
onSubmit: (values) => {
|
||||||
|
dispatch(
|
||||||
|
cloneCollection(
|
||||||
|
values.collectionName,
|
||||||
|
values.collectionFolderName,
|
||||||
|
values.collectionLocation,
|
||||||
|
collection.pathname
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.then(() => {
|
||||||
|
toast.success('Collection created');
|
||||||
|
onClose();
|
||||||
|
})
|
||||||
|
.catch(() => toast.error('An error occurred while creating the collection'));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const browse = () => {
|
||||||
|
dispatch(browseDirectory())
|
||||||
|
.then((dirPath) => {
|
||||||
|
// When the user closes the diolog without selecting anything dirPath will be false
|
||||||
|
if (typeof dirPath === 'string') {
|
||||||
|
formik.setFieldValue('collectionLocation', dirPath);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
formik.setFieldValue('collectionLocation', '');
|
||||||
|
console.error(error);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (inputRef && inputRef.current) {
|
||||||
|
inputRef.current.focus();
|
||||||
|
}
|
||||||
|
}, [inputRef]);
|
||||||
|
|
||||||
|
const onSubmit = () => formik.handleSubmit();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Modal size="sm" title="Clone Collection" confirmText="Create" handleConfirm={onSubmit} handleCancel={onClose}>
|
||||||
|
<form className="bruno-form" onSubmit={formik.handleSubmit}>
|
||||||
|
<div>
|
||||||
|
<label htmlFor="collection-name" className="flex items-center font-semibold">
|
||||||
|
Name
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
id="collection-name"
|
||||||
|
type="text"
|
||||||
|
name="collectionName"
|
||||||
|
ref={inputRef}
|
||||||
|
className="block textbox mt-2 w-full"
|
||||||
|
onChange={(e) => {
|
||||||
|
formik.handleChange(e);
|
||||||
|
if (formik.values.collectionName === formik.values.collectionFolderName) {
|
||||||
|
formik.setFieldValue('collectionFolderName', e.target.value);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
autoComplete="off"
|
||||||
|
autoCorrect="off"
|
||||||
|
autoCapitalize="off"
|
||||||
|
spellCheck="false"
|
||||||
|
value={formik.values.collectionName || ''}
|
||||||
|
/>
|
||||||
|
{formik.touched.collectionName && formik.errors.collectionName ? (
|
||||||
|
<div className="text-red-500">{formik.errors.collectionName}</div>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
<label htmlFor="collection-location" className="block font-semibold mt-3">
|
||||||
|
Location
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
id="collection-location"
|
||||||
|
type="text"
|
||||||
|
name="collectionLocation"
|
||||||
|
readOnly={true}
|
||||||
|
className="block textbox mt-2 w-full cursor-pointer"
|
||||||
|
autoComplete="off"
|
||||||
|
autoCorrect="off"
|
||||||
|
autoCapitalize="off"
|
||||||
|
spellCheck="false"
|
||||||
|
value={formik.values.collectionLocation || ''}
|
||||||
|
onClick={browse}
|
||||||
|
/>
|
||||||
|
{formik.touched.collectionLocation && formik.errors.collectionLocation ? (
|
||||||
|
<div className="text-red-500">{formik.errors.collectionLocation}</div>
|
||||||
|
) : null}
|
||||||
|
<div className="mt-1">
|
||||||
|
<span className="text-link cursor-pointer hover:underline" onClick={browse}>
|
||||||
|
Browse
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<label htmlFor="collection-folder-name" className="flex items-center mt-3">
|
||||||
|
<span className="font-semibold">Folder Name</span>
|
||||||
|
<Tooltip
|
||||||
|
text="This folder will be created under the selected location"
|
||||||
|
tooltipId="collection-folder-name-tooltip"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
id="collection-folder-name"
|
||||||
|
type="text"
|
||||||
|
name="collectionFolderName"
|
||||||
|
className="block textbox mt-2 w-full"
|
||||||
|
onChange={formik.handleChange}
|
||||||
|
autoComplete="off"
|
||||||
|
autoCorrect="off"
|
||||||
|
autoCapitalize="off"
|
||||||
|
spellCheck="false"
|
||||||
|
value={formik.values.collectionFolderName || ''}
|
||||||
|
/>
|
||||||
|
{formik.touched.collectionFolderName && formik.errors.collectionFolderName ? (
|
||||||
|
<div className="text-red-500">{formik.errors.collectionFolderName}</div>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</Modal>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default CloneCollection;
|
@ -20,11 +20,13 @@ import exportCollection from 'utils/collections/export';
|
|||||||
|
|
||||||
import RenameCollection from './RenameCollection';
|
import RenameCollection from './RenameCollection';
|
||||||
import StyledWrapper from './StyledWrapper';
|
import StyledWrapper from './StyledWrapper';
|
||||||
|
import CloneCollection from './CloneCollection/index';
|
||||||
|
|
||||||
const Collection = ({ collection, searchText }) => {
|
const Collection = ({ collection, searchText }) => {
|
||||||
const [showNewFolderModal, setShowNewFolderModal] = useState(false);
|
const [showNewFolderModal, setShowNewFolderModal] = useState(false);
|
||||||
const [showNewRequestModal, setShowNewRequestModal] = useState(false);
|
const [showNewRequestModal, setShowNewRequestModal] = useState(false);
|
||||||
const [showRenameCollectionModal, setShowRenameCollectionModal] = useState(false);
|
const [showRenameCollectionModal, setShowRenameCollectionModal] = useState(false);
|
||||||
|
const [showCloneCollectionModalOpen, setShowCloneCollectionModalOpen] = useState(false);
|
||||||
const [showExportCollectionModal, setShowExportCollectionModal] = useState(false);
|
const [showExportCollectionModal, setShowExportCollectionModal] = useState(false);
|
||||||
const [showRemoveCollectionModal, setShowRemoveCollectionModal] = useState(false);
|
const [showRemoveCollectionModal, setShowRemoveCollectionModal] = useState(false);
|
||||||
const [collectionIsCollapsed, setCollectionIsCollapsed] = useState(collection.collapsed);
|
const [collectionIsCollapsed, setCollectionIsCollapsed] = useState(collection.collapsed);
|
||||||
@ -133,6 +135,9 @@ const Collection = ({ collection, searchText }) => {
|
|||||||
{showExportCollectionModal && (
|
{showExportCollectionModal && (
|
||||||
<ExportCollection collection={collection} onClose={() => setShowExportCollectionModal(false)} />
|
<ExportCollection collection={collection} onClose={() => setShowExportCollectionModal(false)} />
|
||||||
)}
|
)}
|
||||||
|
{showCloneCollectionModalOpen && (
|
||||||
|
<CloneCollection collection={collection} onClose={() => setShowCloneCollectionModalOpen(false)} />
|
||||||
|
)}
|
||||||
<div className="flex py-1 collection-name items-center" ref={drop}>
|
<div className="flex py-1 collection-name items-center" ref={drop}>
|
||||||
<div
|
<div
|
||||||
className="flex flex-grow items-center overflow-hidden"
|
className="flex flex-grow items-center overflow-hidden"
|
||||||
@ -169,6 +174,15 @@ const Collection = ({ collection, searchText }) => {
|
|||||||
>
|
>
|
||||||
New Folder
|
New Folder
|
||||||
</div>
|
</div>
|
||||||
|
<div
|
||||||
|
className="dropdown-item"
|
||||||
|
onClick={(e) => {
|
||||||
|
menuDropdownTippyRef.current.hide();
|
||||||
|
setShowCloneCollectionModalOpen(true);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Clone
|
||||||
|
</div>
|
||||||
<div
|
<div
|
||||||
className="dropdown-item"
|
className="dropdown-item"
|
||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
|
@ -939,7 +939,16 @@ export const createCollection = (collectionName, collectionFolderName, collectio
|
|||||||
.catch(reject);
|
.catch(reject);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
export const cloneCollection = (collectionName, collectionFolderName, collectionLocation, perviousPath) => () => {
|
||||||
|
const { ipcRenderer } = window;
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
ipcRenderer
|
||||||
|
.invoke('renderer:clone-collection', collectionName, collectionFolderName, collectionLocation, perviousPath)
|
||||||
|
.then(resolve)
|
||||||
|
.catch(reject);
|
||||||
|
});
|
||||||
|
};
|
||||||
export const openCollection = () => () => {
|
export const openCollection = () => () => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const { ipcRenderer } = window;
|
const { ipcRenderer } = window;
|
||||||
|
@ -70,7 +70,43 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
// clone collection
|
||||||
|
ipcMain.handle(
|
||||||
|
'renderer:clone-collection',
|
||||||
|
async (event, collectionName, collectionFolderName, collectionLocation, perviousPath) => {
|
||||||
|
try {
|
||||||
|
const dirPath = path.join(collectionLocation, collectionFolderName);
|
||||||
|
if (fs.existsSync(dirPath)) {
|
||||||
|
throw new Error(`collection: ${dirPath} already exists`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isValidPathname(dirPath)) {
|
||||||
|
throw new Error(`collection: invalid pathname - ${dir}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
await createDirectory(dirPath);
|
||||||
|
const uid = generateUidBasedOnHash(dirPath);
|
||||||
|
const brunoJsonFilePath = path.join(perviousPath, 'bruno.json');
|
||||||
|
const content = fs.readFileSync(brunoJsonFilePath, 'utf8');
|
||||||
|
let json = JSON.parse(content);
|
||||||
|
json.name = collectionName;
|
||||||
|
const cont = await stringifyJson(json);
|
||||||
|
await writeFile(path.join(dirPath, 'bruno.json'), cont);
|
||||||
|
const files = searchForBruFiles(perviousPath);
|
||||||
|
console.log(files);
|
||||||
|
for (const sourceFilePath of files) {
|
||||||
|
const fileName = path.basename(sourceFilePath);
|
||||||
|
const destinationFilePath = path.join(dirPath, fileName);
|
||||||
|
console.log(destinationFilePath);
|
||||||
|
fs.copyFileSync(sourceFilePath, destinationFilePath);
|
||||||
|
}
|
||||||
|
mainWindow.webContents.send('main:collection-opened', dirPath, uid, json);
|
||||||
|
ipcMain.emit('main:collection-opened', mainWindow, dirPath, uid);
|
||||||
|
} catch (error) {
|
||||||
|
return Promise.reject(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
// rename collection
|
// rename collection
|
||||||
ipcMain.handle('renderer:rename-collection', async (event, newName, collectionPathname) => {
|
ipcMain.handle('renderer:rename-collection', async (event, newName, collectionPathname) => {
|
||||||
try {
|
try {
|
||||||
|
Loading…
Reference in New Issue
Block a user