Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(subscriptions): count selectable insights, not the cap (#100976)

Matt Puaeaea4074960f
diff --git a/products/subscriptions/frontend/components/Subscriptions/InsightSelector.test.tsx b/products/subscriptions/frontend/components/Subscriptions/InsightSelector.test.tsx
index 2e285fcb73cf..32869db2eba8 100644
--- a/products/subscriptions/frontend/components/Subscriptions/InsightSelector.test.tsx
+++ b/products/subscriptions/frontend/components/Subscriptions/InsightSelector.test.tsx
@@ -57,14 +57,23 @@ describe('InsightSelector', () => {
expect(checkboxes[2]).not.toBeChecked() // Users (103)
})
- it('shows selection count', () => {
+ it.each([
+ ['fewer insights than the limit', 3, '2 of 3 insights selected'],
+ ['more insights than the limit', MAX_INSIGHTS + 1, `2 of ${MAX_INSIGHTS} insights selected`],
+ ])('shows selection count with %s', (_name, tileCount, expected) => {
+ const tiles = Array.from({ length: tileCount as number }, (_, i) => ({
+ id: i + 1,
+ insight: { id: 101 + i, name: `Insight ${i}` } as any,
+ layouts: { sm: { x: 0, y: i } } as any,
+ }))
+
renderInsightSelector({
- tiles: createMockTiles() as DashboardTile[],
+ tiles: tiles as DashboardTile[],
selectedInsightIds: [101, 102],
onChange: jest.fn(),
})
- expect(screen.getByText(`2 of ${MAX_INSIGHTS} insights selected`)).toBeInTheDocument()
+ expect(screen.getByText(expected as string)).toBeInTheDocument()
})
it('calls onChange when selecting an insight', async () => {
diff --git a/products/subscriptions/frontend/components/Subscriptions/InsightSelector.tsx b/products/subscriptions/frontend/components/Subscriptions/InsightSelector.tsx
index 727a9ef389f1..ed0083ae2444 100644
--- a/products/subscriptions/frontend/components/Subscriptions/InsightSelector.tsx
+++ b/products/subscriptions/frontend/components/Subscriptions/InsightSelector.tsx
@@ -54,6 +54,7 @@ export function InsightSelector({
}
const selectedCount = validSelectedIds.length
+ const selectableCount = Math.min(insightTiles.length, MAX_INSIGHTS)
const atMaxLimit = selectedCount >= MAX_INSIGHTS
const toggleInsight = (insightId: number): void => {
@@ -70,7 +71,7 @@ export function InsightSelector({
<div className="border rounded p-2 space-y-2">
<div className="flex justify-between items-center text-sm">
<span className="font-medium">
- {selectedCount} of {MAX_INSIGHTS} insights selected
+ {selectedCount} of {selectableCount} insights selected
</span>
{selectedCount === 0 && <span className="text-danger">Select at least one insight</span>}
</div>