Skip to content
This repository has been archived by the owner on Jun 19, 2024. It is now read-only.

Commit

Permalink
feat: display total and filtered chain counts in chain list (#2659)
Browse files Browse the repository at this point in the history
<!-- start pr-codex -->

## PR-Codex overview
The focus of this PR is to improve chain filtering and display in the dashboard.

### Detailed summary
- Refactored `getChainsToRender` to return more data
- Updated data display to show total, filtered, and displayed chains
- Improved pagination logic to consider filtered chains

> ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}`

<!-- end pr-codex -->
  • Loading branch information
jnsdls committed Jun 14, 2024
1 parent e251dac commit 9656c9c
Showing 1 changed file with 37 additions and 7 deletions.
44 changes: 37 additions & 7 deletions src/app/(dashboard)/(chain)/chainlist/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ async function getChainsToRender(params: SearchParams) {
filteredChains.push(chain);
}

const totalCount = chains.length;
const filteredCount = filteredChains.length;

if (params.query) {
const fuse = new Fuse(filteredChains, {
keys: [
Expand All @@ -121,13 +124,21 @@ async function getChainsToRender(params: SearchParams) {
],
threshold: 0.2,
});
return fuse
.search(params.query, {
limit: DEFAULT_PAGE_SIZE,
})
.map((e) => e.item);
return {
chainsToRender: fuse
.search(params.query, {
limit: DEFAULT_PAGE_SIZE,
})
.map((e) => e.item),
totalCount,
filteredCount,
};
}
return filteredChains;
return {
chainsToRender: filteredChains,
totalCount,
filteredCount,
};
}

export const metadata: Metadata = {
Expand Down Expand Up @@ -188,7 +199,9 @@ async function ChainsData(props: {
searchParams: SearchParams;
activeView: "table" | "grid";
}) {
const chainsToRender = await getChainsToRender(props.searchParams);
const { chainsToRender, totalCount, filteredCount } = await getChainsToRender(
props.searchParams,
);

// pagination
const totalPages = Math.ceil(chainsToRender.length / DEFAULT_PAGE_SIZE);
Expand Down Expand Up @@ -277,6 +290,23 @@ async function ChainsData(props: {
{totalPages > 1 && (
<ChainlistPagination totalPages={totalPages} activePage={activePage} />
)}
<div className="h-4" />
<p className="text-sm text-center text-secondary-foreground text-balance">
Showing{" "}
<span className="text-accent-foreground">{paginatedChains.length}</span>{" "}
out of{" "}
{filteredCount !== totalCount ? (
<>
<span className="text-accent-foreground">{filteredCount}</span>{" "}
chains that match filters. (Total:{" "}
<span className="text-accent-foreground">{totalCount}</span>)
</>
) : (
<>
<span className="text-accent-foreground">{totalCount}</span> chains.
</>
)}
</p>
</>
);
}
Expand Down

0 comments on commit 9656c9c

Please sign in to comment.