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