Add optional export filename, tests for post-implement features

Add optional filename field to export dialog with automatic .json
extension handling. Extract resolveFilename() for testability. Add
tests for includeHistory flag, bundleToJson, and filename resolution.
Add export format compatibility note to CLAUDE.md.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Lukas
2026-03-27 15:42:50 +01:00
parent 209df13c32
commit f4355a8675
6 changed files with 105 additions and 8 deletions

View File

@@ -84,12 +84,18 @@ export function bundleToJson(bundle: ExportBundle): string {
return JSON.stringify(bundle, null, 2);
}
export function triggerDownload(bundle: ExportBundle): void {
export function resolveFilename(name?: string): string {
const base =
name?.trim() ||
`initiative-export-${new Date().toISOString().slice(0, 10)}`;
return base.endsWith(".json") ? base : `${base}.json`;
}
export function triggerDownload(bundle: ExportBundle, name?: string): void {
const blob = new Blob([bundleToJson(bundle)], { type: "application/json" });
const url = URL.createObjectURL(blob);
const date = new Date().toISOString().slice(0, 10);
const filename = `initiative-export-${date}.json`;
const filename = resolveFilename(name);
const anchor = document.createElement("a");
anchor.href = url;