Skip to content

Commit

Permalink
Refactor countRequests function to use getTotalRequestCountInCollecti…
Browse files Browse the repository at this point in the history
…on in CollectionSettings/Info/index.js (#2140)
  • Loading branch information
sanjai0py authored Jun 21, 2024
1 parent b031e1f commit 963b197
Showing 1 changed file with 4 additions and 20 deletions.
24 changes: 4 additions & 20 deletions packages/bruno-app/src/components/CollectionSettings/Info/index.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,10 @@
import React from 'react';
import StyledWrapper from './StyledWrapper';

function countRequests(items) {
let count = 0;

function recurse(item) {
if (item && typeof item === 'object') {
if (item.type !== 'folder') {
count++;
}
if (Array.isArray(item.items)) {
item.items.forEach(recurse);
}
}
}

items.forEach(recurse);

return count;
}
import { getTotalRequestCountInCollection } from 'utils/collections/';

const Info = ({ collection }) => {
const totalRequestsInCollection = getTotalRequestCountInCollection(collection);

return (
<StyledWrapper className="w-full flex flex-col h-full">
<div className="text-xs mb-4 text-muted">General information about the collection.</div>
Expand All @@ -44,7 +28,7 @@ const Info = ({ collection }) => {
</tr>
<tr className="">
<td className="py-2 px-2 text-right">Requests&nbsp;:</td>
<td className="py-2 px-2">{countRequests(collection.items)}</td>
<td className="py-2 px-2">{totalRequestsInCollection}</td>
</tr>
</tbody>
</table>
Expand Down

0 comments on commit 963b197

Please sign in to comment.