pr review changes (#2563)

This commit is contained in:
lohit 2024-07-04 14:47:46 +05:30 committed by GitHub
parent c8f95a34e9
commit 40f7be534a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 18 additions and 14 deletions

View File

@ -1179,7 +1179,6 @@ export const collectionsSlice = createSlice({
uid: uuid(), uid: uuid(),
name: '', name: '',
value: '', value: '',
type: 'request',
enabled: true enabled: true
}); });
set(folder, 'root.request.vars.req', vars); set(folder, 'root.request.vars.req', vars);
@ -1189,7 +1188,6 @@ export const collectionsSlice = createSlice({
uid: uuid(), uid: uuid(),
name: '', name: '',
value: '', value: '',
type: 'response',
enabled: true enabled: true
}); });
set(folder, 'root.request.vars.res', vars); set(folder, 'root.request.vars.res', vars);

View File

@ -380,7 +380,7 @@ export const transformCollectionToSaveToExportAsFile = (collection, options = {}
} }
} }
if (si?.root) { if (si.type == 'folder' && si?.root) {
di.root = { di.root = {
request: { request: {
headers: si?.root?.request?.headers, headers: si?.root?.request?.headers,
@ -393,10 +393,6 @@ export const transformCollectionToSaveToExportAsFile = (collection, options = {}
name: si?.root?.meta?.name name: si?.root?.meta?.name
} }
}; };
di.root.request.auth = {
mode: get(si.root.request, 'auth.mode', 'none')
};
} }
if (si.type === 'js') { if (si.type === 'js') {

View File

@ -38,11 +38,10 @@ const collectionBruToJson = (bru) => {
} }
}; };
const jsonToCollectionBru = (json) => { const jsonToCollectionBru = (json, isFolder) => {
try { try {
const collectionBruJson = { const collectionBruJson = {
headers: _.get(json, 'request.headers', []), headers: _.get(json, 'request.headers', []),
auth: _.get(json, 'request.auth', {}),
script: { script: {
req: _.get(json, 'request.script.req', ''), req: _.get(json, 'request.script.req', ''),
res: _.get(json, 'request.script.res', '') res: _.get(json, 'request.script.res', '')
@ -64,6 +63,10 @@ const jsonToCollectionBru = (json) => {
}; };
} }
if (!isFolder) {
collectionBruJson.auth = _.get(json, 'request.auth', {});
}
return _jsonToCollectionBru(collectionBruJson); return _jsonToCollectionBru(collectionBruJson);
} catch (error) { } catch (error) {
return Promise.reject(error); return Promise.reject(error);

View File

@ -161,7 +161,10 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
name: folderName name: folderName
}; };
const content = jsonToCollectionBru(folderRoot); const content = jsonToCollectionBru(
folderRoot,
true // isFolder
);
await writeFile(folderBruFilePath, content); await writeFile(folderBruFilePath, content);
} catch (error) { } catch (error) {
return Promise.reject(error); return Promise.reject(error);
@ -439,10 +442,14 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
const folderPath = path.join(currentPath, item.name); const folderPath = path.join(currentPath, item.name);
fs.mkdirSync(folderPath); fs.mkdirSync(folderPath);
const folderBruFilePath = path.join(folderPath, 'folder.bru'); if (item?.root?.meta?.name) {
const folderContent = jsonToCollectionBru(item.root); const folderBruFilePath = path.join(folderPath, 'folder.bru');
console.log('folder COntent', item.root, folderContent); const folderContent = jsonToCollectionBru(
fs.writeFileSync(folderBruFilePath, folderContent); item.root,
true // isFolder
);
fs.writeFileSync(folderBruFilePath, folderContent);
}
if (item.items && item.items.length) { if (item.items && item.items.length) {
parseCollectionItems(item.items, folderPath); parseCollectionItems(item.items, folderPath);