-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
f47772c
saving work, didn't include pagination for the sake of proving someth…
dmarticus 248a183
Merge branch 'master' into fix/cohort-pagination
dmarticus 0e106eb
UGH
dmarticus 3882b9a
this should do it
dmarticus 72f1d97
Update UI snapshots for `chromium` (1)
github-actions[bot] 919fd75
Merge branch 'master' into feat/cohort-pagination
dmarticus 7b1c250
tests and whatnot
dmarticus 861664e
Merge branch 'master' into feat/cohort-pagination
dmarticus 965f748
fix merge
dmarticus 7fbb34b
Merge branch 'master' into feat/cohort-pagination
dmarticus 39346d4
Merge branch 'master' into feat/cohort-pagination
dmarticus 44c7631
Merge branch 'master' into feat/cohort-pagination
dmarticus 0e86baf
Merge branch 'master' into feat/cohort-pagination
dmarticus d4eed59
Merge branch 'master' into feat/cohort-pagination
dmarticus 74d6ba9
Update query snapshots
github-actions[bot] 421b6d4
Merge branch 'master' into feat/cohort-pagination
dmarticus f23b8b0
Update UI snapshots for `chromium` (1)
github-actions[bot] cc3673a
Update UI snapshots for `chromium` (2)
github-actions[bot] 2f3a96e
getting the all users cohort filters working
dmarticus ddc5834
Merge branch 'feat/cohort-pagination' of github.com:PostHog/posthog i…
dmarticus b395c43
Merge branch 'master' into feat/cohort-pagination
dmarticus 3b93bd8
Merge branch 'master' into feat/cohort-pagination
dmarticus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file modified
BIN
-1.23 KB
(99%)
frontend/__snapshots__/replay-player-failure--recent-recordings-404--dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-1.36 KB
(99%)
frontend/__snapshots__/replay-player-failure--recent-recordings-404--light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-1.2 KB
(98%)
frontend/__snapshots__/replay-player-success--recent-recordings--dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-1.3 KB
(98%)
frontend/__snapshots__/replay-player-success--recent-recordings--light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-1.12 KB
(98%)
frontend/__snapshots__/replay-player-success--second-recording-in-list--dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-1.24 KB
(98%)
frontend/__snapshots__/replay-player-success--second-recording-in-list--light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,214 @@ | ||
import { router } from 'kea-router' | ||
import { expectLogic } from 'kea-test-utils' | ||
import api from 'lib/api' | ||
import { urls } from 'scenes/urls' | ||
|
||
import { useMocks } from '~/mocks/jest' | ||
import { initKeaTests } from '~/test/init' | ||
import { CohortType, FilterLogicalOperator } from '~/types' | ||
|
||
import { cohortsModel } from './cohortsModel' | ||
|
||
const MOCK_COHORTS = { | ||
count: 2, | ||
results: [ | ||
{ | ||
id: 1, | ||
name: 'Cohort one', | ||
count: 1, | ||
groups: [], | ||
filters: { | ||
properties: { | ||
type: 'AND', | ||
values: [], | ||
}, | ||
}, | ||
is_calculating: false, | ||
is_static: false, | ||
created_at: '2023-08-01T00:00:00Z', | ||
}, | ||
{ | ||
id: 2, | ||
name: 'Cohort two', | ||
count: 2, | ||
groups: [], | ||
filters: { | ||
properties: { | ||
type: 'AND', | ||
values: [], | ||
}, | ||
}, | ||
is_calculating: true, | ||
is_static: false, | ||
created_at: '2023-08-02T00:00:00Z', | ||
}, | ||
], | ||
} | ||
|
||
describe('cohortsModel', () => { | ||
let logic: ReturnType<typeof cohortsModel.build> | ||
|
||
beforeEach(() => { | ||
useMocks({ | ||
get: { | ||
'/api/projects/:team/cohorts/': MOCK_COHORTS, | ||
}, | ||
delete: { | ||
'/api/projects/:team/cohorts/:id/': { success: true }, | ||
}, | ||
patch: { | ||
'/api/projects/:team/cohorts/:id/': (req) => { | ||
const data = req.body as Record<string, any> | ||
return { ...MOCK_COHORTS.results[0], ...data } | ||
}, | ||
}, | ||
}) | ||
initKeaTests() | ||
logic = cohortsModel() | ||
logic.mount() | ||
}) | ||
|
||
describe('core assumptions', () => { | ||
it('loads cohorts on mount', async () => { | ||
await expectLogic(logic).toDispatchActions(['loadCohorts', 'loadCohortsSuccess']) | ||
expect(logic.values.cohorts.results).toHaveLength(2) | ||
expect(logic.values.cohortsWithAllUsers).toHaveLength(3) // includes "All Users" | ||
}) | ||
|
||
it('sets polling timeout for calculating cohorts when on cohorts page', async () => { | ||
// Set the current location to the cohorts page | ||
router.actions.push(urls.cohorts()) | ||
|
||
await expectLogic(logic).toDispatchActions(['loadCohorts', 'loadCohortsSuccess']) | ||
expect(logic.values.pollTimeout).not.toBeNull() | ||
}) | ||
|
||
it('does not set polling timeout when not on cohorts page', async () => { | ||
// Set the current location to a different page | ||
router.actions.push(urls.dashboards()) | ||
|
||
// Mock API to return cohorts with no calculating ones | ||
useMocks({ | ||
get: { | ||
'/api/projects/:team/cohorts/': { | ||
...MOCK_COHORTS, | ||
results: MOCK_COHORTS.results.map((c) => ({ ...c, is_calculating: false })), | ||
}, | ||
}, | ||
}) | ||
|
||
await expectLogic(logic).toDispatchActions(['loadCohorts', 'loadCohortsSuccess']) | ||
expect(logic.values.pollTimeout).toBeNull() | ||
}) | ||
}) | ||
|
||
describe('cohort filters', () => { | ||
it('can set and update filters', async () => { | ||
// Navigate to cohorts page first | ||
router.actions.push(urls.cohorts()) | ||
|
||
// Wait for initial load | ||
await expectLogic(logic).toDispatchActions(['loadCohortsSuccess']) | ||
|
||
// Test search filter | ||
await expectLogic(logic, () => { | ||
logic.actions.setCohortFilters({ search: 'test' }) | ||
}) | ||
.toDispatchActions(['setCohortFilters', 'loadCohorts', 'loadCohortsSuccess']) | ||
.toMatchValues({ | ||
cohortFilters: expect.objectContaining({ search: 'test' }), | ||
}) | ||
|
||
// Test pagination | ||
await expectLogic(logic, () => { | ||
logic.actions.setCohortFilters({ page: 2 }) | ||
}) | ||
.toDispatchActions(['setCohortFilters', 'loadCohorts', 'loadCohortsSuccess']) | ||
.toMatchValues({ | ||
cohortFilters: expect.objectContaining({ page: 2 }), | ||
}) | ||
}) | ||
}) | ||
|
||
describe('cohort operations', () => { | ||
it('can update a cohort', async () => { | ||
// Wait for initial load | ||
await expectLogic(logic).toDispatchActions(['loadCohortsSuccess']) | ||
|
||
const updatedCohort: CohortType = { | ||
id: 1, | ||
name: 'Updated name', | ||
count: 1, | ||
groups: [], | ||
filters: { | ||
properties: { | ||
type: FilterLogicalOperator.And, | ||
values: [], | ||
}, | ||
}, | ||
is_calculating: false, | ||
is_static: false, | ||
} | ||
|
||
await expectLogic(logic, () => { | ||
logic.actions.updateCohort(updatedCohort) | ||
}).toMatchValues({ | ||
cohorts: expect.objectContaining({ | ||
results: expect.arrayContaining([ | ||
expect.objectContaining({ | ||
id: 1, | ||
name: 'Updated name', | ||
}), | ||
]), | ||
}), | ||
}) | ||
}) | ||
|
||
it('can delete a cohort', async () => { | ||
// Wait for initial load | ||
await expectLogic(logic).toDispatchActions(['loadCohortsSuccess']) | ||
|
||
jest.spyOn(api.cohorts, 'determineDeleteEndpoint').mockImplementation(() => 'cohorts') | ||
|
||
await expectLogic(logic, () => { | ||
logic.actions.deleteCohort({ id: 1 }) | ||
}) | ||
.toDispatchActions(['deleteCohort']) | ||
.toMatchValues({ | ||
cohorts: expect.objectContaining({ | ||
results: expect.not.arrayContaining([ | ||
expect.objectContaining({ | ||
id: 1, | ||
}), | ||
]), | ||
}), | ||
}) | ||
}) | ||
}) | ||
|
||
describe('selectors', () => { | ||
it('correctly calculates pagination values', async () => { | ||
// Wait for initial load | ||
await expectLogic(logic).toDispatchActions(['loadCohortsSuccess']) | ||
|
||
await expectLogic(logic).toMatchValues({ | ||
pagination: expect.objectContaining({ | ||
currentPage: 1, | ||
pageSize: 100, | ||
entryCount: 2, | ||
}), | ||
}) | ||
}) | ||
|
||
it('correctly maps cohorts by id', async () => { | ||
await expectLogic(logic) | ||
.toDispatchActions(['loadCohortsSuccess']) | ||
.toMatchValues({ | ||
cohortsById: expect.objectContaining({ | ||
1: expect.objectContaining({ id: 1, name: 'Cohort one' }), | ||
2: expect.objectContaining({ id: 2, name: 'Cohort two' }), | ||
}), | ||
}) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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