Refactor countRequests function to use getTotalRequestCountInCollection in CollectionSettings/Info/index.js (#2140)

This commit is contained in:
Sanjai Kumar 2024-06-21 10:46:51 +05:30 committed by GitHub
parent b031e1f009
commit 963b197afc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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>
@ -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>