mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-21 06:10:44 +08:00
desktop: Disallow attachments when editing a draft comment
Drafts are kept in local storage and publish only their bodies, so a file attached while editing one never reached the COB and peers saw a broken link. The draft composer already disallowed attaching; editing didn't.
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
|
||||
import partial from "lodash/partial";
|
||||
|
||||
import { draftAttachmentsDisabled } from "@app/lib/codeComments";
|
||||
import {
|
||||
formatAnchor,
|
||||
formatAnchorLines,
|
||||
@@ -112,6 +113,9 @@
|
||||
resolvedBy={comments.resolvedBy}
|
||||
inline
|
||||
draft={isDraftThread}
|
||||
disableAttachments={isDraftThread
|
||||
? draftAttachmentsDisabled
|
||||
: undefined}
|
||||
origin={comments.threadOrigins?.[thread.root.id]}
|
||||
reactOnComment={isDraftThread ? undefined : comments.reactOnComment}
|
||||
createReply={(comments.canReply ?? true)
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
import type { CommentOwner } from "@app/lib/codeCommentActions";
|
||||
import { commentActions } from "@app/lib/codeCommentActions";
|
||||
import type { CodeComments } from "@app/lib/codeComments";
|
||||
import { draftAttachmentsDisabled } from "@app/lib/codeComments";
|
||||
import { resolutionsByComment } from "@app/lib/commentResolutions";
|
||||
import { STANDALONE_COMMENTS } from "@app/lib/commentSources";
|
||||
import { diffOptions } from "@app/lib/diffOptions.svelte";
|
||||
@@ -525,7 +526,7 @@
|
||||
// to it.)
|
||||
canReply: !draftReview,
|
||||
hideThreadFileHeader: true,
|
||||
disableAttachments: "Publish your review to attach files",
|
||||
disableAttachments: draftAttachmentsDisabled,
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
@@ -48,6 +48,8 @@
|
||||
// activity timeline for the outer rail to connect to.
|
||||
inline?: boolean;
|
||||
draft?: boolean;
|
||||
// See `ExtendedTextarea`.
|
||||
disableAttachments?: boolean | string;
|
||||
origin?: CommentOrigin;
|
||||
// Rendered on the root comment's authorship line while it is hovered. The
|
||||
// replies do not get it: it says something about the thread, not a comment.
|
||||
@@ -73,6 +75,7 @@
|
||||
canResolve = false,
|
||||
inline = false,
|
||||
draft = false,
|
||||
disableAttachments,
|
||||
origin,
|
||||
hoverNote,
|
||||
highlightedCommentId,
|
||||
@@ -220,6 +223,7 @@
|
||||
timestamp={reply.edits[0].timestamp}
|
||||
body={reply.edits.slice(-1)[0].body}
|
||||
embeds={embedMap(reply.embeds)}
|
||||
{disableAttachments}
|
||||
editComment={canModifyComment(reply.author.did) &&
|
||||
editComment?.bind(null, reply.id)}
|
||||
reactOnComment={reactOnComment?.bind(null, reply.id)}
|
||||
@@ -274,6 +278,7 @@
|
||||
timestamp={root.edits.slice(-1)[0].timestamp}
|
||||
body={root.edits.slice(-1)[0].body}
|
||||
embeds={embedMap(root.embeds)}
|
||||
{disableAttachments}
|
||||
editComment={canModifyComment(root.author.did) &&
|
||||
editComment?.bind(null, root.id)}
|
||||
reactOnComment={reactOnComment?.bind(null, root.id)}
|
||||
|
||||
@@ -77,3 +77,8 @@ export interface CodeComments {
|
||||
rid: string;
|
||||
threads: Thread<CodeLocation>[];
|
||||
}
|
||||
|
||||
// Drafts are kept in local storage and publish only their bodies. An
|
||||
// uploaded file stays unreferenced in the repo until a COB lists it, so
|
||||
// the node's `git gc` can prune it, and peers never receive it.
|
||||
export const draftAttachmentsDisabled = "Publish your review to attach files";
|
||||
|
||||
@@ -210,6 +210,7 @@ export const draftReviewStorage = {
|
||||
});
|
||||
},
|
||||
|
||||
// Draft comments have no embeds, see `draftAttachmentsDisabled`.
|
||||
addComment(
|
||||
id: string,
|
||||
comment: {
|
||||
|
||||
@@ -314,3 +314,34 @@ test("changing a review's verdict keeps its embeds", async ({ page, peer }) => {
|
||||
await expect(page.getByRole("button", { name: /Rejected/ })).toBeVisible();
|
||||
expect(await storedEmbeds()).toEqual([embed]);
|
||||
});
|
||||
|
||||
test("files can't be attached when editing a draft review comment", async ({
|
||||
page,
|
||||
peer,
|
||||
}) => {
|
||||
const { rid, patchId } = await createProject(peer);
|
||||
await page.goto(`/repos/${rid}/patches/${patchId}?view=changes`);
|
||||
await page
|
||||
.locator(
|
||||
'[data-unified] [data-column-number="3"]:not([data-line-type="change-deletion"])',
|
||||
)
|
||||
.hover();
|
||||
await page.locator("[data-utility-button]").click();
|
||||
await page.getByPlaceholder("Leave a comment").fill("Loud enough");
|
||||
await page
|
||||
.getByLabel("extended-textarea")
|
||||
.filter({ has: page.getByPlaceholder("Leave a comment") })
|
||||
.getByRole("button", { name: /^Start review/ })
|
||||
.click();
|
||||
|
||||
await page.getByText("Loud enough").hover();
|
||||
const toggle = page.getByTitle("Comment actions").last();
|
||||
await toggle.click();
|
||||
await toggle
|
||||
.locator(`xpath=following::*[@role="button"][normalize-space()="Edit"][1]`)
|
||||
.click();
|
||||
|
||||
await expect(
|
||||
page.locator('[id^="edit-"]').getByRole("button", { name: "Attach" }),
|
||||
).toBeDisabled();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user