Skip to content

Commit

Permalink
add folder condition in collectionChangeFileEvent and some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pooja-bruno committed Jan 6, 2025
1 parent 22f5c5a commit ee08fca
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const AwsV4Auth = ({ collection }) => {
const dispatch = useDispatch();
const { storedTheme } = useTheme();

const awsv4Auth = collection.draft ? get(collection, 'draft..request.auth.awsv4', {}) : get(collection, 'root.request.auth.awsv4', {});
const awsv4Auth = collection.draft ? get(collection, 'draft.request.auth.awsv4', {}) : get(collection, 'root.request.auth.awsv4', {});

const handleSave = () => dispatch(saveCollectionRoot(collection.uid));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const DigestAuth = ({ collection }) => {
const dispatch = useDispatch();
const { storedTheme } = useTheme();

const digestAuth = collection.draft ? get(collection, 'draft..request.auth.digest', {}) : get(collection, 'root.request.auth.digest', {});
const digestAuth = collection.draft ? get(collection, 'draft.request.auth.digest', {}) : get(collection, 'root.request.auth.digest', {});

const handleSave = () => dispatch(saveCollectionRoot(collection.uid));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const OAuth2AuthorizationCode = ({ item, collection }) => {
const dispatch = useDispatch();
const { storedTheme } = useTheme();

const oAuth = get(collection, 'root.request.auth.oauth2', {});
const oAuth = collection.draft ? get(collection, 'draft.request.auth.oauth2', {}) : get(collection, 'root.request.auth.oauth2', {});

const handleRun = async () => {
dispatch(sendCollectionOauth2Request(collection.uid));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const Docs = ({ collection }) => {
const dispatch = useDispatch();
const { displayedTheme } = useTheme();
const [isEditing, setIsEditing] = useState(false);
const docs = get(collection, 'draft.docs') || get(collection, 'root.docs', '');
const docs = collection.draft ? get(collection, 'draft.docs', '') : get(collection, 'root.docs', '');
const preferences = useSelector((state) => state.app.preferences);
const { theme, storedTheme } = useTheme();

Expand Down
4 changes: 2 additions & 2 deletions packages/bruno-app/src/components/CollectionSettings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ const CollectionSettings = ({ collection }) => {
const hasTests = root?.request?.tests;
const hasDocs = root?.docs;

const headers = collection.draft ? get(collection, 'draft.request.headers') : get(collection, 'root.request.headers', []);
const headers = collection.draft ? get(collection, 'draft.request.headers', []) : get(collection, 'root.request.headers', []);
const activeHeadersCount = headers.filter((header) => header.enabled).length;

const requestVars = collection.draft ? get(collection, 'draft.request.vars.req', []) : get(collection, 'root.request.vars.req', []);
const responseVars = collection.draft ? get(collection, 'draft.request.vars.res', []) : get(collection, 'root.request.vars.res', []);
const activeVarsCount = requestVars.filter((v) => v.enabled).length + responseVars.filter((v) => v.enabled).length;
const auth = collection.draft ? get(collection, 'draft.request,auth', {}).mode : get(collection, 'root.request.auth', {}).mode;
const auth = collection.draft ? get(collection, 'draft.request.auth', {}).mode : get(collection, 'root.request.auth', {}).mode;

const proxyConfig = get(collection, 'brunoConfig.proxy', {});
const clientCertConfig = get(collection, 'brunoConfig.clientCertificates.certs', []);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,6 @@ export const saveFolderRoot = (collectionUid, folderUid) => (dispatch, getState)

const transformFolderRoot = transformFolderRootToSave(folder);

console.log({ transformFolderRoot })

const folderData = {
name: folder.name,
pathname: folder.pathname,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1635,11 +1635,24 @@ export const collectionsSlice = createSlice({
// check and update collection root
if (collection && file.meta.collectionRoot) {
collection.root = file.data;
collection.draft = null;
return;
}

if (collection) {
const item = findItemInCollection(collection, file.data.uid);
const isFolderRoot = file.meta.folderRoot ? true : false;


if (isFolderRoot) {
const folderPath = getDirectoryName(file.meta.pathname);
const folderItem = findItemInCollectionByPathname(collection, folderPath);
if (folderItem) {
folderItem.root = file.data;
folderItem.draft = null;
}
return;
}

if (item) {
// whenever a user attempts to sort a req within the same folder
Expand Down
2 changes: 1 addition & 1 deletion packages/bruno-app/src/utils/collections/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,7 @@ const mergeVars = (collection, requestTreePath = []) => {
let collectionVariables = {};
let folderVariables = {};
let requestVariables = {};
let collectionRequestVars = get(collection, 'root.request.vars.req', []);
let collectionRequestVars = collection.draft ? get(collection, 'draft.request.vars.req', []) : get(collection, 'root.request.vars.req', []);
collectionRequestVars.forEach((_var) => {
if (_var.enabled) {
collectionVariables[_var.name] = _var.value;
Expand Down
2 changes: 1 addition & 1 deletion packages/bruno-cli/src/runner/prepare-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const prepareRequest = (item = {}, collection = {}) => {
responseType: 'arraybuffer'
};

const collectionAuth = get(collection, 'root.request.auth');
const collectionAuth = collection.draft ? get(collection, 'draft.request.auth') : get(collection, 'root.request.auth');
if (collectionAuth && request.auth.mode === 'inherit') {
if (collectionAuth.mode === 'basic') {
axiosRequest.auth = {
Expand Down
14 changes: 7 additions & 7 deletions packages/bruno-cli/src/utils/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const os = require('os');
const mergeHeaders = (collection, request, requestTreePath) => {
let headers = new Map();

let collectionHeaders = get(collection, 'root.request.headers', []);
let collectionHeaders = collection.draft ? get(collection, 'draft.request.headers', []) : get(collection, 'root.request.headers', []);
collectionHeaders.forEach((header) => {
if (header.enabled) {
headers.set(header.name, header.value);
Expand Down Expand Up @@ -34,7 +34,7 @@ const mergeHeaders = (collection, request, requestTreePath) => {

const mergeVars = (collection, request, requestTreePath) => {
let reqVars = new Map();
let collectionRequestVars = get(collection, 'root.request.vars.req', []);
let collectionRequestVars = collection.draft ? get(collection, 'draft.request.vars.req', []) : get(collection, 'root.request.vars.req', []);
let collectionVariables = {};
collectionRequestVars.forEach((_var) => {
if (_var.enabled) {
Expand Down Expand Up @@ -78,7 +78,7 @@ const mergeVars = (collection, request, requestTreePath) => {
}

let resVars = new Map();
let collectionResponseVars = get(collection, 'root.request.vars.res', []);
let collectionResponseVars = collection.draft ? get(collection, 'draft.request.vars.res', []) : get(collection, 'root.request.vars.res', []);
collectionResponseVars.forEach((_var) => {
if (_var.enabled) {
resVars.set(_var.name, _var.value);
Expand Down Expand Up @@ -113,9 +113,9 @@ const mergeVars = (collection, request, requestTreePath) => {
};

const mergeScripts = (collection, request, requestTreePath, scriptFlow) => {
let collectionPreReqScript = get(collection, 'root.request.script.req', '');
let collectionPostResScript = get(collection, 'root.request.script.res', '');
let collectionTests = get(collection, 'root.request.tests', '');
let collectionPreReqScript = collection.draft ? get(collection, 'draft.request.script.req') : get(collection, 'root.request.script.req', '');
let collectionPostResScript = collection.draft ? get(collection, 'draft.request.script.res') : get(collection, 'root.request.script.res', '');
let collectionTests = collection.draft ? get(collection, 'draft.request.tests', '') : get(collection, 'root.request.tests', '');

let combinedPreReqScript = [];
let combinedPostResScript = [];
Expand All @@ -137,7 +137,7 @@ const mergeScripts = (collection, request, requestTreePath, scriptFlow) => {
combinedTests.push(tests);
}
}
}
}s

request.script.req = compact([collectionPreReqScript, ...combinedPreReqScript, request?.script?.req || '']).join(os.EOL);

Expand Down
34 changes: 32 additions & 2 deletions packages/bruno-electron/src/app/watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ const hydrateRequestWithUuid = (request, pathname) => {
return request;
};

const hydrateBruCollectionFileWithUuid = (collectionRoot) => {
const hydrateBruCollectionFileWithUuid = (collectionRoot, pathname) => {
if(pathname) {
collectionRoot.uid = getRequestUid(pathname);
}
const params = _.get(collectionRoot, 'request.params', []);
const headers = _.get(collectionRoot, 'request.headers', []);
const requestVars = _.get(collectionRoot, 'request.vars.req', []);
Expand Down Expand Up @@ -256,7 +259,7 @@ const add = async (win, pathname, collectionUid, collectionPath) => {

file.data = collectionBruToJson(bruContent);

hydrateBruCollectionFileWithUuid(file.data);
hydrateBruCollectionFileWithUuid(file.data, pathname);
win.webContents.send('main:collection-tree-updated', 'addFile', file);
return;
} catch (err) {
Expand Down Expand Up @@ -367,6 +370,33 @@ const change = async (win, pathname, collectionUid, collectionPath) => {
}
}

if (path.basename(pathname) === 'folder.bru') {
const file = {
meta: {
collectionUid,
pathname,
name: path.basename(pathname),
folderRoot: true
}
};

try {
let bruContent = fs.readFileSync(pathname, 'utf8');
file.data = collectionBruToJson(bruContent);

// Preserve the existing UID
const existingUid = getRequestUid(pathname);
file.data.uid = existingUid;

hydrateBruCollectionFileWithUuid(file.data, pathname);
win.webContents.send('main:collection-tree-updated', 'change', file);
return;
} catch (err) {
console.error('Error handling folder.bru change:', err);
return;
}
}

if (hasBruExtension(pathname)) {
try {
const file = {
Expand Down
12 changes: 6 additions & 6 deletions packages/bruno-electron/src/utils/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const os = require('os');
const mergeHeaders = (collection, request, requestTreePath) => {
let headers = new Map();

let collectionHeaders = get(collection, 'root.request.headers', []);
let collectionHeaders = collection.draft ? get(collection, 'draft.request.headers', []) : get(collection, 'root.request.headers', []);
collectionHeaders.forEach((header) => {
if (header.enabled) {
headers.set(header.name, header.value);
Expand Down Expand Up @@ -37,7 +37,7 @@ const mergeHeaders = (collection, request, requestTreePath) => {

const mergeVars = (collection, request, requestTreePath) => {
let reqVars = new Map();
let collectionRequestVars = get(collection, 'root.request.vars.req', []);
let collectionRequestVars = collection.draft ? get(collection, 'draft.request.vars.req', []) : get(collection, 'root.request.vars.req', []);
let collectionVariables = {};
collectionRequestVars.forEach((_var) => {
if (_var.enabled) {
Expand Down Expand Up @@ -81,7 +81,7 @@ const mergeVars = (collection, request, requestTreePath) => {
}

let resVars = new Map();
let collectionResponseVars = get(collection, 'root.request.vars.res', []);
let collectionResponseVars = collection.draft ? get(collection, 'draft.request.vars.res') : get(collection, 'root.request.vars.res', []);
collectionResponseVars.forEach((_var) => {
if (_var.enabled) {
resVars.set(_var.name, _var.value);
Expand Down Expand Up @@ -116,9 +116,9 @@ const mergeVars = (collection, request, requestTreePath) => {
};

const mergeScripts = (collection, request, requestTreePath, scriptFlow) => {
let collectionPreReqScript = get(collection, 'root.request.script.req', '');
let collectionPostResScript = get(collection, 'root.request.script.res', '');
let collectionTests = get(collection, 'root.request.tests', '');
let collectionPreReqScript = collection.draft ? get(collection, 'draft.request.script.req', '') : get(collection, 'root.request.script.req', '');
let collectionPostResScript = collection.draft ? get(collection, 'draft.request.script.res', '') : get(collection, 'root.request.script.res', '');
let collectionTests = collection.draft ? get(collection, 'draft.request.tests') : get(collection, 'root.request.tests', '');

let combinedPreReqScript = [];
let combinedPostResScript = [];
Expand Down

0 comments on commit ee08fca

Please sign in to comment.