diff --git a/packages/bruno-app/src/components/RunnerResults/RunConfigurationPanel/index.jsx b/packages/bruno-app/src/components/RunnerResults/RunConfigurationPanel/index.jsx index 4ccbb1278..436fb2e17 100644 --- a/packages/bruno-app/src/components/RunnerResults/RunConfigurationPanel/index.jsx +++ b/packages/bruno-app/src/components/RunnerResults/RunConfigurationPanel/index.jsx @@ -5,7 +5,8 @@ import { IconGripVertical, IconCheck } from '@tabler/icons'; import { useDispatch } from 'react-redux'; import { updateRunnerConfiguration } from 'providers/ReduxStore/slices/collections/actions'; import StyledWrapper from './StyledWrapper'; -import { isItemARequest } from 'utils/collections'; +import { isItemARequest, isItemAFolder } from 'utils/collections'; +import { sortByNameThenSequence } from 'utils/common/index'; import path from 'utils/common/path'; import { cloneDeep, get } from 'lodash'; import Button from 'ui/Button/index'; @@ -187,20 +188,25 @@ const RunConfigurationPanel = ({ collection, selectedItems, setSelectedItems, ta const processItems = (items) => { if (!items?.length) return; - items.forEach((item) => { - if (isItemARequest(item) && !item.partial && !item.isTransient) { - const relativePath = path.relative(collection.pathname, path.dirname(item.pathname)); - const folderPath = relativePath !== '.' ? relativePath : ''; + const folderItems = sortByNameThenSequence(items.filter((item) => isItemAFolder(item) && !item.isTransient)); + const requestItems = items + .filter((item) => isItemARequest(item) && !item.partial && !item.isTransient) + .sort((a, b) => a.seq - b.seq); - result.push({ - ...item, - folderPath: folderPath.replace(/\\/g, '/') - }); + folderItems.forEach((folder) => { + if (folder.items?.length) { + processItems(folder.items); } + }); - if (item.items?.length) { - processItems(item.items); - } + requestItems.forEach((item) => { + const relativePath = path.relative(collection.pathname, path.dirname(item.pathname)); + const folderPath = relativePath !== '.' ? relativePath : ''; + + result.push({ + ...item, + folderPath: folderPath.replace(/\\/g, '/') + }); }); }; diff --git a/packages/bruno-app/src/components/RunnerResults/index.jsx b/packages/bruno-app/src/components/RunnerResults/index.jsx index 6db4500c7..03cff6458 100644 --- a/packages/bruno-app/src/components/RunnerResults/index.jsx +++ b/packages/bruno-app/src/components/RunnerResults/index.jsx @@ -81,6 +81,7 @@ export default function RunnerResults({ collection }) { const [delay, setDelay] = useState(null); const [activeFilter, setActiveFilter] = useState('all'); const [selectedRequestItems, setSelectedRequestItems] = useState([]); + const isReRunningRef = useRef(false); // ref for the runner output body const runnerBodyRef = useRef(); @@ -165,6 +166,13 @@ export default function RunnerResults({ collection }) { } }, [collection.runnerConfiguration, delay]); + useEffect(() => { + if (isReRunningRef.current + && (items?.length > 0 || runnerInfo?.status === 'ended' || runnerInfo?.status === 'cancelled')) { + isReRunningRef.current = false; + } + }, [items, runnerInfo?.status]); + const ensureCollectionIsMounted = () => { if (collection.mountStatus === 'mounted') { return; @@ -184,6 +192,7 @@ export default function RunnerResults({ collection }) { const runAgain = () => { ensureCollectionIsMounted(); + isReRunningRef.current = true; // Get the saved configuration to determine what to run const savedConfiguration = get(collection, 'runnerConfiguration', null); const savedSelectedItems = savedConfiguration?.selectedRequestItems || []; @@ -201,6 +210,7 @@ export default function RunnerResults({ collection }) { }; const resetRunner = () => { + isReRunningRef.current = false; dispatch( resetCollectionRunner({ collectionUid: collection.uid @@ -222,7 +232,7 @@ export default function RunnerResults({ collection }) { }; let isCollectionLoading = areItemsLoading(collection); - if (!items || !items.length) { + if ((!items || !items.length) && !isReRunningRef.current) { return (