Skip to content

Commit

Permalink
Fixed up API
Browse files Browse the repository at this point in the history
  • Loading branch information
benjackwhite committed Jan 2, 2024
1 parent 767561b commit 11cf2a3
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion frontend/src/scenes/comments/Comment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const Comment = ({ comment }: { comment: CommentType }): JSX.Element => {
{
icon: <IconShare />,
label: 'Reply',
onClick: () => setReplyingComment(comment.source_comment_id ?? comment.id),
onClick: () => setReplyingComment(comment.source_comment ?? comment.id),
},
{
icon: <IconPencil />,
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/scenes/comments/commentsLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export const commentsLogic = kea<commentsLogicType>([
scope: props.scope,
item_id: props.item_id,
item_context: values.itemContext?.context,
source_comment_id: values.replyingCommentId ?? undefined,
source_comment: values.replyingCommentId ?? undefined,
})

values.itemContext?.callback?.({ sent: true })
Expand Down Expand Up @@ -180,11 +180,11 @@ export const commentsLogic = kea<commentsLogicType>([
const commentsById: Record<string, CommentWithRepliesType> = {}

for (const comment of sortedComments ?? []) {
let commentsWithReplies = commentsById[comment.source_comment_id ?? comment.id]
let commentsWithReplies = commentsById[comment.source_comment ?? comment.id]

if (!commentsWithReplies) {
commentsById[comment.source_comment_id ?? comment.id] = commentsWithReplies = {
id: comment.source_comment_id ?? comment.id,
commentsById[comment.source_comment ?? comment.id] = commentsWithReplies = {
id: comment.source_comment ?? comment.id,
comment: undefined,
replies: [],
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3263,7 +3263,7 @@ export type CommentType = {
version: number
created_at: string
created_by: UserBasicType | null
source_comment_id?: string | null
source_comment?: string | null
scope: ActivityScope
item_id?: string
item_context: Record<string, any> | null
Expand Down
10 changes: 5 additions & 5 deletions posthog/api/comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@ def get_queryset(self) -> QuerySet:
if params.get("item_id"):
queryset = queryset.filter(item_id=params.get("item_id"))

source_comment_id = params.get("source_comment_id")
source_comment = params.get("source_comment")
if self.action == "thread":
# Filter based on the source_comment_id
source_comment_id = self.kwargs.get("pk")
# Filter based on the source_comment
source_comment = self.kwargs.get("pk")

if source_comment_id:
if source_comment:
# NOTE: Should we also return the source_comment ?
queryset = queryset.filter(source_comment_id=source_comment_id)
queryset = queryset.filter(source_comment_id=source_comment)

return queryset

Expand Down
10 changes: 5 additions & 5 deletions posthog/api/test/test_comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def test_creates_comment_successfully(self) -> None:
"item_id": None,
"item_context": None,
"scope": "Notebook",
"source_comment_id": None,
"source_comment": None,
}

def test_updates_content_and_increments_version(self) -> None:
Expand Down Expand Up @@ -85,7 +85,7 @@ def test_updates_content_and_increments_version(self) -> None:
"item_id": None,
"item_context": None,
"scope": "Notebook",
"source_comment_id": None,
"source_comment": None,
}

def test_empty_comments_list(self) -> None:
Expand Down Expand Up @@ -122,13 +122,13 @@ def test_lists_comments_filtering(self) -> None:

def test_lists_comments_thread(self) -> None:
initial_comment = self._create_comment({"content": "comment notebook-1", "scope": "Notebook", "item_id": "1"})
self._create_comment({"content": "comment reply", "source_comment_id": initial_comment["id"]})
self._create_comment({"content": "comment other reply", "source_comment_id": initial_comment["id"]})
self._create_comment({"content": "comment reply", "source_comment": initial_comment["id"]})
self._create_comment({"content": "comment other reply", "source_comment": initial_comment["id"]})
self._create_comment({"content": "comment elsewhere"})

for url in [
f"/api/projects/{self.team.id}/comments/{initial_comment['id']}/thread",
f"/api/projects/{self.team.id}/comments/?source_comment_id={initial_comment['id']}",
f"/api/projects/{self.team.id}/comments/?source_comment={initial_comment['id']}",
]:
response = self.client.get(url)
assert len(response.json()["results"]) == 2
Expand Down

0 comments on commit 11cf2a3

Please sign in to comment.