mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-15 11:51:30 +00:00
Merge pull request #5111 from lohxt1/folder_sequencing_fixes_cli
This commit is contained in:
@@ -242,7 +242,7 @@ export const sortByNameThenSequence = items => {
|
||||
|
||||
// Check if there's already an item with the same sequence number
|
||||
const hasItemWithSameSeq = Array.isArray(existingItem)
|
||||
? existingItem[0].seq === item.seq
|
||||
? existingItem?.[0]?.seq === item.seq
|
||||
: existingItem?.seq === item.seq;
|
||||
|
||||
if (hasItemWithSameSeq) {
|
||||
|
||||
@@ -55,7 +55,7 @@ const createCollectionJsonFromPathname = (collectionPath) => {
|
||||
}
|
||||
}
|
||||
let currentDirFolderItems = currentDirItems?.filter((iter) => iter.type === 'folder');
|
||||
let sortedFolderItems = currentDirFolderItems?.sort((a, b) => a.seq - b.seq);
|
||||
let sortedFolderItems = sortByNameThenSequence(currentDirFolderItems);
|
||||
|
||||
let currentDirRequestItems = currentDirItems?.filter((iter) => iter.type !== 'folder');
|
||||
let sortedRequestItems = currentDirRequestItems?.sort((a, b) => a.seq - b.seq);
|
||||
@@ -512,6 +512,48 @@ const processCollectionItems = async (items = [], currentPath) => {
|
||||
}
|
||||
};
|
||||
|
||||
const sortByNameThenSequence = items => {
|
||||
const isSeqValid = seq => Number.isFinite(seq) && Number.isInteger(seq) && seq > 0;
|
||||
|
||||
// Sort folders alphabetically by name
|
||||
const alphabeticallySorted = [...items].sort((a, b) => a.name && b.name && a.name.localeCompare(b.name));
|
||||
|
||||
// Extract folders without 'seq'
|
||||
const withoutSeq = alphabeticallySorted.filter(f => !isSeqValid(f['seq']));
|
||||
|
||||
// Extract folders with 'seq' and sort them by 'seq'
|
||||
const withSeq = alphabeticallySorted.filter(f => isSeqValid(f['seq'])).sort((a, b) => a.seq - b.seq);
|
||||
|
||||
const sortedItems = withoutSeq;
|
||||
|
||||
// Insert folders with 'seq' at their specified positions
|
||||
withSeq.forEach((item) => {
|
||||
const position = item.seq - 1;
|
||||
const existingItem = withoutSeq[position];
|
||||
|
||||
// Check if there's already an item with the same sequence number
|
||||
const hasItemWithSameSeq = Array.isArray(existingItem)
|
||||
? existingItem?.[0]?.seq === item.seq
|
||||
: existingItem?.seq === item.seq;
|
||||
|
||||
if (hasItemWithSameSeq) {
|
||||
// If there's a conflict, group items with same sequence together
|
||||
const newGroup = Array.isArray(existingItem)
|
||||
? [...existingItem, item]
|
||||
: [existingItem, item];
|
||||
|
||||
withoutSeq.splice(position, 1, newGroup);
|
||||
} else {
|
||||
// Insert item at the specified position
|
||||
withoutSeq.splice(position, 0, item);
|
||||
}
|
||||
});
|
||||
|
||||
// return flattened sortedItems
|
||||
return sortedItems.flat();
|
||||
};
|
||||
|
||||
|
||||
module.exports = {
|
||||
createCollectionJsonFromPathname,
|
||||
mergeHeaders,
|
||||
|
||||
@@ -489,7 +489,7 @@ const sortByNameThenSequence = items => {
|
||||
|
||||
// Check if there's already an item with the same sequence number
|
||||
const hasItemWithSameSeq = Array.isArray(existingItem)
|
||||
? existingItem[0].seq === item.seq
|
||||
? existingItem?.[0]?.seq === item.seq
|
||||
: existingItem?.seq === item.seq;
|
||||
|
||||
if (hasItemWithSameSeq) {
|
||||
|
||||
Reference in New Issue
Block a user