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

feat(prop-defs): add hidden option to property definitions #29085

Open
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

raquelmsmith
Copy link
Member

@raquelmsmith raquelmsmith commented Feb 21, 2025

Problem

PostHog ingests a lot of properties, and sometimes it can be confusing for posthog users of certain orgs to know which properties they should be using. For example, do they use the "Country" person property, or the "Latest country" person property? They might not even realize that "Latest country" is an option if they just scroll and see "Country" - even if that is the preferred prop that their org wants them to use.

We have a way to mark properties as "Verified" - ie someone at the org says "this is a good one, use it." But we have no way of saying "this is not a good one, don't use it."

Changes

Adds a "hidden" field to the property definition model. Allows someone to select between Verified / Visible / Hidden for any property - except "core" PostHog properties can't be "Verified" (why? because that's how it originally was so I didn't change it 🤷‍♀️ - they can still be hidden though)

NB: I decided to just add a new field for "hidden" and deal with the conflict of that vs verified in the business logic (eg we don't want to end up with a prop that is both verified and hidden). I could have made a new field like "visibility -> hidden / visible / verified" and migrated it over but it seemed like there was limited benefit to that and I wasn't sure if there was a future where we might want some combination of hidden + verified. So.... I went with the logic instead.

If a property is hidden it still shows up in the Data Management area, but not in the filter property selector thing.

Bunch o screenshots:

image

apparently the prop dev view page didn't say if it was verified so.... added that:
Arc 2025-02-21 13 03 04

Neither did the popover, how is someone supposed to know if it's verified / preferred if it doesn't show up?!? 😆
Arc 2025-02-21 13 03 49

Popover edit (ignore that it says "standard" - i've changed to "visible"):
Arc 2025-02-21 13 04 14

No screenshots for API changes and validation but it should all be there..

👉 Stay up-to-date with PostHog coding conventions for a smoother review.

Does this work well for both Cloud and self-hosted?

N/A - cloud only, teams plan only!

How did you test this code?

Tests, 👀

@raquelmsmith
Copy link
Member Author

Random review request from you @Twixes because I feel like you've touched all these things in the past, and you were a suggested reviewer 😏

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

Based on the provided files, I'll summarize the key changes in this PR:

This PR adds a hidden property status feature to property definitions in PostHog, enabling better property management. Here are the key points:

  • Added hidden boolean field to EnterprisePropertyDefinition model with default=False, allowing properties to be marked as hidden from property selectors
  • Introduced new PropertyStatusControl component replacing VerifiedDefinitionCheckbox, offering three states: Verified, Standard (visible), or Hidden
  • Added validation ensuring properties cannot be both hidden and verified simultaneously - hiding a verified property unverifies it and vice versa
  • Implemented exclude_hidden parameter in API endpoints to filter out hidden properties when enterprise taxonomy feature is enabled
  • Added visual indicators in UI (definition view, popovers) to clearly show property verification status with appropriate icons and tooltips

The changes help organizations better manage their properties by allowing them to hide deprecated or unwanted properties while keeping them accessible in the Data Management area.

13 file(s) reviewed, 12 comment(s)
Edit PR Review Bot Settings | Greptile

migrations.AddField(
model_name="enterprisepropertydefinition",
name="hidden",
field=models.BooleanField(blank=True, default=False, null=True),
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Consider making null=False since default=False is provided. Having both nullable and a default value can lead to ambiguous states.

@@ -19,6 +19,7 @@ class EnterprisePropertyDefinition(PropertyDefinition):
blank=True,
related_name="property_verifying_user",
)
hidden = models.BooleanField(blank=True, null=True, default=False)
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Consider making hidden field non-nullable since it has a default value. This would simplify logic and prevent potential null checks.

Suggested change
hidden = models.BooleanField(blank=True, null=True, default=False)
hidden = models.BooleanField(blank=True, default=False)

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 a good suggestion, same as verified above

Copy link
Member Author

Choose a reason for hiding this comment

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

We have to allow null I think so that the existing rows don't all have to be updated, if anything I would remove the default. Thoughts?

Comment on lines 3326 to 3327

export type PropertyDefinitionVerificationStatus = 'verified' | 'hidden' | 'standard'
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Consider using an enum instead of a union type for better type safety and IDE support

Copy link
Contributor

github-actions bot commented Feb 25, 2025

Size Change: +1.63 kB (+0.02%)

Total Size: 9.72 MB

Filename Size Change
frontend/dist/toolbar.js 9.72 MB +1.63 kB (+0.02%)

compressed-size-action

@@ -19,6 +19,7 @@ class EnterprisePropertyDefinition(PropertyDefinition):
blank=True,
related_name="property_verifying_user",
)
hidden = models.BooleanField(blank=True, null=True, default=False)
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 a good suggestion, same as verified above

@@ -19,6 +19,7 @@ class EnterprisePropertyDefinition(PropertyDefinition):
blank=True,
related_name="property_verifying_user",
)
Copy link
Contributor

Choose a reason for hiding this comment

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

hidden_at, hidden_by (following the verified patter) could be helpful, esp if we don't have audit logs on prop defs (which I'm not sure whether or not we do)

Copy link
Member Author

Choose a reason for hiding this comment

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

I think I'd rather this go into the activity log tbh... and I don't feel like doing that now 😬 Is that cool with you or do you really think it should be included?


def update(self, property_definition: EnterprisePropertyDefinition, validated_data: dict):
# If setting hidden=True, ensure verified becomes false
if validated_data.get("hidden", False):
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this logic duplicated here? validate should be called before update so if it was all in validate then should be covered?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't know 🙈

@Twixes how are the multiple API endpoints used - there is one for ee and one for non-ee. My ee tests didn't pass without the ee api changes so I just copied them over...

def update(self, property_definition: PropertyDefinition, validated_data: dict):
# If setting hidden=True, ensure verified becomes false
if validated_data.get("hidden", False):
validated_data["verified"] = False
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't fully understand why there are two view sets for updating prop defs, but maybe we should update the logic here to be the same, where you also clear the verified at and verified by.

Copy link
Member

@Twixes Twixes left a comment

Choose a reason for hiding this comment

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

Very vaguely involved with definitions, but I'm always in favor of great UX, and I think we're pretty close here! However, some things to smooth out before we merge

Comment on lines +81 to +85
exclude_hidden = serializers.BooleanField(
help_text="Whether to exclude properties marked as hidden",
required=False,
default=False,
)
Copy link
Member

@Twixes Twixes Feb 25, 2025

Choose a reason for hiding this comment

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

It seems it should be the inverse, hidden properties should be hidden unless you opt into including them (we only want to include in the property definitions scene)

Copy link
Member Author

Choose a reason for hiding this comment

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

I kind of disagree - I feel like it's better to include everything by default in the endpoint and use filters to narrow it down, not broaden the scope.

Hidden can make you think it shouldn't be automatically included because of the field name, but in reality the hiding is a UI thing, it's not like it's archived (if it was an archive or delete option I'd agree with you that it should be excluded by default).

@raquelmsmith raquelmsmith requested a review from Twixes February 26, 2025 04:39
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