diff --git a/src/features/tech-log/application/collect-catalog.ts b/src/features/tech-log/application/collect-catalog.ts new file mode 100644 index 0000000..d284639 --- /dev/null +++ b/src/features/tech-log/application/collect-catalog.ts @@ -0,0 +1,39 @@ +import type { CatalogPage } from "../contracts/studio/contract.ts"; +import type { CatalogQuery, RequestOptions, StudioGateway } from "./ports/studio-gateway.ts"; + +/** 계약이 정한 한 번의 최대치(`Limit.maximum`). 이보다 크게 부르면 서버가 422 로 거절한다. */ +const PAGE_SIZE = 100; + +/** + * 서버가 커서를 계속 주는 경우에 대비한 상한. 100 × 50 이면 5,000건이고, 그 앞에서 화면이 + * 영원히 기다리게 두지 않는다. + */ +const MAX_PAGES = 50; + +/** + * 카탈로그를 끝까지 읽는다. + * + *

화면들은 `limit: 100` 으로 한 번만 부르고 있었다. 100 은 계약의 상한이라 더 크게 부를 수도 + * 없었고, 그래서 기록이 101개가 된 날 101번째부터는 관계 대상 선택에도 작업본 목록의 프로젝트 + * 필터에도 나타나지 않았다 — 고를 수 없는 기록이 아무 표시 없이 생겼다. + * + *

응답에는 `nextCursor` 가 있다. 그것이 빌 때까지 이어 읽는다. + */ +export async function collectCatalog( + gateway: Pick, + query: Omit, + options?: RequestOptions, +): Promise { + const items: CatalogPage["items"][number][] = []; + let cursor: string | undefined; + for (let page = 0; page < MAX_PAGES; page += 1) { + const result: CatalogPage = await gateway.getCatalog( + { ...query, limit: PAGE_SIZE, ...(cursor === undefined ? {} : { cursor }) }, + options, + ); + items.push(...result.items); + if (!result.nextCursor) return items; + cursor = result.nextCursor; + } + return items; +} diff --git a/src/features/tech-log/presentation/studio/components/document-editor-screen.tsx b/src/features/tech-log/presentation/studio/components/document-editor-screen.tsx index b98733f..ec9d3e6 100644 --- a/src/features/tech-log/presentation/studio/components/document-editor-screen.tsx +++ b/src/features/tech-log/presentation/studio/components/document-editor-screen.tsx @@ -1,5 +1,6 @@ import { useCallback, useEffect, useMemo, useState } from "react"; +import { collectCatalog } from "../../../application/collect-catalog.ts"; import { isStudioGatewayError } from "../../../application/ports/studio-gateway-error.ts"; import type { components } from "../../../contracts/studio/generated.ts"; import type { @@ -100,12 +101,13 @@ export function DocumentEditorScreen({ documentId }: { documentId: string }) { void Promise.all([ studio.gateway.getDocument(documentId, { signal: request.signal }), /* - 100 은 계약이 정한 상한이다(`Limit.maximum`). 기록이 그 수를 넘으면 목록 뒤쪽은 여기 - 오지 않으므로, 미리보기가 이 목록에 기대지 않게 따로 고쳤다 — 목록에 없는 관계는 - 그렇게 적고 나머지를 그린다. 고르는 쪽은 관계 편집기의 검색이 맡는다. + 한 번에 받는 상한은 계약이 100으로 정해 두었다(`Limit.maximum`). 그 한 번만 부르던 동안 + 기록이 101개가 되자 101번째부터는 관계 대상 목록에 아예 나타나지 않았고, 화면에는 그 + 사실이 보이지 않았다 — 커서를 따라 끝까지 읽는다. */ - ...catalogTypes.map((type) => studio.gateway.getCatalog( - { type, limit: 100 }, + ...catalogTypes.map((type) => collectCatalog( + studio.gateway, + { type }, { signal: request.signal }, )), ]).then( @@ -113,7 +115,7 @@ export function DocumentEditorScreen({ documentId }: { documentId: string }) { if (request.signal.aborted) return; setResult({ key: requestKey, - catalog: catalogPages.flatMap((page) => page.items), + catalog: catalogPages.flat(), problem: null, }); begin(detail.document, inputOf(detail.document)); diff --git a/src/features/tech-log/presentation/studio/components/document-list.tsx b/src/features/tech-log/presentation/studio/components/document-list.tsx index d56a08a..d91ae2f 100644 --- a/src/features/tech-log/presentation/studio/components/document-list.tsx +++ b/src/features/tech-log/presentation/studio/components/document-list.tsx @@ -2,6 +2,7 @@ import { useEffect, useState, type FormEvent } from "react"; import { useSearchParams } from "react-router-dom"; import { DestructiveConfirmDialog } from "./destructive-confirm-dialog.tsx"; +import { collectCatalog } from "../../../application/collect-catalog.ts"; import type { ListDocumentsQuery } from "../../../application/ports/studio-gateway.ts"; import type { CatalogPage, DocumentPage } from "../../../contracts/studio/contract.ts"; import type { components } from "../../../contracts/studio/generated.ts"; @@ -203,12 +204,10 @@ export function DocumentList() { */ useEffect(() => { const controller = new AbortController(); - void gateway - .getCatalog({ type: "PROJECT", limit: 100 }, { signal: controller.signal }) - .then( - (page) => setProjects(page.items), - () => undefined, - ); + void collectCatalog(gateway, { type: "PROJECT" }, { signal: controller.signal }).then( + (items) => setProjects(items), + () => undefined, + ); return () => controller.abort(); }, [gateway]); @@ -281,7 +280,8 @@ export function DocumentList() { id="studio-search" type="search" value={searchDraft} - placeholder="제목, 요약, slug" + /* 서버가 뒤지는 것은 제목뿐이다(`lower(title) LIKE`). 없는 것을 적어 두지 않는다. */ + placeholder="제목" onChange={(event) => setSearchDraft(event.target.value)} /> diff --git a/src/features/tech-log/presentation/studio/components/project-editor.tsx b/src/features/tech-log/presentation/studio/components/project-editor.tsx index 3f949cc..73096a9 100644 --- a/src/features/tech-log/presentation/studio/components/project-editor.tsx +++ b/src/features/tech-log/presentation/studio/components/project-editor.tsx @@ -7,6 +7,7 @@ import type { ProjectEditResponse, TopicEdit, } from "../../../contracts/management/contract.ts"; +import { collectCatalog } from "../../../application/collect-catalog.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"; @@ -125,14 +126,14 @@ export function ProjectEditor() { managementGateway.getProject(projectId), managementGateway.listProjectActivities(projectId), managementGateway.listTopics(), - gateway.getCatalog({ type: "RELATION", limit: 100 }), + collectCatalog(gateway, { type: "RELATION" }), ]); if (cancelled) return; setProject(loaded); setDraft(toDraft(loaded)); setActivities(activityList); setTopics(topicList.filter((topic) => topic.status !== "ARCHIVED")); - setRecords(catalog.items ?? []); + setRecords(catalog); setError(""); } catch { if (!cancelled) setError("프로젝트를 불러오지 못했습니다."); diff --git a/src/features/tech-log/presentation/studio/components/publication-flow-classes.ts b/src/features/tech-log/presentation/studio/components/publication-flow-classes.ts index 4c5aeba..ea58d7c 100644 --- a/src/features/tech-log/presentation/studio/components/publication-flow-classes.ts +++ b/src/features/tech-log/presentation/studio/components/publication-flow-classes.ts @@ -20,6 +20,7 @@ const publicationFlowClassContract = { success: "studio-publication-success", actions: "studio-publication-actions", filters: "studio-publication-filters", + searchField: "studio-publication-search-field", errorState: "studio-publication-error-state", emptyState: "studio-publication-empty-state", historyList: "studio-publication-history-list", diff --git a/src/features/tech-log/presentation/studio/components/publication-list.tsx b/src/features/tech-log/presentation/studio/components/publication-list.tsx index 0db14f5..93d913b 100644 --- a/src/features/tech-log/presentation/studio/components/publication-list.tsx +++ b/src/features/tech-log/presentation/studio/components/publication-list.tsx @@ -180,16 +180,26 @@ export function PublicationList({

- - + {/* + 검색 버튼은 검색 칸에 붙인다. 셋을 나란한 칸으로 두었더니 격자가 「검색칸 · 버튼 · + 이벤트」로 잘려, 검색칸이 871px 로 벌어지고 이벤트 셀렉트는 91px 로 눌려 「게시 취소」가 + 잘려 보였다. 버튼은 자기가 무엇을 실행하는지 옆에 있을 때 읽힌다. + */} +
+ +
+ setQueryDraft(event.currentTarget.value)} + /* 서버가 실제로 뒤지는 것은 제목뿐이다. 요약을 적어 두면 넣어도 안 나오는 이유를 알 수 없다. */ + placeholder="제목" + /> + +
+