: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(cohorts): stop claiming "showing all" when the list is short of the count (#118232)
posthog[bot]d1a9aa3d1e04
diff --git a/frontend/src/queries/nodes/DataNode/LoadNext.tsx b/frontend/src/queries/nodes/DataNode/LoadNext.tsxindex 567864ea64dc..d4a5004c2e8c 100644--- a/frontend/src/queries/nodes/DataNode/LoadNext.tsx+++ b/frontend/src/queries/nodes/DataNode/LoadNext.tsx@@ -3,6 +3,7 @@ import { useMemo } from 'react'import { TZLabel } from 'lib/components/TZLabel'import { LemonButton } from 'lib/lemon-ui/LemonButton'+import { humanFriendlyNumber } from 'lib/utils/numbers'import { dataNodeLogic } from '~/queries/nodes/DataNode/dataNodeLogic'import { DataNode } from '~/queries/schema/schema-general'@@ -13,9 +14,10 @@ import { DEFAULT_PAGE_SIZE } from '../DataVisualization/Components/Table'interface LoadNextProps {query: DataNodenouns?: [string, string]+ expectedTotalRows?: number}-export function LoadNext({ query, nouns = ['entry', 'entries'] }: LoadNextProps): JSX.Element {+export function LoadNext({ query, nouns = ['entry', 'entries'], expectedTotalRows }: LoadNextProps): JSX.Element {const { canLoadNextData, nextDataLoading, numberOfRows, hasMoreData, dataLimit } = useValues(dataNodeLogic)const { loadNextData } = useActions(dataNodeLogic)@@ -41,17 +43,20 @@ export function LoadNext({ query, nouns = ['entry', 'entries'] }: LoadNextProps)} else if (isHogQLQuery(query) && !canLoadNextData && hasMoreData && dataLimit) {return `Default limit of ${dataLimit} rows reached. Try adding a LIMIT clause to adjust.`}+ if (!canLoadNextData && !hasMoreData && numberOfRows && expectedTotalRows && numberOfRows < expectedTotalRows) {+ return `Showing ${humanFriendlyNumber(numberOfRows)} of ${humanFriendlyNumber(expectedTotalRows)} ${nouns[1]}`+ }const noun = numberOfRows === 1 ? nouns[0] : nouns[1]let result = `Showing ${hasMoreData && (numberOfRows ?? 0) > 1 ? 'first ' : canLoadNextData || numberOfRows === 1 ? '' : 'all '- }${numberOfRows === 1 ? 'one' : numberOfRows} ${noun}`+ }${numberOfRows === 1 ? 'one' : humanFriendlyNumber(numberOfRows)} ${noun}`if (canLoadNextData) {result += nextDataLoading ? ' – loading more…' : ' – click to load more'} else if (hasMoreData) {result += ' – reached the end of results'}return result- }, [query, dataLimit, numberOfRows, canLoadNextData, nextDataLoading, hasMoreData, nouns])+ }, [query, dataLimit, numberOfRows, canLoadNextData, nextDataLoading, hasMoreData, nouns, expectedTotalRows])// pagination component existsif (diff --git a/frontend/src/queries/nodes/DataTable/DataTable.tsx b/frontend/src/queries/nodes/DataTable/DataTable.tsxindex 72787a399e58..e29e0cabc5fc 100644--- a/frontend/src/queries/nodes/DataTable/DataTable.tsx+++ b/frontend/src/queries/nodes/DataTable/DataTable.tsx@@ -1167,7 +1167,11 @@ export function DataTable({(dataTableRows ?? []).length > 0 &&(context?.showLoadNextButton ||!sourceFeatures.has(QueryFeature.hideLoadNextButton)) ? (- <LoadNext query={query.source} nouns={context?.dataTableNouns} />+ <LoadNext+ query={query.source}+ nouns={context?.dataTableNouns}+ expectedTotalRows={context?.dataTableExpectedTotalRows}+ />) : null}nouns={context?.dataTableNouns}diff --git a/frontend/src/queries/types.ts b/frontend/src/queries/types.tsindex d17a1547b09e..22098023ac8c 100644--- a/frontend/src/queries/types.ts+++ b/frontend/src/queries/types.ts@@ -77,6 +77,8 @@ export interface QueryContext<Q extends QuerySchema = QuerySchema> {dataTableStickyHeader?: boolean/** Override the nouns used by Data Table counts and pagination. */dataTableNouns?: [string, string]+ /** Expected total row count from another source. The footer shows "X of Y" when all rows are loaded and the counts differ. */+ dataTableExpectedTotalRows?: numbercompactDataTableToolbar?: booleanhideRecordingButton?: boolean/** Custom expandable config for DataTable rows */diff --git a/frontend/src/scenes/cohorts/CohortEdit.test.tsx b/frontend/src/scenes/cohorts/CohortEdit.test.tsxindex 0848e9463fd1..e38d305765f2 100644--- a/frontend/src/scenes/cohorts/CohortEdit.test.tsx+++ b/frontend/src/scenes/cohorts/CohortEdit.test.tsx@@ -653,6 +653,46 @@ describe('cohortEditLogic', () => {})})+ describe('persons list footer', () => {+ afterEach(() => {+ cleanup()+ })++ it.each([+ { count: 2455, expectedFooter: 'Showing 2 of 2,455 entries' },+ { count: 2, expectedFooter: 'Showing all 2 entries' },+ { count: 1, expectedFooter: 'Showing all 2 entries' },+ ])('shows "$expectedFooter" when the cohort count is $count', async ({ count, expectedFooter }) => {+ const cohortId = 7+ useMocks({+ get: {+ [`/api/projects/:team_id/cohorts/${cohortId}/`]: {+ ...mockCohort,+ id: cohortId,+ is_static: false,+ is_calculating: false,+ count,+ version: 1,+ pending_version: 1,+ last_calculation: '2024-01-01T00:00:00Z',+ },+ },+ post: {+ '/api/environments/:team_id/query/:query_kind/': {+ columns: ['id'],+ types: ['UUID'],+ results: [['person-a'], ['person-b']],+ hasMore: false,+ },+ },+ })++ render(<CohortEdit id={cohortId} />)++ expect(await screen.findByText(expectedFooter)).toBeInTheDocument()+ })+ })+describe('used-in summary', () => {afterEach(() => {cleanup()diff --git a/frontend/src/scenes/cohorts/CohortEdit.tsx b/frontend/src/scenes/cohorts/CohortEdit.tsxindex ce6fa4355e04..2833efd6360f 100644--- a/frontend/src/scenes/cohorts/CohortEdit.tsx+++ b/frontend/src/scenes/cohorts/CohortEdit.tsx@@ -904,6 +904,9 @@ export function CohortEdit({ id, attachTo }: CohortEditProps): JSX.Element {disabledReason={broadcastDisabledReason}/>),+ dataTableExpectedTotalRows: shouldShowCountWarning+ ? (cohort.count ?? undefined)+ : undefined,columns: canRemovePersonFromCohort? {'person.$delete': {