From a66316e22d4dad75e9503b3c207321e6884a9094 Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Wed, 16 Sep 2026 01:23:49 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EB=AF=B8=EB=A6=AC=EB=B3=B4=EA=B8=B0?= =?UTF-8?q?=EA=B0=80=20=EC=97=86=EB=8A=94=20=EC=A3=BC=EC=A0=9C=20=ED=95=98?= =?UTF-8?q?=EB=82=98=EB=A1=9C=20=EC=A3=BD=EC=A7=80=20=EC=95=8A=EA=B3=A0,?= =?UTF-8?q?=20=EC=9E=90=EB=A3=8C=EB=8A=94=20=EC=B0=BD=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=EA=B3=A0=EB=A5=B8=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 주제를 보관으로 내리거나 지우면 그 주제를 가리키던 작업본이 즉시 터졌다. 작성자는 「초안을 미리 볼 수 없습니다 / TOPIC catalog entry not found: cf1fe22a…」라는 UUID 만 보고, 무엇을 어디서 고쳐야 하는지 알 수 없었다 — 미리보기가 죽으면 고칠 화면까지 함께 죽는다. 이름 없는 자리로 대신해 문서를 그리고, 무엇이 잘못됐는지는 편집 폼의 그 칸이 말한다. 목록에 없는 값도 셀렉트에 임시 항목으로 남긴다: 남기지 않으면 「선택하지 않음」 으로 보여서, 고른 적 없는 주제 때문에 경고가 뜬다고 읽힌다. 편집 폼 아래에 고를 수 있는 자료가 전부 펼쳐져 있었다. 36개면 36줄이고 줄마다 파일 이름과 삭제 단추가 따라붙어 본문보다 자료 목록이 길었다 — 글을 쓰는 화면이 자료 관리 화면이 되어 있었다. 폼에는 지금 몇 개를 쓰는지와 넣는 단추만 두고, 고르는 일은 창 안에서 한다. 고르기 화면과 관리 화면은 같은 자료를 다루되 하는 일이 다르다. Studio 위쪽은 네 가지 일만 보인다. 목적지 여섯에 구분선을 그어도 처음 들어온 사람은 여섯 중 어디부터 가야 하는지를 스스로 판단해야 했다 — 나뉘어 보이는 것과 적어 보이는 것은 다르다. 그 일 안의 화면은 일을 고른 뒤에 나타나고, 화면이 하나뿐인 일은 이름을 두 번 적지 않는다. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_015c8cBFUaVr7KLVUx6ujz7D --- .../project-public-render-model.ts | 47 +++++++- .../studio/components/asset-picker-dialog.tsx | 108 ++++++++++++++++++ .../studio/components/case-fields.tsx | 5 +- .../components/common-document-fields.tsx | 13 ++- .../studio/components/concept-fields.tsx | 5 +- .../studio/components/setup-fields.tsx | 5 +- .../studio/components/studio-header.tsx | 83 +++++++++----- .../presentation/styles/studio-editor.css | 13 +++ .../tech-log/presentation/styles/studio.css | 21 ++-- tests/features/tech-log/asset-picker.test.tsx | 13 +++ .../preview-survives-missing-topic.test.ts | 90 +++++++++++++++ .../tech-log/studio-shell-smoke.test.tsx | 20 ++-- 12 files changed, 367 insertions(+), 56 deletions(-) create mode 100644 src/features/tech-log/presentation/studio/components/asset-picker-dialog.tsx create mode 100644 tests/features/tech-log/preview-survives-missing-topic.test.ts diff --git a/src/features/tech-log/domain/content-format/project-public-render-model.ts b/src/features/tech-log/domain/content-format/project-public-render-model.ts index 9ebb1f4..54dfe39 100644 --- a/src/features/tech-log/domain/content-format/project-public-render-model.ts +++ b/src/features/tech-log/domain/content-format/project-public-render-model.ts @@ -115,6 +115,16 @@ function catalogEntry( return entry ?? null; } +/** + * 목록에 없는 대상의 자리. + * + *

계약의 `DisplayTarget` 은 비울 수 없다. 이름을 비워 두면 화면은 그 줄을 그리지 않는다 — + * 지어낸 이름을 넣는 것보다 낫다. 지어내면 작성자는 멀쩡한 줄을 보고 아무 문제가 없다고 읽는다. + */ +function placeholderTarget(): CatalogEntry { + return { id: "", type: "TOPIC", label: "", dependencyRevision: "missing" }; +} + function displayTarget( entry: CatalogEntry, ): components["schemas"]["DisplayTarget"] { @@ -232,9 +242,20 @@ export function projectWorkingCopy( context: ProjectionContext, supportsEvidenceKey: SupportsEvidenceKey, ): AuthoringRenderModel { - const topic = catalogEntry(catalog, input.topicId, "TOPIC", true); - const project = catalogEntry(catalog, input.projectId, "PROJECT", false); - if (!topic) fail("TOPIC catalog entry is required"); + /* + 주제와 프로젝트가 목록에 없다고 미리보기를 통째로 버리지 않는다. + + 주제를 보관으로 내리거나 지우면 그 주제를 가리키던 작업본이 즉시 이 자리에서 터졌다 — + 작성자는 「초안을 미리 볼 수 없습니다 / TOPIC catalog entry not found: cf1fe22a…」라는 + UUID 만 보고, 무엇을 고쳐야 하는지도 어디서 고쳐야 하는지도 알 수 없었다. 미리보기가 + 죽으면 고칠 화면까지 함께 죽는다. + + 이름 없는 자리로 대신한다. 맥락 덩어리는 이름이 빈 주제를 그리지 않으므로 화면은 조용히 + 주제 줄만 빠지고, 무엇이 잘못됐는지는 편집 폼의 그 칸이 말한다(`missingTopicIssue`). + */ + const topic = + catalogEntry(catalog, input.topicId, "TOPIC", false, false) ?? placeholderTarget(); + const project = catalogEntry(catalog, input.projectId, "PROJECT", false, false); if (input.kind === "PROJECT_DECISION" && !project) { fail("Decision 은 프로젝트에 속합니다. 기본 정보에서 프로젝트를 골라 주세요."); } @@ -395,3 +416,23 @@ export function projectWorkingCopy( }; } } + + +/** + * 고른 주제가 목록에 없다면 그 사실을 한 문장으로. + * + *

미리보기는 이제 이 경우에 죽지 않고 주제 줄만 비운다. 그러면 작성자에게는 아무 일도 없었던 + * 것처럼 보이므로, 고쳐야 할 칸이 스스로 말해야 한다. + */ +export function missingTopicIssue( + topicId: string | null, + catalog: ReadonlyArray, +): string | null { + if (!topicId) return null; + const found = catalog.some( + (entry) => entry.id === topicId && entry.type === "TOPIC", + ); + return found + ? null + : "고른 주제를 목록에서 찾을 수 없습니다. 보관됐거나 지워진 주제입니다 — 다시 골라 주세요."; +} diff --git a/src/features/tech-log/presentation/studio/components/asset-picker-dialog.tsx b/src/features/tech-log/presentation/studio/components/asset-picker-dialog.tsx new file mode 100644 index 0000000..9436a3c --- /dev/null +++ b/src/features/tech-log/presentation/studio/components/asset-picker-dialog.tsx @@ -0,0 +1,108 @@ +import { useEffect, useRef, useState } from "react"; + +import type { StudioAssetGateway } from "../../../application/ports/studio-asset-gateway.ts"; +import type { Asset } from "../../../contracts/studio/contract.ts"; +import { AssetPicker } from "./asset-picker.tsx"; + +/** 본문이 그림을 가리키는 방법. 이 수를 세면 "지금 몇 개를 쓰는가" 가 나온다. */ +const EVIDENCE_DIRECTIVE = /^:::evidence\b/gmu; + +export function countBodyAssets(bodyMarkdown: string): number { + return bodyMarkdown.match(EVIDENCE_DIRECTIVE)?.length ?? 0; +} + +/** + * 자료는 고르러 들어가는 것이지 폼에 펼쳐 두는 것이 아니다. + * + *

편집 폼 아래에 고를 수 있는 자료가 전부 펼쳐져 있었다. 36개면 36줄이고, 줄마다 파일 이름과 + * 삭제 단추가 따라붙어 본문보다 자료 목록이 길었다 — 좁은 화면에서는 그 덩어리가 여러 줄로 + * 깨지면서 삭제 단추만 따로 떨어지기도 했다. 글을 쓰는 화면이 자료 관리 화면이 되어 있었다. + * + *

폼에는 지금 몇 개를 쓰는지와 넣는 단추만 둔다. 고르는 일은 창 안에서 한다 — 검색과 목록은 + * 그대로 쓰되 글의 흐름을 막지 않는다. + * + *

관리(이름·대체 텍스트·사용처·삭제)는 Asset 화면이 맡는다. 같은 자료를 두 화면이 다루되 + * 하는 일이 다르다: 여기는 글에 넣기, 저기는 관리하기. + */ +export function AssetPickerDialog({ + gateway, + usedCount, + onInsert, + onAssetsObserved, +}: { + gateway: StudioAssetGateway; + /** 본문이 지금 가리키는 자료 수. */ + usedCount: number; + onInsert(directive: string): void; + onAssetsObserved?(assets: readonly Asset[]): void; +}) { + const [open, setOpen] = useState(false); + const dialogRef = useRef(null); + const triggerRef = useRef(null); + + useEffect(() => { + const dialog = dialogRef.current; + if (!dialog) return; + /* + `showModal` 이 없는 환경이 있다(jsdom 이 그렇다). 없으면 창을 그냥 보이는 상태로 둔다 — + 고르지 못하게 막는 것보다 낫다. + */ + if (open) { + if (typeof dialog.showModal === "function") dialog.showModal(); + else dialog.setAttribute("open", ""); + } else if (dialog.open) { + if (typeof dialog.close === "function") dialog.close(); + else dialog.removeAttribute("open"); + } + }, [open]); + + const close = () => { + setOpen(false); + // 닫고 나면 초점이 갈 곳이 있어야 한다. 열었던 단추로 돌려준다. + queueMicrotask(() => triggerRef.current?.focus()); + }; + + return ( +

+

+ {usedCount > 0 ? `본문에서 자료 ${usedCount}개를 씁니다` : "본문에 넣은 자료가 없습니다"} +

+ + + setOpen(false)} + onCancel={close} + > + {/* 창을 그릴 때만 목록을 부른다 — 열지 않은 창이 매번 자료를 받아 올 이유가 없다. */} + {open ? ( +
+
+

본문에 넣을 자료

+ +
+ { + onInsert(directive); + close(); + }} + /> +
+ ) : null} +
+
+ ); +} diff --git a/src/features/tech-log/presentation/studio/components/case-fields.tsx b/src/features/tech-log/presentation/studio/components/case-fields.tsx index 6a01c3b..bd12b9d 100644 --- a/src/features/tech-log/presentation/studio/components/case-fields.tsx +++ b/src/features/tech-log/presentation/studio/components/case-fields.tsx @@ -3,7 +3,8 @@ import { useRef, useState } from "react"; import type { components } from "../../../contracts/studio/generated.ts"; import type { Asset, AssetKind } from "../../../contracts/studio/contract.ts"; import { useStudioAssetGateway } from "../use-studio.ts"; -import { AssetPicker, buildEvidenceDirective } from "./asset-picker.tsx"; +import { buildEvidenceDirective } from "./asset-picker.tsx"; +import { AssetPickerDialog, countBodyAssets } from "./asset-picker-dialog.tsx"; import { AssetUploadDialog } from "./asset-upload-dialog.tsx"; import { MarkdownToolbar } from "./markdown-toolbar.tsx"; import { FieldNotice, type FieldIssue } from "./field-issues.tsx"; @@ -122,7 +123,7 @@ export function CaseFields({ Asset 업로드 - + {uploadOpen ? ( ): void; }) { + const missingTopic = missingTopicIssue(draft.topicId ?? null, topics); + return (

DOCUMENT

기본 정보

@@ -61,7 +64,15 @@ export function CommonDocumentFields({ 남은 자리는 그 옆에 따로 보여 준다. */}