add: export info & remove unused component (#6547)

* add: export info

* changes
This commit is contained in:
naman-bruno
2025-12-30 23:06:57 +05:30
committed by GitHub
parent 8fa8ae5fed
commit 27dff7567c
10 changed files with 81 additions and 53 deletions

View File

@@ -10,8 +10,10 @@ import { cloneDeep } from 'lodash';
import { transformCollectionToSaveToExportAsFile } from 'utils/collections/index';
import { useSelector } from 'react-redux';
import { findCollectionByUid, areItemsLoading } from 'utils/collections/index';
import { useApp } from 'providers/App';
const ShareCollection = ({ onClose, collectionUid }) => {
const { version } = useApp();
const collection = useSelector((state) => findCollectionByUid(state.collections.collections, collectionUid));
const isCollectionLoading = areItemsLoading(collection);
@@ -39,7 +41,7 @@ const ShareCollection = ({ onClose, collectionUid }) => {
const handleExportBrunoCollection = () => {
const collectionCopy = cloneDeep(collection);
exportBrunoCollection(transformCollectionToSaveToExportAsFile(collectionCopy));
exportBrunoCollection(transformCollectionToSaveToExportAsFile(collectionCopy), version);
onClose();
};
@@ -51,7 +53,7 @@ const ShareCollection = ({ onClose, collectionUid }) => {
const handleExportOpenCollection = () => {
const collectionCopy = cloneDeep(collection);
exportOpenCollection(transformCollectionToSaveToExportAsFile(collectionCopy));
exportOpenCollection(transformCollectionToSaveToExportAsFile(collectionCopy), version);
onClose();
};

View File

@@ -1,35 +0,0 @@
import React from 'react';
import exportBrunoCollection from 'utils/collections/export';
import exportPostmanCollection from 'utils/exporters/postman-collection';
import cloneDeep from 'lodash/cloneDeep';
import Modal from 'components/Modal';
import { transformCollectionToSaveToExportAsFile } from 'utils/collections/index';
const ExportCollection = ({ onClose, collection }) => {
const handleExportBrunoCollection = () => {
const collectionCopy = cloneDeep(collection);
exportBrunoCollection(transformCollectionToSaveToExportAsFile(collectionCopy));
onClose();
};
const handleExportPostmanCollection = () => {
const collectionCopy = cloneDeep(collection);
exportPostmanCollection(collectionCopy);
onClose();
};
return (
<Modal size="sm" title="Export Collection" hideFooter={true} handleConfirm={onClose} handleCancel={onClose}>
<div>
<div className="text-link hover:underline cursor-pointer" onClick={handleExportBrunoCollection}>
Bruno Collection
</div>
<div className="text-link hover:underline cursor-pointer mt-2" onClick={handleExportPostmanCollection}>
Postman Collection
</div>
</div>
</Modal>
);
};
export default ExportCollection;

View File

@@ -57,8 +57,8 @@ const WorkspaceOverview = ({ workspace }) => {
setImportCollectionLocationModalOpen(true);
};
const handleImportCollectionLocation = (convertedCollection, collectionLocation) => {
dispatch(importCollection(convertedCollection, collectionLocation))
const handleImportCollectionLocation = (convertedCollection, collectionLocation, options = {}) => {
dispatch(importCollection(convertedCollection, collectionLocation, options))
.then(() => {
setImportCollectionLocationModalOpen(false);
setImportData(null);

View File

@@ -93,7 +93,7 @@ export const deleteSecretsInEnvs = (envs) => {
});
};
export const exportCollection = (collection) => {
export const exportCollection = (collection, version) => {
// delete uids
delete collection.uid;
@@ -105,6 +105,9 @@ export const exportCollection = (collection) => {
deleteSecretsInEnvs(collection.environments);
transformItem(collection.items);
collection.exportedAt = new Date().toISOString();
collection.exportedUsing = version ? `Bruno/${version}` : 'Bruno';
const fileName = `${collection.name}.json`;
const fileBlob = new Blob([JSON.stringify(collection, null, 2)], { type: 'application/json' });

View File

@@ -3,9 +3,18 @@ import jsyaml from 'js-yaml';
import { brunoToOpenCollection } from '@usebruno/converters';
import { sanitizeName } from 'utils/common/regex';
export const exportCollection = (collection) => {
export const exportCollection = (collection, version) => {
const openCollection = brunoToOpenCollection(collection);
if (!openCollection.extensions) {
openCollection.extensions = {};
}
if (!openCollection.extensions.bruno) {
openCollection.extensions.bruno = {};
}
openCollection.extensions.bruno.exportedAt = new Date().toISOString();
openCollection.extensions.bruno.exportedUsing = version ? `Bruno/${version}` : 'Bruno';
const yamlContent = jsyaml.dump(openCollection, {
indent: 2,
lineWidth: -1,

View File

@@ -1,9 +1,16 @@
import { BrunoError } from 'utils/common/error';
import { validateSchema, transformItemsInCollection, updateUidsInCollection, hydrateSeqInCollection } from './common';
const stripExportMetadata = (collection) => {
delete collection.exportedAt;
delete collection.exportedUsing;
return collection;
};
export const processBrunoCollection = async (jsonData) => {
try {
let collection = hydrateSeqInCollection(jsonData);
let collection = stripExportMetadata(jsonData);
collection = hydrateSeqInCollection(collection);
collection = updateUidsInCollection(collection);
collection = transformItemsInCollection(collection);
await validateSchema(collection);

View File

@@ -145,12 +145,33 @@ export const brunoToOpenCollection = (collection: BrunoCollection): OpenCollecti
openCollection.bundled = true;
const extensions: { ignore?: string[] } = {};
const brunoExtension: {
ignore?: string[];
presets?: {
requestType?: string;
requestUrl?: string;
};
} = {};
if ((collection.brunoConfig as BrunoConfig)?.ignore?.length) {
extensions.ignore = (collection.brunoConfig as BrunoConfig).ignore;
brunoExtension.ignore = (collection.brunoConfig as BrunoConfig).ignore;
}
if (Object.keys(extensions).length > 0) {
openCollection.extensions = extensions;
const presets = (collection.brunoConfig as BrunoConfig)?.presets;
if (presets?.requestType || presets?.requestUrl) {
brunoExtension.presets = {};
if (presets.requestType) {
brunoExtension.presets.requestType = presets.requestType;
}
if (presets.requestUrl) {
brunoExtension.presets.requestUrl = presets.requestUrl;
}
}
if (Object.keys(brunoExtension).length > 0) {
openCollection.extensions = {
bruno: brunoExtension
};
}
return openCollection;

View File

@@ -60,16 +60,16 @@ const fromOpenCollectionOAuth2 = (auth: AuthOAuth2): BrunoAuth => {
clientSecret: base.clientSecret || null,
scope: base.scope || null,
state: base.state || null,
pkce: base.pkce || null,
pkce: base.pkce ?? false,
credentialsPlacement: base.credentialsPlacement || null,
credentialsId: base.credentialsId || null,
tokenPlacement: base.tokenPlacement || null,
tokenHeaderPrefix: base.tokenHeaderPrefix || null,
tokenQueryKey: base.tokenQueryKey || null,
refreshTokenUrl: base.refreshTokenUrl || null,
autoRefreshToken: base.autoRefreshToken || null,
autoFetchToken: base.autoFetchToken || null,
additionalParameters: null
autoRefreshToken: base.autoRefreshToken ?? false,
autoFetchToken: base.autoFetchToken ?? false,
additionalParameters: {}
},
wsse: null,
apikey: null

View File

@@ -7,9 +7,16 @@ import { fromOpenCollectionFolder } from "./folder";
import { fromOpenCollectionEnvironments } from "./environment";
const fromOpenCollectionConfig = (oc: OpenCollection): BrunoConfig => {
const extensions = oc.extensions;
const ignoreList = extensions && Array.isArray(extensions.ignore)
? extensions.ignore as string[]
const brunoExtension = oc.extensions?.bruno as {
ignore?: string[];
presets?: {
requestType?: string;
requestUrl?: string;
};
} | undefined;
const ignoreList = brunoExtension && Array.isArray(brunoExtension.ignore)
? brunoExtension.ignore
: ['node_modules', '.git'];
const brunoConfig: BrunoConfig = {
@@ -19,6 +26,16 @@ const fromOpenCollectionConfig = (oc: OpenCollection): BrunoConfig => {
ignore: ignoreList
};
if (brunoExtension?.presets?.requestType || brunoExtension?.presets?.requestUrl) {
brunoConfig.presets = {};
if (brunoExtension.presets.requestType) {
brunoConfig.presets.requestType = brunoExtension.presets.requestType;
}
if (brunoExtension.presets.requestUrl) {
brunoConfig.presets.requestUrl = brunoExtension.presets.requestUrl;
}
}
const config = oc.config;
if (!config) {
return brunoConfig;

View File

@@ -171,6 +171,10 @@ export interface BrunoConfig {
name?: string;
type?: string;
ignore?: string[];
presets?: {
requestType?: string;
requestUrl?: string;
};
protobuf?: {
protoFiles?: { path: string }[];
importPaths?: { path: string; disabled?: boolean }[];