feat(export): exported report files are named after the person, pair reports after both (BUG-2066)
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DbBXp2Vp62Ur3C7yRWQdSq
This commit is contained in:
@@ -27762,3 +27762,15 @@
|
||||
- 验证与防复发:`frontend/tests/synastry-add-date-time-2062.test.tsx` 断言弹窗用共用控件、没有示例值,填了日期和时间的草稿通过 `isBirthTimeDraftReady`(修复前为 false,已在旧代码上跑过确认),以及每一步缺什么对应哪句提示。用产品样式表把真实弹窗渲染成静态页面在无头浏览器里看过空白和已填两种状态;登录后的真实页面本机起不来,没有看过。
|
||||
- 关联记录:BUG-2051(地点选择器)、BUG-1649 与 issue #144(时间范围的规则)、BUG-2056(保存失败用系统提示;这里是填写校验,留在弹窗里)。
|
||||
- 修复版本:`claude/synastry-add-date-2062`。
|
||||
|
||||
## BUG-2066 | 三种报告导出的文件名看不出是谁的
|
||||
|
||||
- 状态:fixed-pending-verify(待测试环境真机确认)。
|
||||
- 首次发现 / 最近更新:2026-11-20 / 2026-11-20。
|
||||
- 触发与现象:个人报告、年运报告、婚恋合盘导出的文件名只有报告名和日期(「个人报告-日期」「年运报告-日期」「婚恋合盘-日期」)。给几个人各导一份以后,文件夹里分不出哪份是谁的。产品负责人 2026-11-20 提出文件名要带上本人的名字。
|
||||
- 触发条件:任何人导出任意一种报告。
|
||||
- 根因:三个文件名函数只接日期和语言,导出面板没有拿到报告对象的名字。
|
||||
- 修复:`exportFilenameFor(名字, 原文件名)` 把名字放在最前面:「名字-个人报告-日期」「名字-年运报告-日期」「甲与乙-婚恋合盘-日期」(英文版合盘是「A and B-Synastry-report-日期」)。文件名不能用的字符换成「-」,名字超过 40 个字截断,没有名字时文件名不变。导出面板新增 `subjectName`,三个报告页各自传入;原来的三个文件名函数不动。
|
||||
- 验证与防复发:`frontend/tests/export-filename-2066.test.ts` 覆盖三种报告的文件名、非法字符、空名字、超长名字,以及三个报告页都把名字传给导出面板;`annual-md-export-20261113.test.tsx` 里真实点击导出得到的文件名按原值、新值、原因更新。登录后的真实页面本机起不来,没有实际下载过文件。
|
||||
- 关联记录:BUG-1869(年运导出)、BUG-2038(合盘导出里的两个名字)。
|
||||
- 修复版本:`claude/export-filename-2066`。
|
||||
|
||||
@@ -835,6 +835,7 @@ export function AnnualReportExport({ report }: Readonly<{ report: Pick<ReportSta
|
||||
format="annual"
|
||||
editions={{ zh: buildAnnualExportBlocks(snapshot) }}
|
||||
reportDate={snapshot.range.span.match(/^\d{4}-\d{2}-\d{2}\b/)?.[0]}
|
||||
subjectName={snapshot.subject.name}
|
||||
onClose={() => setOpen(false)}
|
||||
/>
|
||||
) : null}
|
||||
|
||||
@@ -749,6 +749,7 @@ export function PersonalReportPage({
|
||||
artifactBirthWindow={state.artifactBirthWindow}
|
||||
english={state.englishEdition === "ready" && state.markdownEn ? { markdown: state.markdownEn, factTables: state.factTablesEn } : null}
|
||||
reportDate={state.createdAt}
|
||||
subjectName={state.subjectDisplayName}
|
||||
language={shown}
|
||||
englishEdition={state.englishEdition}
|
||||
onLanguageChange={switchLanguage}
|
||||
|
||||
@@ -20,6 +20,8 @@ import { Button } from "@/components/ui/button";
|
||||
import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
||||
|
||||
interface ReportActionsProps {
|
||||
/** Whose report this is; leads the exported file name (BUG-2066). */
|
||||
subjectName?: string | null;
|
||||
markdown: string;
|
||||
charts?: ReportDocumentV2["charts"];
|
||||
factTables?: readonly ReportFactTable[];
|
||||
@@ -58,6 +60,7 @@ export function ReportActions({
|
||||
english = null,
|
||||
language = "zh",
|
||||
englishEdition = "legacy",
|
||||
subjectName,
|
||||
onLanguageChange,
|
||||
placement = "bar",
|
||||
}: ReportActionsProps) {
|
||||
@@ -94,6 +97,7 @@ export function ReportActions({
|
||||
initialLanguage={language}
|
||||
englishEdition={englishEdition}
|
||||
reportDate={reportDate}
|
||||
subjectName={subjectName}
|
||||
onClose={() => setExportOpen(false)}
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -5,7 +5,7 @@ import { ChevronRight, X } from "lucide-react";
|
||||
import { detectPrintRestriction } from "@/lib/client-report-export";
|
||||
import { downloadMarkdownReport } from "@/lib/consultation-report-export";
|
||||
import { notifyError, notifyInfo, notifySuccess } from "@/lib/notify";
|
||||
import { exportFilename, joinExportBlocks, type ReportExportBlock } from "@/lib/report-export-blocks";
|
||||
import { exportFilename, exportFilenameFor, joinExportBlocks, type ReportExportBlock } from "@/lib/report-export-blocks";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Checkbox } from "@/components/ui/checkbox";
|
||||
import { Input } from "@/components/ui/input";
|
||||
@@ -58,13 +58,15 @@ export type ReportExportEditions = Readonly<{ zh: readonly ReportExportBlock[];
|
||||
* 导出报告. Desktop slides in from the right; a phone slides up from the bottom.
|
||||
* Pick the edition, then 「整篇报告」 or 「自选章节」. No caption and no file size.
|
||||
*/
|
||||
export function ReportExportDrawer({ editions, initialLanguage = "zh", englishEdition = "legacy", reportDate, format, onClose }: {
|
||||
export function ReportExportDrawer({ editions, initialLanguage = "zh", englishEdition = "legacy", reportDate, format, subjectName, onClose }: {
|
||||
editions: ReportExportEditions;
|
||||
/** The edition the reader is showing; the sheet starts on it. */
|
||||
initialLanguage?: ReportLanguage;
|
||||
englishEdition?: EnglishEditionStatus;
|
||||
reportDate?: string | null;
|
||||
format?: "annual" | "synastry";
|
||||
/** Whose report this is; leads the file name (BUG-2066). A pair report passes one name per edition. */
|
||||
subjectName?: string | null | Readonly<{ zh: string; en: string }>;
|
||||
onClose: () => void;
|
||||
}) {
|
||||
const side = useSyncExternalStore(subscribeExportSheetSide, exportSheetSide, () => "right" as const);
|
||||
@@ -124,7 +126,8 @@ export function ReportExportDrawer({ editions, initialLanguage = "zh", englishEd
|
||||
const filename = format === "annual" ? annualExportFilename(reportDate)
|
||||
: format === "synastry" ? synastryExportFilename(reportDate, language, full)
|
||||
: exportFilename(reportDate, full, language);
|
||||
downloadMarkdownReport(filename, joinExportBlocks(selected));
|
||||
const subject = subjectName && typeof subjectName === "object" ? subjectName[language] : subjectName;
|
||||
downloadMarkdownReport(exportFilenameFor(subject, filename), joinExportBlocks(selected));
|
||||
onClose();
|
||||
notifySuccess("已导出");
|
||||
} catch (cause) {
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
} from "@/lib/synastry-analysis-reader";
|
||||
import { ReportExportButton } from "@/components/personal-report/report-actions";
|
||||
import { ReportExportDrawer } from "@/components/personal-report/report-export-drawer";
|
||||
import { exportPairName } from "@/lib/report-export-blocks";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { notifyError, notifyInfo } from "@/lib/notify";
|
||||
import { useEffect, useState } from "react";
|
||||
@@ -306,6 +307,7 @@ export function SynastryReportView(props: {
|
||||
englishEdition={english ? "ready" : "legacy"}
|
||||
editions={{ zh: exportBlocks("zh"), ...(english ? { en: exportBlocks("en") } : {}) }}
|
||||
reportDate={props.createdAt}
|
||||
subjectName={{ zh: exportPairName(names.a, names.b, "zh"), en: exportPairName(names.a, names.b, "en") }}
|
||||
onClose={() => setExporting(false)}
|
||||
/>
|
||||
) : null}
|
||||
|
||||
@@ -207,6 +207,22 @@ export function exportFilename(reportDate: string | null | undefined, isFull: bo
|
||||
return `${personalReportMarkdownFilename(reportDate)}${isFull ? "" : "-节选"}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* BUG-2066 (产品负责人 2026-11-20): an exported file says whose report it is. The name goes first:
|
||||
* 「林遥-个人报告-2026-11-20」, 「林遥-年运报告-…」, 「林遥与周远-婚恋合盘-…」. Characters a file name cannot
|
||||
* hold become 「-」; a name longer than 40 characters is cut; no name leaves the file name as it was.
|
||||
*/
|
||||
export function exportFilenameFor(subject: string | null | undefined, filename: string): string {
|
||||
const name = (subject ?? "").replace(/[\\/:*?"<>|\u0000-\u001f]+/gu, "-").replace(/\s+/gu, " ").trim().replace(/^[-. ]+|[-. ]+$/gu, "");
|
||||
return name ? `${[...name].slice(0, 40).join("")}-${filename}` : filename;
|
||||
}
|
||||
|
||||
/** The two people of a pair report as one file-name part. */
|
||||
export function exportPairName(a: string | null | undefined, b: string | null | undefined, language: ReportLanguage = "zh"): string {
|
||||
const names = [a, b].map((value) => (value ?? "").trim()).filter(Boolean);
|
||||
return names.join(language === "en" ? " and " : "与");
|
||||
}
|
||||
|
||||
/** UTF-8 bytes of exactly what the download would contain; not a per-character guess. */
|
||||
export function exportByteSize(blocks: readonly ReportExportBlock[]): number {
|
||||
return blocks.length ? new TextEncoder().encode(joinExportBlocks(blocks)).length : 0;
|
||||
|
||||
@@ -133,7 +133,10 @@ test("annual drawer shows two groups and downloads the selected appendix with th
|
||||
await h.event(byLabel("正文", "checkbox"));
|
||||
await h.event(byLabel("计算依据", "checkbox"));
|
||||
await h.event(byText("button", "导出 "));
|
||||
assert.equal(filename, "年运报告-2026-08-04.md");
|
||||
// 原值: "年运报告-2026-08-04.md"
|
||||
// 新值: "虚构甲-年运报告-2026-08-04.md"
|
||||
// 原因: BUG-2066,导出文件名前面带上这份报告是谁的
|
||||
assert.equal(filename, "虚构甲-年运报告-2026-08-04.md");
|
||||
const markdown = await blob?.text();
|
||||
assert.ok(markdown);
|
||||
assert.match(markdown, /技法执行情况[\s\S]*真实案例校准/);
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { readFileSync } from "node:fs";
|
||||
import test from "node:test";
|
||||
|
||||
import { annualExportFilename } from "../src/lib/annual-report-export.ts";
|
||||
import { exportFilename, exportFilenameFor, exportPairName } from "../src/lib/report-export-blocks.ts";
|
||||
import { synastryExportFilename } from "../src/lib/synastry-report-export.ts";
|
||||
|
||||
// BUG-2066 (产品负责人 2026-11-20): the exported file of a personal, annual or pair report says whose it is.
|
||||
const read = (path: string) => readFileSync(new URL(path, import.meta.url), "utf8");
|
||||
|
||||
test("BUG-2066 the person's name leads the file name of all three reports", () => {
|
||||
assert.equal(exportFilenameFor("林遥", exportFilename("2026-11-20", true)), "林遥-个人报告-2026-11-20");
|
||||
assert.equal(exportFilenameFor("Lin Yao", exportFilename("2026-11-20", false, "en")), "Lin Yao-Personal-Report-2026-11-20-excerpt-EN");
|
||||
assert.equal(exportFilenameFor("林遥", annualExportFilename("2026-04-18")), "林遥-年运报告-2026-04-18");
|
||||
assert.equal(exportFilenameFor(exportPairName("林遥", "周远"), synastryExportFilename("2026-11-16T03:00:00Z", "zh", true)), "林遥与周远-婚恋合盘-2026-11-16");
|
||||
assert.equal(exportFilenameFor(exportPairName("Lin", "Zhou", "en"), synastryExportFilename("2026-11-16T03:00:00Z", "en", true)), "Lin and Zhou-Synastry-report-2026-11-16");
|
||||
});
|
||||
|
||||
test("BUG-2066 a name cannot break the file name; no name leaves it as it was", () => {
|
||||
assert.equal(exportFilenameFor("a/b:c*?", "个人报告-2026-11-20"), "a-b-c-个人报告-2026-11-20");
|
||||
assert.equal(exportFilenameFor(" ", "个人报告-2026-11-20"), "个人报告-2026-11-20");
|
||||
assert.equal(exportFilenameFor(undefined, "个人报告-2026-11-20"), "个人报告-2026-11-20");
|
||||
assert.equal(exportFilenameFor("..", "年运报告-2026-04-18"), "年运报告-2026-04-18");
|
||||
assert.equal(exportFilenameFor("名".repeat(80), "x").length, 42);
|
||||
assert.equal(exportPairName("林遥", ""), "林遥");
|
||||
});
|
||||
|
||||
test("BUG-2066 the three report pages pass the name to the export sheet", () => {
|
||||
assert.match(read("../src/components/personal-report/personal-report-page.tsx"), /subjectName=\{state\.subjectDisplayName\}\n\s+language=\{shown\}/u);
|
||||
assert.match(read("../src/components/annual/annual-report-page.tsx"), /subjectName=\{snapshot\.subject\.name\}/u);
|
||||
assert.match(read("../src/components/synastry/synastry-report-view.tsx"), /subjectName=\{\{ zh: exportPairName\(names\.a, names\.b, "zh"\)/u);
|
||||
assert.match(read("../src/components/personal-report/report-export-drawer.tsx"), /downloadMarkdownReport\(exportFilenameFor\(subject, filename\)/u);
|
||||
});
|
||||
Reference in New Issue
Block a user