Skip to content

Commit

Permalink
fix(ui): Fix statistics card's layout
Browse files Browse the repository at this point in the history
When the total number of items is 0, the card layout alignment is wrong
compared to cards which show the item distribution bar. Fix this by
testing whether at least one of item counts is greater than zero, and
if not, reserve an invisible space for the item distribution bar. This
aligns all statistics cards.

Signed-off-by: Jyrki Keisala <jyrki.keisala@doubleopen.org>
  • Loading branch information
Etsija committed Dec 23, 2024
1 parent 63b1d1b commit 88373a0
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ui/src/components/statistics-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const StatisticsCard = ({
</CardHeader>
<CardContent className='text-sm'>
<div className='flex flex-col'>
{counts.length > 0 && (
{counts.length > 0 && counts.some(({ count }) => count > 0) ? (
<div className='relative mb-2 h-3 w-full overflow-hidden rounded-sm bg-gray-100'>
{percentages.map(({ key, count, color, percentage }, index) => {
const left = percentages
Expand All @@ -95,6 +95,8 @@ export const StatisticsCard = ({
);
})}
</div>
) : (
<div className='relative mb-2 h-3 w-full overflow-hidden rounded-sm' />
)}
<div className='text-2xl font-bold'>
{value !== undefined ? value : 'Failed'}
Expand Down

0 comments on commit 88373a0

Please sign in to comment.