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: Discussions panel #19272

Merged
merged 172 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
172 commits
Select commit Hold shift + click to select a range
86b00cf
changed color theme ui (wip)
corywatilo Dec 6, 2023
fe315a9
Update UI snapshots for `chromium` (1)
github-actions[bot] Dec 6, 2023
2851218
Added comments api
benjackwhite Dec 12, 2023
4ecb8dc
Fixed up tests
benjackwhite Dec 12, 2023
6d8345a
Update query snapshots
github-actions[bot] Dec 12, 2023
6ab8724
Fixes
benjackwhite Dec 12, 2023
a2c391d
Fixes
benjackwhite Dec 15, 2023
148b941
Added stories
benjackwhite Dec 15, 2023
85ad7e4
Update UI snapshots for `chromium` (1)
github-actions[bot] Dec 15, 2023
a8a7734
Update UI snapshots for `chromium` (2)
github-actions[bot] Dec 15, 2023
373c978
Fixes
benjackwhite Dec 15, 2023
fd22eab
feat: comments frontend (#19303)
daibhin Dec 15, 2023
c154f6d
Merge branch 'master' into feat/comments-2
benjackwhite Dec 15, 2023
35f531c
Fix
benjackwhite Dec 18, 2023
b9d53f3
Fixed up button styles
benjackwhite Dec 18, 2023
46a1070
Fix up
benjackwhite Dec 18, 2023
fad3ee8
Fix
benjackwhite Dec 18, 2023
6f50423
fix: Change clearable lemonselect to use sideaction
benjackwhite Dec 18, 2023
a1ef69b
Fix
benjackwhite Dec 18, 2023
986bd45
Merge branch 'master' into fix/select-button-gap
benjackwhite Dec 18, 2023
c207b66
Update UI snapshots for `chromium` (2)
github-actions[bot] Dec 18, 2023
3c6af92
Merge branch 'feat/scrollable-component' into feat/comments-2
benjackwhite Dec 18, 2023
05d37f0
Fix
benjackwhite Dec 18, 2023
be21dd0
Fixes
benjackwhite Dec 18, 2023
53dd609
Fixed up lemonbuttonwithsideaction wrapping
benjackwhite Dec 18, 2023
0143584
Merge branch 'fix/select-button-gap' of github.com:PostHog/posthog in…
benjackwhite Dec 18, 2023
40cdf81
Update query snapshots
github-actions[bot] Dec 18, 2023
12f0ba4
render comment marks
daibhin Dec 15, 2023
caec26a
cleanup approach
daibhin Dec 18, 2023
2d2bf4e
Update UI snapshots for `webkit` (2)
github-actions[bot] Dec 18, 2023
71514c4
Update UI snapshots for `chromium` (1)
github-actions[bot] Dec 18, 2023
de03b05
Update UI snapshots for `chromium` (2)
github-actions[bot] Dec 18, 2023
7e5b83c
Update query snapshots
github-actions[bot] Dec 18, 2023
4665f22
remove mark if input blurred
daibhin Dec 18, 2023
8ea9fa2
autofocus input
daibhin Dec 18, 2023
62bd258
Update UI snapshots for `webkit` (2)
github-actions[bot] Dec 18, 2023
79289f3
Merge branch 'feat/comments-2' of github.com:PostHog/posthog into fea…
benjackwhite Dec 18, 2023
e784157
Update UI snapshots for `webkit` (2)
github-actions[bot] Dec 18, 2023
a1d8e10
Fixes
benjackwhite Dec 18, 2023
e3780af
remove mark if comment deleted
daibhin Dec 18, 2023
10fa781
rerun migration
daibhin Dec 18, 2023
9f8d5ac
Merge branch 'master' into feat/comments-2
daibhin Dec 18, 2023
e959b62
fix migration conflicts
daibhin Dec 18, 2023
60a3622
Merge branch 'feat/comments-2' of github.com:PostHog/posthog into fea…
benjackwhite Dec 18, 2023
0cca64e
add comment id to mark
daibhin Dec 18, 2023
af0cc6e
Update UI snapshots for `webkit` (2)
github-actions[bot] Dec 18, 2023
99271d8
Update UI snapshots for `webkit` (2)
github-actions[bot] Dec 18, 2023
650081f
Update UI snapshots for `webkit` (2)
github-actions[bot] Dec 18, 2023
89ff8ea
Update UI snapshots for `webkit` (2)
github-actions[bot] Dec 18, 2023
9727913
Update UI snapshots for `webkit` (2)
github-actions[bot] Dec 18, 2023
a3ca247
Update UI snapshots for `webkit` (2)
github-actions[bot] Dec 18, 2023
c8c056c
Update UI snapshots for `webkit` (2)
github-actions[bot] Dec 18, 2023
da86794
Update UI snapshots for `webkit` (2)
github-actions[bot] Dec 18, 2023
ef62f8b
Update UI snapshots for `webkit` (2)
github-actions[bot] Dec 18, 2023
a3f1aff
Update UI snapshots for `webkit` (2)
github-actions[bot] Dec 18, 2023
33f1a91
Update UI snapshots for `webkit` (2)
github-actions[bot] Dec 18, 2023
3882d8e
Merge branch 'feat/comments-2' of github.com:PostHog/posthog into fea…
benjackwhite Dec 19, 2023
2f4e531
Don't load comments straight away
benjackwhite Dec 19, 2023
43424a6
Fixes
benjackwhite Dec 19, 2023
69b0357
Swap to callback approach
benjackwhite Dec 19, 2023
16cab07
Fixed up context
benjackwhite Dec 19, 2023
056b852
Fixed highlighting of relevant comment
benjackwhite Dec 19, 2023
a6d8065
Added regexes
benjackwhite Dec 19, 2023
772a11a
Some fixes
benjackwhite Dec 19, 2023
4df28de
Merge
benjackwhite Dec 19, 2023
1238dd4
Fix migrations
benjackwhite Dec 19, 2023
1d575eb
Update UI snapshots for `webkit` (2)
github-actions[bot] Dec 19, 2023
82a7b69
Merge branch 'master' into fix/select-button-gap
benjackwhite Dec 19, 2023
d33d7f0
Fix
benjackwhite Dec 19, 2023
9d01380
Update UI snapshots for `chromium` (1)
github-actions[bot] Dec 19, 2023
8a45d43
Merge branch 'fix/select-button-gap' into feat/comments-2
benjackwhite Dec 19, 2023
3677612
Fixes
benjackwhite Dec 19, 2023
afc9a60
Update query snapshots
github-actions[bot] Dec 19, 2023
a6e2476
Update query snapshots
github-actions[bot] Dec 19, 2023
4aab86f
Fixes
benjackwhite Dec 20, 2023
262b7f4
add flag to discussion insertion
daibhin Dec 20, 2023
02a1c33
remove deleted comment mark
daibhin Dec 20, 2023
5c87255
show comments on nodes
daibhin Dec 20, 2023
fc05af2
hide new comment button if selection within comment
daibhin Dec 20, 2023
5231d04
remove mark if cancel pressed
daibhin Dec 20, 2023
229eab0
cleanup
daibhin Dec 21, 2023
1110fd0
Merge branch 'master' into feat/comments-2
daibhin Dec 21, 2023
fcf5342
reset snapshot
daibhin Dec 21, 2023
eded370
fix tiptap flush sync error
daibhin Dec 21, 2023
b72b5ae
Update UI snapshots for `chromium` (2)
github-actions[bot] Dec 21, 2023
1205f36
Added activity scopes
benjackwhite Dec 21, 2023
14c2ef3
Merge branches 'feat/comments-2' and 'feat/comments-2' of github.com:…
benjackwhite Dec 21, 2023
a8fd951
Move to segmented button
benjackwhite Dec 21, 2023
06b84e8
Merge branch 'feat/move-web-to-segmented-button' into feat/comments-2
benjackwhite Dec 21, 2023
b0c1105
Update UI snapshots for `chromium` (2)
github-actions[bot] Dec 21, 2023
cf5b280
Fixes
benjackwhite Dec 21, 2023
8ac6d44
Update UI snapshots for `chromium` (1)
github-actions[bot] Dec 21, 2023
d83b09f
Update UI snapshots for `chromium` (2)
github-actions[bot] Dec 21, 2023
ff817d6
Merge branch 'feat/comments-2' of github.com:PostHog/posthog into fea…
benjackwhite Dec 21, 2023
1d442c8
Fixed up filter select
benjackwhite Dec 21, 2023
6054d04
Fixes
benjackwhite Dec 21, 2023
3d9a815
Fix
benjackwhite Dec 21, 2023
5e8a0fe
Fixes
benjackwhite Dec 21, 2023
db63441
Fixed up activity dropdown
benjackwhite Dec 21, 2023
128eea1
Fixes
benjackwhite Dec 21, 2023
4c56951
Fixes
benjackwhite Dec 21, 2023
47eb8f9
Merge branch 'master' into feat/comments-2
benjackwhite Dec 21, 2023
ff1c602
Update UI snapshots for `chromium` (1)
github-actions[bot] Dec 21, 2023
afe3eaa
reset selection
daibhin Dec 21, 2023
7a3489f
Update UI snapshots for `chromium` (2)
github-actions[bot] Dec 21, 2023
f1a1be7
Update UI snapshots for `chromium` (2)
github-actions[bot] Dec 21, 2023
046ea28
Fixes
benjackwhite Dec 21, 2023
3257819
Merge branch 'feat/comments-2' of github.com:PostHog/posthog into fea…
benjackwhite Dec 21, 2023
18b45eb
More work to get activity working
benjackwhite Dec 22, 2023
7d4bdad
cleanup
daibhin Dec 22, 2023
61c0081
Fixe option in activity dropdown
benjackwhite Dec 22, 2023
c332b1d
Swap notebooks activity to use short_id
benjackwhite Dec 22, 2023
888fce5
Fix scenes
benjackwhite Dec 22, 2023
eb0a7f1
Added new selector like we have for breadcrumbs
benjackwhite Dec 22, 2023
cc28254
Add missing scopes
benjackwhite Dec 22, 2023
589b90f
Fix
benjackwhite Dec 22, 2023
ea567a2
Update UI snapshots for `chromium` (1)
github-actions[bot] Dec 22, 2023
7d4dc24
Update UI snapshots for `chromium` (2)
github-actions[bot] Dec 22, 2023
8620c85
Update UI snapshots for `chromium` (2)
github-actions[bot] Dec 22, 2023
4560067
Update UI snapshots for `chromium` (2)
github-actions[bot] Dec 22, 2023
368666a
Update UI snapshots for `chromium` (2)
github-actions[bot] Dec 22, 2023
54ff0b5
Update UI snapshots for `chromium` (2)
github-actions[bot] Dec 22, 2023
621b4bd
Update UI snapshots for `chromium` (2)
github-actions[bot] Dec 22, 2023
2ad9ec6
Update UI snapshots for `chromium` (2)
github-actions[bot] Dec 22, 2023
876af2f
Update UI snapshots for `chromium` (2)
github-actions[bot] Dec 22, 2023
88cd873
Update UI snapshots for `chromium` (2)
github-actions[bot] Dec 22, 2023
591f528
Update UI snapshots for `chromium` (2)
github-actions[bot] Dec 22, 2023
3d60d2e
Update UI snapshots for `chromium` (2)
github-actions[bot] Dec 22, 2023
32cf563
Update query snapshots
github-actions[bot] Dec 22, 2023
561ada8
Update UI snapshots for `chromium` (2)
github-actions[bot] Dec 22, 2023
97da005
Update query snapshots
github-actions[bot] Dec 22, 2023
00199e3
Update UI snapshots for `chromium` (2)
github-actions[bot] Dec 22, 2023
073ae2e
Update UI snapshots for `chromium` (2)
github-actions[bot] Dec 22, 2023
f1229d5
Merge branch 'master' into feat/comments-2
benjackwhite Jan 2, 2024
1fbe5ba
fix
benjackwhite Jan 2, 2024
fac5189
Update UI snapshots for `chromium` (1)
github-actions[bot] Jan 2, 2024
3d66034
Update UI snapshots for `chromium` (1)
github-actions[bot] Jan 2, 2024
cbabab3
Fixes
benjackwhite Jan 2, 2024
48512b5
Fixed up notebook ID system
benjackwhite Jan 2, 2024
13ae65d
Fix
benjackwhite Jan 2, 2024
7f2d80e
Fixes
benjackwhite Jan 2, 2024
de3edd9
Fix api
benjackwhite Jan 2, 2024
6092a73
Update query snapshots
github-actions[bot] Jan 2, 2024
3cac70d
Fixes
benjackwhite Jan 2, 2024
d15a6ac
Fixes
benjackwhite Jan 2, 2024
a3a41c6
fix
benjackwhite Jan 2, 2024
2d5ceef
Fixes
benjackwhite Jan 2, 2024
f618c19
Fix
benjackwhite Jan 2, 2024
3b39b03
Corrected scope
benjackwhite Jan 2, 2024
767561b
Fixed source comment
benjackwhite Jan 2, 2024
11cf2a3
Fixed up API
benjackwhite Jan 2, 2024
1e32544
Fixed up minimal comment display
benjackwhite Jan 2, 2024
f24fc33
Fixes and added comments to important changes
benjackwhite Jan 2, 2024
b2b7dec
Fix
benjackwhite Jan 2, 2024
70a4096
Update UI snapshots for `chromium` (2)
github-actions[bot] Jan 2, 2024
633d9ea
Fixes
benjackwhite Jan 2, 2024
a2050b8
Merge branch 'feat/comments-2' of github.com:PostHog/posthog into fea…
benjackwhite Jan 2, 2024
524c245
Fix
benjackwhite Jan 2, 2024
aeaf016
Fix
benjackwhite Jan 2, 2024
ed8ff15
Fixed up a bunch of issues around possible optional detail
benjackwhite Jan 2, 2024
3e0de81
Revert "Fixed up a bunch of issues around possible optional detail"
benjackwhite Jan 2, 2024
9b7139f
Fix up check
benjackwhite Jan 2, 2024
c0a6750
Remove todos
benjackwhite Jan 2, 2024
0a9f036
Fix up
benjackwhite Jan 2, 2024
c7d3138
Fix
benjackwhite Jan 2, 2024
af63ae8
Fix
benjackwhite Jan 2, 2024
5e7fae4
Fix test
benjackwhite Jan 2, 2024
b33f167
Fix up ID changes
benjackwhite Jan 2, 2024
b225efe
Fixes
benjackwhite Jan 2, 2024
0335a92
Merge branch 'master' into feat/comments-2
benjackwhite Jan 2, 2024
b24c25f
Fixes
benjackwhite Jan 2, 2024
380d2f6
Update frontend/src/layout/navigation-3000/sidepanel/panels/activity/…
benjackwhite Jan 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion latest_migrations.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ contenttypes: 0002_remove_content_type_name
ee: 0015_add_verified_properties
otp_static: 0002_throttling
otp_totp: 0002_auto_20190420_0723
posthog: 0373_externaldataschema
posthog: 0374_add_comments
sessions: 0001_initial
social_django: 0010_uid_db_index
two_factor: 0007_auto_20201201_1019
8 changes: 8 additions & 0 deletions posthog/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
app_metrics,
async_migration,
authentication,
comments,
dead_letter_queue,
early_access_feature,
event_definition,
Expand Down Expand Up @@ -332,4 +333,11 @@ def api_not_found(request):
["team_id"],
)

projects_router.register(
r"comments",
comments.CommentViewSet,
"project_comments",
["team_id"],
)

projects_router.register(r"search", search.SearchViewSet, "project_search", ["team_id"])
89 changes: 89 additions & 0 deletions posthog/api/comments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
from typing import Any, Dict
from django.db import transaction
from django.db.models import QuerySet

from rest_framework import exceptions, serializers, viewsets, pagination
from rest_framework.decorators import action
from rest_framework.request import Request
from rest_framework.response import Response

from posthog.api.forbid_destroy_model import ForbidDestroyModel

from posthog.api.routing import StructuredViewSetMixin
from posthog.api.shared import UserBasicSerializer
from posthog.models.comment import Comment


class CommentSerializer(serializers.ModelSerializer):
created_by = UserBasicSerializer(read_only=True)

class Meta:
model = Comment
exclude = []
read_only_fields = ["id", "created_by", "version"]

def validate(self, data):
request = self.context["request"]

if self.instance:
if self.instance.created_by != request.user:
raise exceptions.PermissionDenied("You can only modify your own comments")
# TODO: Ensure created_by is set
# And only allow updates to own comment

data["created_by"] = request.user

return data

def update(self, instance: Comment, validated_data: Dict, **kwargs) -> Comment:
request = self.context["request"]

with transaction.atomic():
# select_for_update locks the database row so we ensure version updates are atomic
locked_instance = Comment.objects.select_for_update().get(pk=instance.pk)

if locked_instance.created_by != request.user:
raise

if validated_data.keys():
if validated_data.get("content"):
validated_data["version"] = locked_instance.version + 1

updated_instance = super().update(locked_instance, validated_data)

return updated_instance


class CommentPagination(pagination.CursorPagination):
ordering = "-created_at"
page_size = 100


class CommentViewSet(StructuredViewSetMixin, ForbidDestroyModel, viewsets.ModelViewSet):
queryset = Comment.objects.all()
serializer_class = CommentSerializer
pagination_class = CommentPagination

def get_queryset(self) -> QuerySet:
queryset = super().get_queryset()
params = self.request.GET.dict()

if params.get("user"):
queryset = queryset.filter(user=params.get("user"))

if params.get("scope"):
queryset = queryset.filter(scope=params.get("scope"))

if params.get("item_id"):
queryset = queryset.filter(item_id=params.get("item_id"))

if self.action == "thread":
# Filter based on the source_comment_id
object_id = self.kwargs.get("pk")
queryset = queryset.filter(source_comment_id=object_id)

return queryset

@action(methods=["GET"], detail=True)
def thread(self, request: Request, *args: Any, **kwargs: Any) -> Response:
return self.list(request, *args, **kwargs)
35 changes: 35 additions & 0 deletions posthog/migrations/0374_add_comments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Generated by Django 3.2.19 on 2023-12-12 09:31

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import posthog.models.utils


class Migration(migrations.Migration):

dependencies = [
('posthog', '0373_externaldataschema'),
]

operations = [
migrations.CreateModel(
name='Comment',
fields=[
('id', models.UUIDField(default=posthog.models.utils.UUIDT, editable=False, primary_key=True, serialize=False)),
('content', models.TextField(blank=True, null=True)),
('deleted_at', models.DateTimeField(auto_now_add=True)),
('version', models.IntegerField(default=0)),
('created_at', models.DateTimeField(auto_now_add=True)),
('item_id', models.CharField(max_length=72, null=True)),
('scope', models.CharField(max_length=79)),
('created_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)),
('source_comment_id', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='posthog.comment')),
('team', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='posthog.team')),
],
),
migrations.AddIndex(
model_name='comment',
index=models.Index(fields=['team_id', 'scope', 'item_id'], name='posthog_com_team_id_be2206_idx'),
),
]
1 change: 1 addition & 0 deletions posthog/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from .async_deletion import AsyncDeletion, DeletionType
from .async_migration import AsyncMigration, AsyncMigrationError, MigrationStatus
from .cohort import Cohort, CohortPeople
from .comment import Comment
from .dashboard import Dashboard
from .dashboard_tile import DashboardTile, Text
from .early_access_feature import EarlyAccessFeature
Expand Down
51 changes: 51 additions & 0 deletions posthog/models/comment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from django.db import models
from posthog.models.activity_logging.activity_log import Change, Detail, log_activity
from posthog.models.signals import mutable_receiver

from posthog.models.utils import UUIDModel

# NOTE: This model is meant to be loosely related to the `activity_log` as they are similar in function and approach


class Comment(UUIDModel):
team: models.ForeignKey = models.ForeignKey("Team", on_delete=models.CASCADE)
content: models.TextField = models.TextField(blank=True, null=True)
deleted_at: models.DateTimeField = models.DateTimeField(auto_now_add=True, blank=True)
version: models.IntegerField = models.IntegerField(default=0)
created_at: models.DateTimeField = models.DateTimeField(auto_now_add=True, blank=True)
created_by: models.ForeignKey = models.ForeignKey("User", on_delete=models.SET_NULL, null=True, blank=True)

# Loose relationship modelling to other PostHog resources
item_id = models.fields.CharField(max_length=72, null=True)
scope = models.fields.CharField(max_length=79, null=False)

# TODO: How do we allow comments to exist on individual elements such as a line in a Notebook?
# Maybe the right way is to create a Mark in a notebook and then have that store the CommentID, keeping the comments clean
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# TODO: How do we allow comments to exist on individual elements such as a line in a Notebook?
# Maybe the right way is to create a Mark in a notebook and then have that store the CommentID, keeping the comments clean


# Threads/replies are simply comments with a source_comment_id
source_comment_id: models.ForeignKey = models.ForeignKey("Comment", on_delete=models.CASCADE, null=True, blank=True)

class Meta:
indexes = [models.Index(fields=["team_id", "scope", "item_id"])]


@mutable_receiver(models.signals.post_save, sender=Comment)
def log_comment_activity(sender, instance: Comment, created: bool, **kwargs):
if created:
# TODO: Ensure we got this right, people should get notified when
# 1. A comment is placed on something they are interested in
# 2. A comment is in reply to a thread they started (for now)
# 3. A comment includes a @mention of them
benjackwhite marked this conversation as resolved.
Show resolved Hide resolved
log_activity(
organization_id=None,
team_id=instance.team_id,
user=instance.created_by,
item_id=instance.item_id,
scope=instance.scope,
activity="commented",
# TODO: Check with Paul if this is right
detail=Detail(
name=instance.content,
changes=[Change(type="Comment", field="content", action="created", after=instance.content)],
Copy link
Member

Choose a reason for hiding this comment

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

to the point above...

you could have "edited" as the action too and then you can cover the @ mention case. Because it's only "comment activities including an @ mention since the last bookmark for this user"

),
)
Loading