Skip to content

Commit cbbb585

Browse files
majiayu000claude
andauthored
fix(frontend): ensure attachments are properly linked when creating memos (#5428)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent b7b6583 commit cbbb585

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

web/src/components/MemoEditor/services/memoService.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,21 @@ import { create } from "@bufbuild/protobuf";
22
import { FieldMaskSchema, timestampDate, timestampFromDate } from "@bufbuild/protobuf/wkt";
33
import { isEqual } from "lodash-es";
44
import { memoServiceClient } from "@/connect";
5+
import type { Attachment } from "@/types/proto/api/v1/attachment_service_pb";
6+
import { AttachmentSchema } from "@/types/proto/api/v1/attachment_service_pb";
57
import type { Memo } from "@/types/proto/api/v1/memo_service_pb";
68
import { MemoSchema } from "@/types/proto/api/v1/memo_service_pb";
79
import type { EditorState } from "../state";
810
import { uploadService } from "./uploadService";
911

12+
/**
13+
* Converts attachments to reference format for API requests.
14+
* The backend only needs the attachment name to link it to a memo.
15+
*/
16+
function toAttachmentReferences(attachments: Attachment[]): Attachment[] {
17+
return attachments.map((a) => create(AttachmentSchema, { name: a.name }));
18+
}
19+
1020
function buildUpdateMask(
1121
prevMemo: Memo,
1222
state: EditorState,
@@ -28,7 +38,7 @@ function buildUpdateMask(
2838
}
2939
if (!isEqual(allAttachments, prevMemo.attachments)) {
3040
mask.add("attachments");
31-
patch.attachments = allAttachments;
41+
patch.attachments = toAttachmentReferences(allAttachments);
3242
}
3343
if (!isEqual(state.metadata.relations, prevMemo.relations)) {
3444
mask.add("relations");
@@ -95,7 +105,7 @@ export const memoService = {
95105
const memoData = create(MemoSchema, {
96106
content: state.content,
97107
visibility: state.metadata.visibility,
98-
attachments: allAttachments,
108+
attachments: toAttachmentReferences(allAttachments),
99109
relations: state.metadata.relations,
100110
location: state.metadata.location,
101111
createTime: state.timestamps.createTime ? timestampFromDate(state.timestamps.createTime) : undefined,

0 commit comments

Comments
 (0)