-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(cohorts): enable cohort pagination #27422
base: master
Are you sure you want to change the base?
Changes from 5 commits
f47772c
248a183
0e106eb
3882b9a
72f1d97
919fd75
7b1c250
861664e
965f748
7fbb34b
39346d4
44c7631
0e86baf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,10 +21,10 @@ import { CohortType, ProductKey } from '~/types' | |
import { cohortsModel } from '../../models/cohortsModel' | ||
|
||
export function Cohorts(): JSX.Element { | ||
const { cohorts, cohortsSearch, cohortsLoading } = useValues(cohortsModel) | ||
const { deleteCohort, exportCohortPersons } = useActions(cohortsModel) | ||
const { cohorts, cohortsLoading, pagination, cohortFilters } = useValues(cohortsModel) | ||
const { deleteCohort, exportCohortPersons, setCohortFilters } = useActions(cohortsModel) | ||
const { searchParams } = useValues(router) | ||
const [searchTerm, setSearchTerm] = useState<string>('') | ||
const [searchTerm, setSearchTerm] = useState(cohortFilters.search || '') | ||
|
||
const columns: LemonTableColumns<CohortType> = [ | ||
{ | ||
|
@@ -142,7 +142,7 @@ export function Cohorts(): JSX.Element { | |
productKey={ProductKey.COHORTS} | ||
thingName="cohort" | ||
description="Use cohorts to group people together, such as users who used your app in the last week, or people who viewed the signup page but didn’t convert." | ||
isEmpty={cohorts?.length == 0 && !cohortsLoading} | ||
isEmpty={cohorts.count == 0 && !cohortsLoading && !searchTerm} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't want to show the "create new cohort" option if the cohort list has filters applied |
||
docsURL="https://posthog.com/docs/data/cohorts" | ||
action={() => router.actions.push(urls.cohort('new'))} | ||
customHog={ListHog} | ||
|
@@ -152,16 +152,19 @@ export function Cohorts(): JSX.Element { | |
<LemonInput | ||
type="search" | ||
placeholder="Search for cohorts" | ||
onChange={setSearchTerm} | ||
onChange={(search) => { | ||
setSearchTerm(search) | ||
setCohortFilters({ search: search || undefined, page: 1 }) | ||
}} | ||
value={searchTerm} | ||
/> | ||
</div> | ||
<LemonTable | ||
columns={columns} | ||
loading={cohortsLoading} | ||
rowKey="id" | ||
pagination={{ pageSize: 100 }} | ||
dataSource={searchTerm ? cohortsSearch(searchTerm) : cohorts ?? []} | ||
pagination={pagination} | ||
dataSource={cohorts.results} | ||
Comment on lines
+166
to
+167
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the pagination and data are now controlled exclusively by the logic, and not some mix of react state management and the logic. And now pagination actually works (it didn't beforehand 😓 ) |
||
nouns={['cohort', 'cohorts']} | ||
data-attr="cohorts-table" | ||
/> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we used to cap the limit at 600, which was causing a problem with returning the cohort name here: https://posthog.slack.com/archives/C07Q2U4BH4L/p1734442912694879