diff --git a/CHANGELOG.md b/CHANGELOG.md index e6655ab..c253634 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 Version must be kept in-sync between [`package.json`](package.json) and [`wxt.config.js`](wxt.config.ts). ## [Unreleased] +### Fixed +- We don't show edited comments in the popup table anymore. ([#110](https://github.com/diffplug/gitcasso/pull/110)) ## [1.1.0] - 2025-10-07 ### Added diff --git a/src/entrypoints/background.ts b/src/entrypoints/background.ts index f9f96eb..b776210 100644 --- a/src/entrypoints/background.ts +++ b/src/entrypoints/background.ts @@ -1,7 +1,8 @@ -import type { - CommentEvent, - CommentEventType, - CommentSpot, +import { + type CommentEvent, + type CommentEventType, + type CommentSpot, + DRAFT_STORAGE_UNSUPPORTED, } from "@/lib/enhancer" import { type DraftStats, statsFor } from "@/lib/enhancers/draft-stats" import { logger } from "@/lib/logger" @@ -51,6 +52,11 @@ export function handleCommentEvent( return CLOSE_MESSAGE_PORT } + // Skip storage for spots that don't support draft history + if (message.spot.unique_key === DRAFT_STORAGE_UNSUPPORTED) { + return CLOSE_MESSAGE_PORT + } + switch (message.type) { case "ENHANCED": { // track the draft diff --git a/src/lib/enhancer.ts b/src/lib/enhancer.ts index c50dc01..a4f3a6d 100644 --- a/src/lib/enhancer.ts +++ b/src/lib/enhancer.ts @@ -50,3 +50,40 @@ export interface CommentEnhancer { /** The default title of a row */ tableTitle(spot: Spot): string } + +/** + * Special sentinel value for unique_key indicating that draft history + * should not be stored for this spot. Spots with this unique_key will: + * - Still be enhanced with OverType + * - NOT be stored in the background service's openSpots map + * - NOT appear in the popup table + */ +export const DRAFT_STORAGE_UNSUPPORTED = "DRAFT_STORAGE_UNSUPPORTED" as const + +/** + * Abstract base class for enhancers that return spots with DRAFT_STORAGE_UNSUPPORTED. + * Table methods throw exceptions since such spots won't appear in the table. + */ +export abstract class CommentEnhancerNoDraftHistory< + Spot extends CommentSpot = CommentSpot, +> implements CommentEnhancer +{ + abstract forSpotTypes(): string[] + abstract tryToEnhance( + textarea: HTMLTextAreaElement, + location: StrippedLocation + ): Spot | null + abstract enhance(textarea: HTMLTextAreaElement, spot: Spot): OverTypeInstance + + tableUpperDecoration(_spot: Spot): never { + throw new Error( + "tableUpperDecoration should not be called for DRAFT_STORAGE_UNSUPPORTED spots" + ) + } + + tableTitle(_spot: Spot): never { + throw new Error( + "tableTitle should not be called for DRAFT_STORAGE_UNSUPPORTED spots" + ) + } +} diff --git a/src/lib/enhancers/github/GitHubEditEnhancer.tsx b/src/lib/enhancers/github/GitHubEditEnhancer.tsx index 2bc8b61..37222de 100644 --- a/src/lib/enhancers/github/GitHubEditEnhancer.tsx +++ b/src/lib/enhancers/github/GitHubEditEnhancer.tsx @@ -1,11 +1,10 @@ import OverType, { type OverTypeInstance } from "overtype" -import type React from "react" -import type { - CommentEnhancer, - CommentSpot, - StrippedLocation, +import { + CommentEnhancerNoDraftHistory, + type CommentSpot, + DRAFT_STORAGE_UNSUPPORTED, + type StrippedLocation, } from "@/lib/enhancer" -import { logger } from "@/lib/logger" import { fixupOvertype, modifyDOM } from "../overtype-misc" import { commonGitHubOptions, @@ -22,7 +21,7 @@ export interface GitHubEditSpot extends CommentSpot { type: typeof GH_EDIT } -export class GitHubEditEnhancer implements CommentEnhancer { +export class GitHubEditEnhancer extends CommentEnhancerNoDraftHistory { forSpotTypes(): string[] { return [GH_EDIT] } @@ -44,15 +43,10 @@ export class GitHubEditEnhancer implements CommentEnhancer { if (itemId) { // Exclude textareas within Shared-module__CommentBox (those are for adding new comments, not editing) if (!isInProjectCommentBox(textarea)) { - const unique_key = `github.com:project-draft:${itemId}:edit-body` - logger.debug( - `${this.constructor.name} enhanced project draft body textarea`, - unique_key - ) return { isIssue: true, type: GH_EDIT, - unique_key, + unique_key: DRAFT_STORAGE_UNSUPPORTED, } } } @@ -63,15 +57,10 @@ export class GitHubEditEnhancer implements CommentEnhancer { // Edit mode: empty placeholder // Add new comment mode: has placeholder "Add your comment here..." or similar if (!textarea.placeholder || textarea.placeholder.trim() === "") { - const unique_key = `github.com:${issueInfo.slug}:${issueInfo.number}:edit-comment` - logger.debug( - `${this.constructor.name} enhanced project issue comment edit textarea`, - unique_key - ) return { isIssue: true, type: GH_EDIT, - unique_key, + unique_key: DRAFT_STORAGE_UNSUPPORTED, } } } @@ -86,9 +75,6 @@ export class GitHubEditEnhancer implements CommentEnhancer { if (!match) { return null } - const [, owner, repo, numberStr] = match - const number = parseInt(numberStr!, 10) - const unique_key = `github.com:${owner}/${repo}:${number}:edit-body` // Only enhance textareas that are for editing issue/PR body const isIssueBodyRootEdit = textarea.closest(".react-issue-body") @@ -102,15 +88,10 @@ export class GitHubEditEnhancer implements CommentEnhancer { if (!isIssueBodyRootEdit && !isIssueBodyCommentEdit && !isPRBodyEdit) { return null } - - logger.debug( - `${this.constructor.name} enhanced issue/PR body textarea`, - unique_key - ) return { isIssue: !!(isIssueBodyRootEdit || isIssueBodyCommentEdit), type: GH_EDIT, - unique_key, + unique_key: DRAFT_STORAGE_UNSUPPORTED, } } @@ -128,12 +109,4 @@ export class GitHubEditEnhancer implements CommentEnhancer { ) return overtype } - - tableUpperDecoration(_spot: GitHubEditSpot): React.ReactNode { - return N/A - } - - tableTitle(_spot: GitHubEditSpot): string { - return "N/A" - } } diff --git a/tests/corpus-fixture.ts b/tests/corpus-fixture.ts index e8a3181..d23a742 100644 --- a/tests/corpus-fixture.ts +++ b/tests/corpus-fixture.ts @@ -30,7 +30,10 @@ vi.mock("overtype", () => { }) import { describe as baseDescribe, test as baseTest, expect } from "vitest" -import type { StrippedLocation } from "@/lib/enhancer" +import { + DRAFT_STORAGE_UNSUPPORTED, + type StrippedLocation, +} from "@/lib/enhancer" import { EnhancerRegistry } from "../src/lib/registries" import type { CORPUS } from "./corpus/_corpus-index" import { cleanupDOM, setupDOM } from "./corpus-utils" @@ -94,6 +97,10 @@ export function tableUI() { const enhanced = enhancers.tryToEnhance(textarea, location) const forValue = `id=${textarea.id} name=${textarea.name} className=${textarea.className}` if (enhanced) { + // Skip spots that don't support table display (DRAFT_STORAGE_UNSUPPORTED) + if (enhanced.spot.unique_key === DRAFT_STORAGE_UNSUPPORTED) { + continue + } uiResults.push({ for: forValue, title: enhanced.enhancer.tableTitle(enhanced.spot), diff --git a/tests/lib/enhancers/__snapshots__/gh-detection.test.ts.snap b/tests/lib/enhancers/__snapshots__/gh-detection.test.ts.snap index 401542e..52df51c 100644 --- a/tests/lib/enhancers/__snapshots__/gh-detection.test.ts.snap +++ b/tests/lib/enhancers/__snapshots__/gh-detection.test.ts.snap @@ -23,7 +23,7 @@ exports[`github detection > gh_issue_edit:should detect correct spots 1`] = ` "spot": { "isIssue": true, "type": "GH_EDIT", - "unique_key": "github.com:diffplug/gitcasso:56:edit-body", + "unique_key": "DRAFT_STORAGE_UNSUPPORTED", }, }, { @@ -47,7 +47,7 @@ exports[`github detection > gh_issue_edit_multiple:should detect correct spots 1 "spot": { "isIssue": true, "type": "GH_EDIT", - "unique_key": "github.com:diffplug/testing-deletable:3:edit-body", + "unique_key": "DRAFT_STORAGE_UNSUPPORTED", }, }, { @@ -55,7 +55,7 @@ exports[`github detection > gh_issue_edit_multiple:should detect correct spots 1 "spot": { "isIssue": true, "type": "GH_EDIT", - "unique_key": "github.com:diffplug/testing-deletable:3:edit-body", + "unique_key": "DRAFT_STORAGE_UNSUPPORTED", }, }, { @@ -140,7 +140,7 @@ exports[`github detection > gh_pr_edit:should detect correct spots 1`] = ` "spot": { "isIssue": false, "type": "GH_EDIT", - "unique_key": "github.com:diffplug/gitcasso:58:edit-body", + "unique_key": "DRAFT_STORAGE_UNSUPPORTED", }, }, { @@ -166,7 +166,7 @@ exports[`github detection > gh_pr_edit_multiple:should detect correct spots 1`] "spot": { "isIssue": false, "type": "GH_EDIT", - "unique_key": "github.com:diffplug/testing-deletable:5:edit-body", + "unique_key": "DRAFT_STORAGE_UNSUPPORTED", }, }, { @@ -178,7 +178,7 @@ exports[`github detection > gh_pr_edit_multiple:should detect correct spots 1`] "spot": { "isIssue": false, "type": "GH_EDIT", - "unique_key": "github.com:diffplug/testing-deletable:5:edit-body", + "unique_key": "DRAFT_STORAGE_UNSUPPORTED", }, }, { @@ -228,7 +228,7 @@ exports[`github detection > gh_project_draft_edit:should detect correct spots 1` "spot": { "isIssue": true, "type": "GH_EDIT", - "unique_key": "github.com:project-draft:129503329:edit-body", + "unique_key": "DRAFT_STORAGE_UNSUPPORTED", }, }, ] @@ -257,7 +257,7 @@ exports[`github detection > gh_project_issue_edit:should detect correct spots 1` "spot": { "isIssue": true, "type": "GH_EDIT", - "unique_key": "github.com:project-draft:129503239:edit-body", + "unique_key": "DRAFT_STORAGE_UNSUPPORTED", }, }, { diff --git a/tests/lib/enhancers/__snapshots__/gh-ui.test.ts.snap b/tests/lib/enhancers/__snapshots__/gh-ui.test.ts.snap index 15c6ae1..0b52a02 100644 --- a/tests/lib/enhancers/__snapshots__/gh-ui.test.ts.snap +++ b/tests/lib/enhancers/__snapshots__/gh-ui.test.ts.snap @@ -30,13 +30,6 @@ exports[`github ui > gh_issue:should render correct UI elements 1`] = ` exports[`github ui > gh_issue_edit:should render correct UI elements 1`] = ` [ - { - "for": "id=:rc3: name=null className=prc-Textarea-TextArea-13q4j focus-visible overtype-input", - "title": "N/A", - "upperDecoration": - N/A - , - }, { "for": "id=:ra7: name=null className=prc-Textarea-TextArea-13q4j overtype-input", "title": "Description", @@ -65,20 +58,6 @@ exports[`github ui > gh_issue_edit:should render correct UI elements 1`] = ` exports[`github ui > gh_issue_edit_multiple:should render correct UI elements 1`] = ` [ - { - "for": "id=:r76: name=null className=prc-Textarea-TextArea-13q4j overtype-input", - "title": "N/A", - "upperDecoration": - N/A - , - }, - { - "for": "id=:r8k: name=null className=prc-Textarea-TextArea-13q4j focus-visible overtype-input", - "title": "N/A", - "upperDecoration": - N/A - , - }, { "for": "id=:r5b: name=null className=prc-Textarea-TextArea-13q4j overtype-input", "title": "Description", @@ -165,13 +144,6 @@ exports[`github ui > gh_pr:should render correct UI elements 1`] = ` exports[`github ui > gh_pr_edit:should render correct UI elements 1`] = ` [ - { - "for": "id=issue-3429313834-body name=pull_request[body] className=js-comment-field js-paste-markdown js-task-list-field js-quick-submit js-size-to-fit size-to-fit js-session-resumable CommentBox-input FormControl-textarea js-saved-reply-shortcut-comment-field focus-visible overtype-input", - "title": "N/A", - "upperDecoration": - N/A - , - }, { "for": "id=new_comment_field name=comment[body] className=js-comment-field js-paste-markdown js-task-list-field js-quick-submit FormControl-textarea CommentBox-input js-size-to-fit size-to-fit js-session-resumable js-saved-reply-shortcut-comment-field overtype-input", "title": "Feat/expand corpus @@ -202,20 +174,6 @@ exports[`github ui > gh_pr_edit:should render correct UI elements 1`] = ` exports[`github ui > gh_pr_edit_multiple:should render correct UI elements 1`] = ` [ - { - "for": "id=issue-3454672384-body name=pull_request[body] className=js-comment-field js-paste-markdown js-task-list-field js-quick-submit js-size-to-fit size-to-fit js-session-resumable CommentBox-input FormControl-textarea js-saved-reply-shortcut-comment-field overtype-input", - "title": "N/A", - "upperDecoration": - N/A - , - }, - { - "for": "id=issuecomment-3335416053-body name=issue_comment[body] className=js-comment-field js-paste-markdown js-task-list-field js-quick-submit js-size-to-fit size-to-fit js-session-resumable CommentBox-input FormControl-textarea js-saved-reply-shortcut-comment-field focus-visible overtype-input", - "title": "N/A", - "upperDecoration": - N/A - , - }, { "for": "id=new_comment_field name=comment[body] className=js-comment-field js-paste-markdown js-task-list-field js-quick-submit FormControl-textarea CommentBox-input js-size-to-fit size-to-fit js-session-resumable js-saved-reply-shortcut-comment-field overtype-input", "title": "Update README.md @@ -274,17 +232,7 @@ exports[`github ui > gh_project:should render correct UI elements 1`] = `[]`; exports[`github ui > gh_project_draft:should render correct UI elements 1`] = `[]`; -exports[`github ui > gh_project_draft_edit:should render correct UI elements 1`] = ` -[ - { - "for": "id=:r5a: name=null className=prc-Textarea-TextArea-13q4j overtype-input", - "title": "N/A", - "upperDecoration": - N/A - , - }, -] -`; +exports[`github ui > gh_project_draft_edit:should render correct UI elements 1`] = `[]`; exports[`github ui > gh_project_issue:should render correct UI elements 1`] = ` [ @@ -316,13 +264,6 @@ exports[`github ui > gh_project_issue:should render correct UI elements 1`] = ` exports[`github ui > gh_project_issue_edit:should render correct UI elements 1`] = ` [ - { - "for": "id=:rdh: name=null className=prc-Textarea-TextArea-13q4j overtype-input", - "title": "N/A", - "upperDecoration": - N/A - , - }, { "for": "id=:rbs: name=null className=prc-Textarea-TextArea-13q4j overtype-input", "title": "what about drafts?",