Fix optimistic comment draft clearing
This commit is contained in:
parent
5e65bb2b92
commit
a7cfbc98f3
3 changed files with 48 additions and 3 deletions
|
|
@ -10,6 +10,7 @@ import { MarkdownEditor, type MarkdownEditorRef, type MentionOption } from "./Ma
|
||||||
import { StatusBadge } from "./StatusBadge";
|
import { StatusBadge } from "./StatusBadge";
|
||||||
import { AgentIcon } from "./AgentIconPicker";
|
import { AgentIcon } from "./AgentIconPicker";
|
||||||
import { formatDateTime } from "../lib/utils";
|
import { formatDateTime } from "../lib/utils";
|
||||||
|
import { restoreSubmittedCommentDraft } from "../lib/comment-submit-draft";
|
||||||
import { PluginSlotOutlet } from "@/plugins/slots";
|
import { PluginSlotOutlet } from "@/plugins/slots";
|
||||||
|
|
||||||
interface CommentWithRunMeta extends IssueComment {
|
interface CommentWithRunMeta extends IssueComment {
|
||||||
|
|
@ -420,17 +421,24 @@ export function CommentThread({
|
||||||
if (!trimmed) return;
|
if (!trimmed) return;
|
||||||
const hasReassignment = enableReassign && reassignTarget !== currentAssigneeValue;
|
const hasReassignment = enableReassign && reassignTarget !== currentAssigneeValue;
|
||||||
const reassignment = hasReassignment ? parseReassignment(reassignTarget) : null;
|
const reassignment = hasReassignment ? parseReassignment(reassignTarget) : null;
|
||||||
|
const submittedBody = trimmed;
|
||||||
|
|
||||||
setSubmitting(true);
|
setSubmitting(true);
|
||||||
|
setBody("");
|
||||||
try {
|
try {
|
||||||
// TODO: wire an explicit "send + interrupt" action through the composer if we expose it in the UI.
|
// TODO: wire an explicit "send + interrupt" action through the composer if we expose it in the UI.
|
||||||
await onAdd(trimmed, reopen ? true : undefined, reassignment ?? undefined);
|
await onAdd(submittedBody, reopen ? true : undefined, reassignment ?? undefined);
|
||||||
setBody("");
|
|
||||||
if (draftKey) clearDraft(draftKey);
|
if (draftKey) clearDraft(draftKey);
|
||||||
setReopen(true);
|
setReopen(true);
|
||||||
setReassignTarget(effectiveSuggestedAssigneeValue);
|
setReassignTarget(effectiveSuggestedAssigneeValue);
|
||||||
} catch {
|
} catch {
|
||||||
// Parent mutation handlers surface the failure and keep the draft intact.
|
setBody((current) =>
|
||||||
|
restoreSubmittedCommentDraft({
|
||||||
|
currentBody: current,
|
||||||
|
submittedBody,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
// Parent mutation handlers surface the failure and the draft is restored for retry.
|
||||||
} finally {
|
} finally {
|
||||||
setSubmitting(false);
|
setSubmitting(false);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
31
ui/src/lib/comment-submit-draft.test.ts
Normal file
31
ui/src/lib/comment-submit-draft.test.ts
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
import { restoreSubmittedCommentDraft } from "./comment-submit-draft";
|
||||||
|
|
||||||
|
describe("restoreSubmittedCommentDraft", () => {
|
||||||
|
it("restores the submitted body when the editor is still empty after a failed request", () => {
|
||||||
|
expect(
|
||||||
|
restoreSubmittedCommentDraft({
|
||||||
|
currentBody: "",
|
||||||
|
submittedBody: "Retry me",
|
||||||
|
}),
|
||||||
|
).toBe("Retry me");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("treats whitespace-only input as empty when restoring a failed draft", () => {
|
||||||
|
expect(
|
||||||
|
restoreSubmittedCommentDraft({
|
||||||
|
currentBody: " ",
|
||||||
|
submittedBody: "Retry me",
|
||||||
|
}),
|
||||||
|
).toBe("Retry me");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("preserves newer input when the user has already typed again", () => {
|
||||||
|
expect(
|
||||||
|
restoreSubmittedCommentDraft({
|
||||||
|
currentBody: "new draft",
|
||||||
|
submittedBody: "Retry me",
|
||||||
|
}),
|
||||||
|
).toBe("new draft");
|
||||||
|
});
|
||||||
|
});
|
||||||
6
ui/src/lib/comment-submit-draft.ts
Normal file
6
ui/src/lib/comment-submit-draft.ts
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
export function restoreSubmittedCommentDraft(params: {
|
||||||
|
currentBody: string;
|
||||||
|
submittedBody: string;
|
||||||
|
}) {
|
||||||
|
return params.currentBody.trim() ? params.currentBody : params.submittedBody;
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue