Files
tech-log-frontend/src/features/tech-log/presentation/studio/components/topic-editor.tsx
T
DongHyeonkaandClaude Opus 5 bb6eba00db fix: UX 리뷰의 출시 차단 다섯 건을 고친다
B1. 검증·미리보기 화면이 CSS 없이 배포됐다. `workflow.module.css` 를 import
하는 파일이 하나도 없었고, Vite 의 CSS Module 은 import 되어야 번들에 들어간다.
제목이 62px 가 아니라 16px 로 나왔고 미리보기의 링크 두 개가 공백 없이 붙었다.
규칙이 전부 `:global()` 이었으므로 모듈일 이유가 없다 — studio.css 로 옮겼다.

B2. Asset 라이브러리에 스타일이 없고 진입 경로도 없었다. 네 클래스에 규칙이
하나도 없어 key·상태·사용 수가 공백 없이 이어 붙었다. 스무 개짜리 목록에
썸네일도 없어 무엇을 고르는지 눌러 봐야 알았다. 내비게이션에도 없어서 URL 을
직접 쳐야 닿았다 — "정리하는 화면" 에 정리하러 갈 길이 없었다.

B3. 삭제에 확인이 없었다. 문서·주제·프로젝트·릴리즈·Asset 전부 한 번에 영구
삭제였고, 그 「삭제」가 행에서 시각적으로 가장 강한 요소였다(16px/600 빨강).
정작 그 행에서 해야 할 일인 「검증하기」는 13px/400 이었다. 확인 창을 하나
만들어 다섯 곳에 붙이고, 행의 우선순위를 되돌렸다.

B4(일부). robots.txt 가 광고하던 sitemap 이 404 였다. 무엇이 게시됐는지는
서버만 알므로 정적 파일이 아니라 조회로 만든다(백엔드 커밋 참조). robots.txt
가 그 주소를 가리키게 했다.

B5. 라우트 프리픽스 밖 URL 이 nginx 의 맨 `Not Found` 로 끝났다. 404 상태는
그대로 두고 — 크롤러에게 링크가 깨졌다고 말하는 것이 그것이다 — 본문만 앱을
주도록 `error_page 404 @not_found` 를 뒀다.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PTnWufiY9ATv57egkKKVAV
2026-09-09 15:31:05 +09:00

447 lines
18 KiB
TypeScript

import { useCallback, useEffect, useState, type FormEvent } from "react";
import { DestructiveConfirmDialog } from "./destructive-confirm-dialog.tsx";
import type { TopicEdit, TopicVariantEdit } from "../../../contracts/management/contract.ts";
import { managementFailureMessage } from "../../../application/ports/management-gateway-error.ts";
import { useRouteInput } from "../../../../../presentation/routes/route-input.tsx";
import { GuardedStudioLink } from "./guarded-studio-link.tsx";
import { slugFromName } from "./slug-from-name.ts";
import { useSaveShortcut } from "./use-save-shortcut.ts";
import { useStudio } from "../use-studio.ts";
/** 경로 파라미터는 `unknown` 으로 들어온다 — 라우터가 코덱을 통과시킨 값이라도 타입은 좁혀 써야 한다. */
function routeId(value: unknown): string {
return typeof value === "string" ? value : "";
}
type Draft = {
name: string;
slug: string;
description: string;
scope: string;
thesis: string;
variantLabel: string;
};
function toDraft(topic: TopicEdit): Draft {
return {
name: topic.name,
slug: topic.slug,
description: topic.description ?? "",
scope: topic.scope ?? "",
thesis: topic.thesis ?? "",
variantLabel: topic.variantLabel ?? "",
};
}
type VariantDraft = {
slug: string;
title: string;
summary: string;
conclusion: string;
};
const EMPTY_VARIANT: VariantDraft = { slug: "", title: "", summary: "", conclusion: "" };
/**
* 주제 한 편을 편집한다.
*
* <p>「주제·프로젝트」 화면은 주제를 만들고 지울 수만 있었다. 이름과 slug 말고는 쓸 자리가 없어,
* 주제가 답하는 질문(논지)도 축의 이름도 어디에도 적을 수 없었다 — 공개 주제 화면이 그 둘을 읽는데
* 쓸 곳이 없으니 늘 비어 있었다.
*
* <p>축(variant)은 주제 안의 접근/구조 하나다. 인증 경계라면 SPA·BFF·Mediator 가 각각 하나고,
* 각자 만들어 보고 무엇을 알게 됐는지가 다르다. 비교표가 읽는 것은 요약이 아니라 그 결론이다.
*
* <p>새 CSS 를 만들지 않는다 — 프로젝트 편집기와 같은 클래스를 쓰므로 Studio 의 나머지와 같은
* 간격·타이포·색을 따른다.
*/
export function TopicEditor() {
const { params } = useRouteInput<"TECH_LOG_STUDIO_TOPIC_EDIT">();
const topicId = routeId(params.id);
const { managementGateway, setRequestAnnouncement } = useStudio();
const [topic, setTopic] = useState<TopicEdit | null>(null);
const [draft, setDraft] = useState<Draft | null>(null);
const [variants, setVariants] = useState<TopicVariantEdit[]>([]);
const [newVariant, setNewVariant] = useState<VariantDraft>(EMPTY_VARIANT);
const [pending, setPending] = useState(false);
const [error, setError] = useState("");
const [generation, setGeneration] = useState(0);
const reload = useCallback(() => setGeneration((value) => value + 1), []);
useEffect(() => {
let cancelled = false;
// 동기적으로 던지는 호출도 잡는다 — 다른 Studio 편집기와 같은 이유다.
void (async () => {
try {
const [topicList, variantList] = await Promise.all([
managementGateway.listTopics(),
managementGateway.listTopicVariants(topicId),
]);
if (cancelled) return;
const loaded = topicList.find((entry) => entry.id === topicId);
if (!loaded) {
setError("주제를 찾을 수 없습니다.");
return;
}
setTopic(loaded);
setDraft(toDraft(loaded));
setVariants(variantList);
setError("");
} catch {
if (!cancelled) setError("주제를 불러오지 못했습니다.");
}
})();
return () => {
cancelled = true;
};
}, [managementGateway, topicId, generation]);
const update = (patch: Partial<Draft>) =>
setDraft((current) => (current ? { ...current, ...patch } : current));
const save = async (event: FormEvent) => {
event.preventDefault();
if (pending || !topic || !draft || topic.id === undefined || topic.version === undefined) return;
setPending(true);
setError("");
try {
const saved = await managementGateway.updateTopic(topic.id, {
expectedVersion: topic.version,
name: draft.name.trim(),
// slug 는 공개 주소다. 비워 두면 주제 화면에 닿을 수 없으므로 이름에서 만들어 채운다.
slug: draft.slug.trim() || slugFromName(draft.name),
description: draft.description,
scope: draft.scope,
thesis: draft.thesis,
variantLabel: draft.variantLabel.trim(),
});
setRequestAnnouncement(`주제를 버전 ${saved.version}으로 저장했습니다.`);
reload();
} catch (failure) {
setError(managementFailureMessage(failure, "주제를 저장하지 못했습니다."));
} finally {
setPending(false);
}
};
// 폼 제출과 같은 일을 하므로 submit 이벤트를 만들어 보낸다 — 검증·기본값 처리가 한 곳에 남는다.
useSaveShortcut(
() => void save({ preventDefault: () => {} } as FormEvent),
Boolean(topic && draft) && !pending,
);
const addVariant = async (event: FormEvent) => {
event.preventDefault();
if (pending || !newVariant.title.trim()) return;
setPending(true);
setError("");
try {
await managementGateway.createTopicVariant(topicId, {
slug: newVariant.slug.trim() || slugFromName(newVariant.title),
title: newVariant.title.trim(),
summary: newVariant.summary,
conclusion: newVariant.conclusion,
displayOrder: variants.length,
});
setNewVariant(EMPTY_VARIANT);
setRequestAnnouncement(`${newVariant.title} 을(를) 추가했습니다.`);
reload();
} catch (failure) {
setError(managementFailureMessage(failure, "축을 추가하지 못했습니다."));
} finally {
setPending(false);
}
};
const saveVariant = async (variant: TopicVariantEdit) => {
if (pending || variant.id === undefined || variant.version === undefined) return;
setPending(true);
setError("");
try {
await managementGateway.updateTopicVariant(topicId, variant.id, {
expectedVersion: variant.version,
slug: variant.slug,
title: variant.title,
summary: variant.summary,
conclusion: variant.conclusion,
displayOrder: variant.displayOrder,
});
setRequestAnnouncement(`${variant.title} 을(를) 저장했습니다.`);
reload();
} catch (failure) {
setError(managementFailureMessage(failure, "축을 저장하지 못했습니다."));
} finally {
setPending(false);
}
};
/* 축을 지우면 거기 걸려 있던 기록이 그 주제의 공통 기록으로 돌아간다. 되돌릴 수 없으므로 묻는다. */
const [pendingDelete, setPendingDelete] = useState<TopicVariantEdit | null>(null);
const removeVariant = async (variant: TopicVariantEdit) => {
if (pending || variant.id === undefined || variant.version === undefined) return;
setPending(true);
setError("");
try {
await managementGateway.deleteTopicVariant(topicId, variant.id, variant.version);
setRequestAnnouncement(`${variant.title} 을(를) 삭제했습니다.`);
setPendingDelete(null);
reload();
} catch (failure) {
setError(managementFailureMessage(failure, "축을 삭제하지 못했습니다."));
} finally {
setPending(false);
}
};
const patchVariant = (id: string | undefined, patch: Partial<TopicVariantEdit>) =>
setVariants((current) =>
current.map((variant) => (variant.id === id ? { ...variant, ...patch } : variant)),
);
const axisLabel = draft?.variantLabel.trim() || "축";
return (
<div className="studio-page studio-editor-page">
<header className="studio-page-top">
<div className="studio-page-heading">
<p className="studio-eyebrow">TOPIC · VERSION {topic?.version ?? "—"}</p>
<h1>{topic?.name ?? "주제"}</h1>
<p>공개 주제 화면이 여기 값을 그대로 읽습니다.</p>
</div>
<GuardedStudioLink className="studio-primary-action" href="/studio/taxonomy">
주제·프로젝트로
</GuardedStudioLink>
</header>
{error ? (
<p className="studio-screen-error" role="alert">
{error}
</p>
) : null}
{!topic && !error ? (
<p className="studio-loading" role="status">
주제를 불러오는 중입니다.
</p>
) : null}
{topic && draft ? (
<>
<form onSubmit={save}>
<section className="studio-editor-section" aria-labelledby="studio-topic-basics-title">
<div className="studio-editor-section-heading">
<p className="studio-eyebrow">TOPIC</p>
<h2 id="studio-topic-basics-title">기본 정보</h2>
<p>목록과 주제 화면에 그대로 나가는 값입니다.</p>
</div>
<div className="studio-field-grid">
<label className="studio-field studio-field--wide">
<span>이름</span>
<input
value={draft.name}
maxLength={120}
onChange={(event) => update({ name: event.currentTarget.value })}
/>
</label>
<label className="studio-field">
<span>slug</span>
<input
value={draft.slug}
maxLength={100}
placeholder="비우면 이름에서 만듭니다"
onChange={(event) => update({ slug: event.currentTarget.value })}
/>
</label>
{/*
축의 이름은 주제마다 다르다 — 인증 경계에서는 「구조」, 조회 성능에서는
「조회 전략」. 내부 모델 이름(variant)을 화면에 그대로 쓰지 않는다.
*/}
<label className="studio-field">
<span>축 이름</span>
<input
value={draft.variantLabel}
maxLength={40}
placeholder="예: 구조 / 조회 전략 · 비우면 축을 쓰지 않습니다"
onChange={(event) => update({ variantLabel: event.currentTarget.value })}
/>
</label>
<label className="studio-field studio-field--wide">
<span>설명</span>
<input
value={draft.description}
maxLength={300}
placeholder="목록에서 이 주제를 가려내는 한 줄입니다."
onChange={(event) => update({ description: event.currentTarget.value })}
/>
</label>
{/*
논지는 이 주제가 답하는 질문이다. 기록을 합쳐 자동으로 나오는 글이 아니라
사람이 쓰는 글이라, 담을 칸이 없던 동안 주제 화면의 첫 문단이 비어 있었다.
*/}
<label className="studio-field studio-field--wide">
<span>논지 — 이 주제가 답하는 질문</span>
<textarea
value={draft.thesis}
maxLength={2000}
rows={3}
placeholder="공개 주제 화면의 첫 문단입니다. 비우면 설명이 대신 나갑니다."
onChange={(event) => update({ thesis: event.currentTarget.value })}
/>
</label>
<label className="studio-field studio-field--wide">
<span>범위</span>
<input
value={draft.scope}
maxLength={300}
onChange={(event) => update({ scope: event.currentTarget.value })}
/>
</label>
</div>
<div className="studio-editor-actions">
<button className="studio-primary-action" type="submit" disabled={pending}>
저장
</button>
</div>
</section>
</form>
<section className="studio-editor-section" aria-labelledby="studio-topic-variants-title">
<div className="studio-editor-section-heading">
<p className="studio-eyebrow">{axisLabel.toUpperCase()}</p>
<h2 id="studio-topic-variants-title">{`${axisLabel} 목록`}</h2>
<p>
이 주제 안에서 실제로 만들어 본 접근입니다. 어느 축에도 걸리지 않은 기록은 이
주제의 공통 기록으로 읽힙니다.
</p>
</div>
<p className="studio-result-count">{`${variants.length}개의 ${axisLabel}`}</p>
{variants.map((variant) => (
<article className="studio-document-row" key={variant.id ?? variant.slug}>
<div className="studio-field-grid">
<label className="studio-field">
<span>제목</span>
<input
value={variant.title}
maxLength={80}
onChange={(event) =>
patchVariant(variant.id, { title: event.currentTarget.value })
}
/>
</label>
<label className="studio-field">
<span>slug</span>
<input
value={variant.slug}
maxLength={100}
onChange={(event) =>
patchVariant(variant.id, { slug: event.currentTarget.value })
}
/>
</label>
<label className="studio-field studio-field--wide">
<span>요약 — 이것이 무엇인가</span>
<input
value={variant.summary ?? ""}
maxLength={600}
onChange={(event) =>
patchVariant(variant.id, { summary: event.currentTarget.value })
}
/>
</label>
{/*
비교표가 읽는 것은 이 칸이다. 기록의 요약 첫 줄을 잘라 쓰면 안 되는 자리라
따로 둔다 — 요약은 무엇인가를 말하고, 결론은 무엇을 알게 됐는가를 말한다.
*/}
<label className="studio-field studio-field--wide">
<span>결론 — 만들어 보고 무엇을 알게 됐나</span>
<textarea
value={variant.conclusion ?? ""}
maxLength={600}
rows={2}
onChange={(event) =>
patchVariant(variant.id, { conclusion: event.currentTarget.value })
}
/>
</label>
</div>
<div className="studio-editor-actions">
<button
className="studio-primary-action"
type="button"
disabled={pending}
onClick={() => void saveVariant(variant)}
>
저장
</button>
<button
className="studio-danger-action"
type="button"
disabled={pending}
onClick={() => {
setError("");
setPendingDelete(variant);
}}
>
삭제
</button>
</div>
</article>
))}
<form onSubmit={addVariant}>
<div className="studio-field-grid">
<label className="studio-field">
<span>{`새 ${axisLabel} 제목`}</span>
<input
value={newVariant.title}
maxLength={80}
onChange={(event) => {
// 갱신 함수가 돌 때 `currentTarget` 은 이미 null 이다. 먼저 읽어 둔다.
const value = event.currentTarget.value;
setNewVariant((current) => ({ ...current, title: value }));
}}
/>
</label>
<label className="studio-field">
<span>slug</span>
<input
value={newVariant.slug}
maxLength={100}
placeholder="비우면 제목에서 만듭니다"
onChange={(event) => {
// 갱신 함수가 돌 때 `currentTarget` 은 이미 null 이다. 먼저 읽어 둔다.
const value = event.currentTarget.value;
setNewVariant((current) => ({ ...current, slug: value }));
}}
/>
</label>
</div>
<div className="studio-editor-actions">
<button className="studio-primary-action" type="submit" disabled={pending}>
추가
</button>
</div>
</form>
</section>
</>
) : null}
<DestructiveConfirmDialog
open={pendingDelete !== null}
pending={pending}
title="축을 삭제합니다"
targetName={pendingDelete?.title ?? ""}
description="이 축에 걸려 있던 기록은 이 주제의 공통 기록으로 돌아갑니다."
error={error}
onCancel={() => setPendingDelete(null)}
onConfirm={() => {
if (pendingDelete) void removeVariant(pendingDelete);
}}
/>
</div>
);
}