Skip to content
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

Static cohort on person modal #2952

Merged
merged 72 commits into from
Feb 24, 2021
Merged

Static cohort on person modal #2952

merged 72 commits into from
Feb 24, 2021

Conversation

EDsCODE
Copy link
Member

@EDsCODE EDsCODE commented Jan 14, 2021

Changes

Please describe.

  • support for trends and stickiness to be able to click create cohort when viewing people
  • will submit a worker job to async calculate the cohort so that large cohorts to hamper response time
  • Will create a static cohort extending logic in upload-static-cohort-csv
  • behind ff 'save-cohort-on-modal'

If this affects the frontend, include screenshots.

Checklist

  • Clickhouse support
  • Django backend tests
  • frontend naming the cohort
  • closing modal and creating another datapoint cohort without refreshing

<Button type="primary" onClick={() => saveCohortWithFilters()}>
{'Save cohort'}
</Button>
</div>
{user?.is_multi_tenancy && featureFlags['filter_by_session_props'] ? (
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@macobo put the button here temporarily. i think it should be clear from conflicts

@timgl timgl temporarily deployed to posthog-static-cohort-o-z5juam January 14, 2021 21:21 Inactive
@EDsCODE EDsCODE temporarily deployed to posthog-static-cohort-o-z5juam January 14, 2021 21:52 Inactive
Base automatically changed from upload-static-cohort-csv to master January 15, 2021 10:19
@EDsCODE EDsCODE temporarily deployed to posthog-static-cohort-o-z5juam January 15, 2021 14:27 Inactive
@EDsCODE EDsCODE requested a review from timgl February 16, 2021 19:04
Copy link
Contributor

@macobo macobo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some initial comments but I'm still unsure about the general logic, but might be best to chat about this IRL.

ee/clickhouse/queries/clickhouse_stickiness.py Outdated Show resolved Hide resolved
ee/clickhouse/views/cohort.py Show resolved Hide resolved
frontend/src/loadPostHogJS.tsx Show resolved Hide resolved
frontend/src/models/cohortsModel.ts Outdated Show resolved Hide resolved
ee/kafka_client/topics.py Outdated Show resolved Hide resolved
is_static: true,
name: cohortName,
}
cohortLogic({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels slightly sketchy.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup. I originally had this in the connect handler, but I think kea typegen doesn't handle logics that are initialized with props in connect yet so it was erroring unless I did this. Need to QA to make sure the logics work as expected here

frontend/src/scenes/insights/PersonModal.js Outdated Show resolved Hide resolved
frontend/src/scenes/insights/PersonModal.js Outdated Show resolved Hide resolved
@EDsCODE
Copy link
Member Author

EDsCODE commented Feb 18, 2021

Button could have better placement

Found {people.count === 99 ? '99+' : people.count} {people.count === 1 ? 'user' : 'users'}
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'flex-start' }}>
Found {people.count === 99 ? '99+' : people.count} {people.count === 1 ? 'user' : 'users'}
{(view === ViewType.TRENDS || view === ViewType.STICKINESS) && (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WDYT about putting this behind a feature flag?

Advantage: We can turn it off more easily if/as we discover bugs
Disadvantage: More management work, won't work well with self-hosted.

Copy link
Contributor

@macobo macobo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't have a chance to test this out - deploy wasn't working? Left some comments, we're not far from merging.

frontend/src/scenes/insights/Insights.js Outdated Show resolved Hide resolved
@@ -328,9 +328,42 @@ function _Insights() {
)
}

function TrendInsight({ view }) {
const { filters: _filters, loading, showingPeople } = useValues(trendsLogic({ dashboardItemId: null, view }))
function SaveCohortModal({ onOk, onCancel, visible }) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-actionable: This is causing some duplication while at the same time missing e.g. validation for cohort name length - might cause pain down the line. I don't think worth abstracting out though, given the "extra" bits in the main modal.

frontend/src/scenes/insights/Insights.js Outdated Show resolved Hide resolved
from posthog.tasks.calculate_cohort import insert_cohort_from_query


class ClickhouseCohortSerializer(CohortSerializer):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is missing tests it seems.

Perhaps we can generalize the posthog.api.test.test_cohort and reuse it here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you mean the base serializer is missing tests or the clickhousecohortserializer? There's no logic to test in the clickhouseserializer functions as they're essentially just overrides to the base function call

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant the whole view as a whole - we have tests for /api/cohort for postgres but not for this I think?

Copy link
Member Author

@EDsCODE EDsCODE Feb 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah i see the confusion. So the tests in posthog/api/cohort only have top level testing where they just make sure the celery task is eventually called. Adding this to the ee flow would be redundant as these tests are not testing any specific logic from EE.

The actual ee logic is tested but in different places which makes this slightly confusing. For example, ee/clickhouse/models/test/test_cohort has a test for the insert_users_by_list function and then ee/tasks/test/test_calculate_cohort contains the tests for the newly added functionality in this PR

ee/clickhouse/views/cohort.py Outdated Show resolved Hide resolved
insert_cohort_from_query.delay(cohort.pk, INSIGHT_STICKINESS, filter.to_dict())

def _handle_trend_people(self, cohort: Cohort, filter: Filter) -> None:
if len(filter.entities) >= 1:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I need a bit of context for this, code is unclear.

Which entities are we sending over here? Only the one relevant for the modal? If so, there should only ever be exactly one entity right?

If all, then choosing the first seems incorrect and not sure when the else case can happen.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in #3428 could also use a frontend test but I think we should merge the fix first so this PR isn't stuck. I have a log of component tests that I will write separately

ee/clickhouse/views/actions.py Show resolved Hide resolved
ee/clickhouse/views/actions.py Show resolved Hide resolved
@EDsCODE EDsCODE mentioned this pull request Feb 22, 2021
6 tasks
Copy link
Contributor

@macobo macobo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Things are looking good, we should get this in. There's a test failure though.

Perhaps worth putting the new frontend code behind a feature flag though?

@EDsCODE
Copy link
Member Author

EDsCODE commented Feb 23, 2021

feature flag added! test fixed! #3428 should be merged first

@EDsCODE EDsCODE merged commit 9514e29 into master Feb 24, 2021
@EDsCODE EDsCODE deleted the static-cohort-on-person-modal branch February 24, 2021 14:59
@EDsCODE EDsCODE mentioned this pull request Mar 3, 2021
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants