1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-09-24 17:51:14 +02:00

fix: quick project filters total calculation

This commit is contained in:
Tymoteusz Czech 2025-09-11 15:56:22 +02:00
parent 4b42435590
commit 1fdc73548d
No known key found for this signature in database
GPG Key ID: 133555230D88D75F
2 changed files with 9 additions and 3 deletions

View File

@ -66,6 +66,10 @@ export const LifecycleFilters = ({
countData, countData,
}: ILifecycleFiltersBaseProps) => { }: ILifecycleFiltersBaseProps) => {
const current = state.lifecycle?.values ?? []; const current = state.lifecycle?.values ?? [];
const allFlagsCount = Object.entries(countData ?? {}).reduce(
(acc, [key, count]) => (key !== 'archived' ? acc + count : acc),
0,
);
return ( return (
<Wrapper> <Wrapper>
@ -75,7 +79,9 @@ export const LifecycleFilters = ({
value === null value === null
? !state.lifecycle ? !state.lifecycle
: current.includes(value); : current.includes(value);
const count = value ? countData?.[value] : total; const count = value
? countData?.[value]
: allFlagsCount || undefined;
const dynamicLabel = const dynamicLabel =
isActive && Number.isInteger(total) isActive && Number.isInteger(total)
? `${label} (${total === count ? total : `${total} of ${count}`})` ? `${label} (${total === count ? total : `${total} of ${count}`})`

View File

@ -47,7 +47,7 @@ describe('LifecycleFilters', () => {
<FeaturesOverviewLifecycleFilters state={{}} onChange={vi.fn()} />, <FeaturesOverviewLifecycleFilters state={{}} onChange={vi.fn()} />,
); );
expect(getByText('All flags')).toBeInTheDocument(); expect(getByText('All flags (10)')).toBeInTheDocument();
expect(getByText('Develop (2)')).toBeInTheDocument(); expect(getByText('Develop (2)')).toBeInTheDocument();
expect(getByText('Rollout production (3)')).toBeInTheDocument(); expect(getByText('Rollout production (3)')).toBeInTheDocument();
expect(getByText('Cleanup (4)')).toBeInTheDocument(); expect(getByText('Cleanup (4)')).toBeInTheDocument();
@ -98,7 +98,7 @@ describe('LifecycleFilters', () => {
lifecycle: { operator: 'IS', values: ['completed'] }, lifecycle: { operator: 'IS', values: ['completed'] },
}); });
await userEvent.click(getByText('All flags')); await userEvent.click(getByText('All flags (10)'));
expect(onChange).toHaveBeenCalledWith({ lifecycle: null }); expect(onChange).toHaveBeenCalledWith({ lifecycle: null });
}); });
}); });