Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 2 additions & 0 deletions frontend/cypress/e2e/comment.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ describe('Comment', () => {
cy.get('button:contains("👍"):visible').click()
cy.wait('@reactRequest')
cy.get('button:contains("👍 1")').should('exist')
cy.get(`div[data-id=${comment.name}]`).contains('Edited').should('not.exist')

// remove a reaction
cy.get(`div[data-id=${comment.name}] button[aria-label="Add a reaction"]`).click()
Expand All @@ -82,6 +83,7 @@ describe('Comment', () => {
.type('{enter}@john{enter}', { delay: 100 }) // mention user
cy.button('Submit').click()
cy.get(`div[data-id=${comment.name}]`).contains('This is an edited comment').should('exist')
cy.get(`div[data-id=${comment.name}]`).contains('Edited').should('exist')
cy.get(
`div[data-id=${comment.name}] [data-type="mention"][data-id="john@example.com"]`,
).should('exist')
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/components/Comment.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
</time>
</Tooltip>
<Tooltip
v-if="comment.modified > comment.creation"
:text="dayjsLocal(comment.modified).format('D MMM YYYY [at] h:mm A')"
v-if="comment.edited_at"
:text="dayjsLocal(comment.edited_at).format('D MMM YYYY [at] h:mm A')"
>
<span class="text-ink-gray-5"> &nbsp;&middot; Edited </span>
</Tooltip>
Expand Down Expand Up @@ -180,7 +180,7 @@ const dropdownOptions = computed(() => [
label: 'Revisions',
icon: 'rotate-ccw',
onClick: () => (showRevisionsDialog.value = true),
condition: () => props.comment.modified > props.comment.creation,
condition: () => Boolean(props.comment.edited_at),
},
{
label: 'Copy link',
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/CommentsArea.vue
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ const comments = useList<GPComment>({
'owner',
'creation',
'modified',
'edited_at',
'deleted_at',
{ reactions: ['name', 'user', 'emoji'] },
],
Expand Down
10 changes: 9 additions & 1 deletion frontend/src/components/CommentsList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,14 @@ const newCommentEditor = ref(null)
const comments = useList<
Pick<
GPComment,
'name' | 'content' | 'owner' | 'creation' | 'modified' | 'deleted_at' | 'reactions'
| 'name'
| 'content'
| 'owner'
| 'creation'
| 'modified'
| 'edited_at'
| 'deleted_at'
| 'reactions'
>
>({
doctype: 'GP Comment',
Expand All @@ -141,6 +148,7 @@ const comments = useList<
'owner',
'creation',
'modified',
'edited_at',
'deleted_at',
{ reactions: ['name', 'user', 'emoji'] },
],
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/types/doctypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ export interface GPComment extends DocType {
reference_doctype?: string
/** Reference Name: Dynamic Link (reference_doctype) */
reference_name?: string
/** Edited At: Datetime */
edited_at?: string
/** Reactions: Table (GP Reaction) */
reactions: GPReaction[]
/** Deleted At: Datetime */
Expand Down
6 changes: 6 additions & 0 deletions gameplan/gameplan/doctype/gp_comment/gp_comment.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"content",
"reference_doctype",
"reference_name",
"edited_at",
"deleted_at",
"reactions",
"tags"
Expand All @@ -34,6 +35,11 @@
"label": "Reference Name",
"options": "reference_doctype"
},
{
"fieldname": "edited_at",
"fieldtype": "Datetime",
"label": "Edited At"
},
{
"fieldname": "reactions",
"fieldtype": "Table",
Expand Down
8 changes: 8 additions & 0 deletions gameplan/gameplan/doctype/gp_comment/gp_comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def after_delete(self):
self.update_task_meta()

def before_save(self):
self.set_edited_at()
self.update_tags()

def update_discussion_meta(self):
Expand Down Expand Up @@ -68,6 +69,13 @@ def sanitize_content(self):
self.content = remove_empty_trailing_paragraphs(self.content)
self.content = sanitize_content(self.content)

def set_edited_at(self):
if not self.get_doc_before_save():
return

if self.has_value_changed("content"):
self.edited_at = frappe.utils.now()

def on_update(self):
self.notify_mentions()
self.notify_reactions()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import frappe


def execute():
frappe.db.sql(
"""
update `tabGP Comment` comment
inner join (
select docname, max(creation) as edited_at
from `tabVersion`
where ref_doctype = 'GP Comment'
and data like %s
group by docname
) revisions on revisions.docname = comment.name
set comment.edited_at = revisions.edited_at
where comment.edited_at is null
""",
# Version.data stores changed fields as JSON arrays like ["content", old, new].
('%["content",%',),
)
1 change: 1 addition & 0 deletions gameplan/patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ gameplan.gameplan.doctype.gp_project_visit.patches.add_indexes
gameplan.gameplan.doctype.gp_unread_record.patches.migrate_to_unread_records
gameplan.gameplan.doctype.gp_pinned_project.patches.delete_pinned_projects_for_archived_spaces
gameplan.gameplan.doctype.gp_discussion.patches.set_default_pin_scope
gameplan.gameplan.doctype.gp_comment.patches.backfill_gp_comment_edited_at
Loading