Skip to content

Commit 721d0e1

Browse files
Improved Request Count Calculation and UI Handling in RunCollectionItem (usebruno#2959)
* Fix | properl calculates the request number for folder run * Chore|formatted document --------- Co-authored-by: Anusree Subash <[email protected]>
1 parent f31c997 commit 721d0e1

File tree

1 file changed

+41
-31
lines changed
  • packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/RunCollectionItem

1 file changed

+41
-31
lines changed

Diff for: packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/RunCollectionItem/index.js

+41-31
Original file line numberDiff line numberDiff line change
@@ -23,43 +23,53 @@ const RunCollectionItem = ({ collection, item, onClose }) => {
2323
onClose();
2424
};
2525

26-
const runLength = item ? get(item, 'items.length', 0) : get(collection, 'items.length', 0);
27-
const items = flattenItems(item ? item.items : collection.items);
28-
const requestItems = items.filter((item) => item.type !== 'folder');
29-
const recursiveRunLength = requestItems.length;
26+
const getRequestsCount = (items) => {
27+
const requestTypes = ['http-request', 'graphql-request']
28+
return items.filter(req => requestTypes.includes(req.type)).length;
29+
}
30+
31+
const runLength = item ? getRequestsCount(item.items) : get(collection, 'items.length', 0);
32+
const flattenedItems = flattenItems(item ? item.items : collection.items);
33+
const recursiveRunLength = getRequestsCount(flattenedItems);
3034

3135
return (
3236
<StyledWrapper>
3337
<Modal size="md" title="Collection Runner" hideFooter={true} handleCancel={onClose}>
34-
<div className="mb-1">
35-
<span className="font-medium">Run</span>
36-
<span className="ml-1 text-xs">({runLength} requests)</span>
37-
</div>
38-
<div className="mb-8">This will only run the requests in this folder.</div>
38+
{!runLength && !recursiveRunLength ? (
39+
<div className="mb-8">No request found in this folder.</div>
40+
) : (
41+
<div>
42+
<div className="mb-1">
43+
<span className="font-medium">Run</span>
44+
<span className="ml-1 text-xs">({runLength} requests)</span>
45+
</div>
46+
<div className="mb-8">This will only run the requests in this folder.</div>
3947

40-
<div className="mb-1">
41-
<span className="font-medium">Recursive Run</span>
42-
<span className="ml-1 text-xs">({recursiveRunLength} requests)</span>
43-
</div>
44-
<div className="mb-8">This will run all the requests in this folder and all its subfolders.</div>
48+
<div className="mb-1">
49+
<span className="font-medium">Recursive Run</span>
50+
<span className="ml-1 text-xs">({recursiveRunLength} requests)</span>
51+
</div>
52+
<div className="mb-8">This will run all the requests in this folder and all its subfolders.</div>
4553

46-
<div className="flex justify-end bruno-modal-footer">
47-
<span className="mr-3">
48-
<button type="button" onClick={onClose} className="btn btn-md btn-close">
49-
Cancel
50-
</button>
51-
</span>
52-
<span>
53-
<button type="submit" className="submit btn btn-md btn-secondary mr-3" onClick={() => onSubmit(true)}>
54-
Recursive Run
55-
</button>
56-
</span>
57-
<span>
58-
<button type="submit" className="submit btn btn-md btn-secondary" onClick={() => onSubmit(false)}>
59-
Run
60-
</button>
61-
</span>
62-
</div>
54+
<div className="flex justify-end bruno-modal-footer">
55+
<span className="mr-3">
56+
<button type="button" onClick={onClose} className="btn btn-md btn-close">
57+
Cancel
58+
</button>
59+
</span>
60+
<span>
61+
<button type="submit" disabled={!recursiveRunLength} className="submit btn btn-md btn-secondary mr-3" onClick={() => onSubmit(true)}>
62+
Recursive Run
63+
</button>
64+
</span>
65+
<span>
66+
<button type="submit" disabled={!runLength} className="submit btn btn-md btn-secondary" onClick={() => onSubmit(false)}>
67+
Run
68+
</button>
69+
</span>
70+
</div>
71+
</div>
72+
)}
6373
</Modal>
6474
</StyledWrapper>
6575
);

0 commit comments

Comments
 (0)