Unverified Commit cbbb585b authored by lif's avatar lif Committed by GitHub

fix(frontend): ensure attachments are properly linked when creating memos (#5428)

Co-authored-by: 's avatarClaude Opus 4.5 <noreply@anthropic.com>
parent b7b65835
...@@ -2,11 +2,21 @@ import { create } from "@bufbuild/protobuf"; ...@@ -2,11 +2,21 @@ import { create } from "@bufbuild/protobuf";
import { FieldMaskSchema, timestampDate, timestampFromDate } from "@bufbuild/protobuf/wkt"; import { FieldMaskSchema, timestampDate, timestampFromDate } from "@bufbuild/protobuf/wkt";
import { isEqual } from "lodash-es"; import { isEqual } from "lodash-es";
import { memoServiceClient } from "@/connect"; import { memoServiceClient } from "@/connect";
import type { Attachment } from "@/types/proto/api/v1/attachment_service_pb";
import { AttachmentSchema } from "@/types/proto/api/v1/attachment_service_pb";
import type { Memo } from "@/types/proto/api/v1/memo_service_pb"; import type { Memo } from "@/types/proto/api/v1/memo_service_pb";
import { MemoSchema } from "@/types/proto/api/v1/memo_service_pb"; import { MemoSchema } from "@/types/proto/api/v1/memo_service_pb";
import type { EditorState } from "../state"; import type { EditorState } from "../state";
import { uploadService } from "./uploadService"; import { uploadService } from "./uploadService";
/**
* Converts attachments to reference format for API requests.
* The backend only needs the attachment name to link it to a memo.
*/
function toAttachmentReferences(attachments: Attachment[]): Attachment[] {
return attachments.map((a) => create(AttachmentSchema, { name: a.name }));
}
function buildUpdateMask( function buildUpdateMask(
prevMemo: Memo, prevMemo: Memo,
state: EditorState, state: EditorState,
...@@ -28,7 +38,7 @@ function buildUpdateMask( ...@@ -28,7 +38,7 @@ function buildUpdateMask(
} }
if (!isEqual(allAttachments, prevMemo.attachments)) { if (!isEqual(allAttachments, prevMemo.attachments)) {
mask.add("attachments"); mask.add("attachments");
patch.attachments = allAttachments; patch.attachments = toAttachmentReferences(allAttachments);
} }
if (!isEqual(state.metadata.relations, prevMemo.relations)) { if (!isEqual(state.metadata.relations, prevMemo.relations)) {
mask.add("relations"); mask.add("relations");
...@@ -95,7 +105,7 @@ export const memoService = { ...@@ -95,7 +105,7 @@ export const memoService = {
const memoData = create(MemoSchema, { const memoData = create(MemoSchema, {
content: state.content, content: state.content,
visibility: state.metadata.visibility, visibility: state.metadata.visibility,
attachments: allAttachments, attachments: toAttachmentReferences(allAttachments),
relations: state.metadata.relations, relations: state.metadata.relations,
location: state.metadata.location, location: state.metadata.location,
createTime: state.timestamps.createTime ? timestampFromDate(state.timestamps.createTime) : undefined, createTime: state.timestamps.createTime ? timestampFromDate(state.timestamps.createTime) : undefined,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment