fix: tighten decision center query paths
This commit is contained in:
@@ -438,6 +438,14 @@ function diaryQuery(filters: AnyRecord): string {
|
||||
return params.toString();
|
||||
}
|
||||
|
||||
function diaryEntryLookupPath(entry: any): string {
|
||||
const key = entry?.id || entry?.date;
|
||||
const params = new URLSearchParams();
|
||||
if (entry?.sourceFile) params.set("sourceFile", String(entry.sourceFile));
|
||||
const query = params.toString();
|
||||
return `/api/diary/entries/${encodeURIComponent(key)}${query ? `?${query}` : ""}`;
|
||||
}
|
||||
|
||||
function DiaryEntryCard({ entry, selected, onSelect, onRaw }: AnyRecord) {
|
||||
return h("article", { className: `diary-entry-card ${selected ? "selected" : ""}`, "data-testid": `diary-entry-${stableTestId(entry.date || entry.id)}` },
|
||||
h("button", { type: "button", className: "diary-entry-main", onClick: () => onSelect(entry) },
|
||||
@@ -702,7 +710,7 @@ export function DecisionCenterPage({ microservices, onRaw, apiBaseUrl = "/api" }
|
||||
async function selectDiaryEntry(entry: any): Promise<void> {
|
||||
setDiaryState((prev: any) => ({ ...prev, selected: entry }));
|
||||
try {
|
||||
const response = await requestJson(decisionApi(apiBaseUrl, `/api/diary/entries/${encodeURIComponent(entry.date || entry.id)}`));
|
||||
const response = await requestJson(decisionApi(apiBaseUrl, diaryEntryLookupPath(entry)));
|
||||
const selected = response.entry || entry;
|
||||
setDiaryState((prev: any) => ({ ...prev, selected }));
|
||||
setDiaryForm(diaryFormFromEntry(selected));
|
||||
@@ -740,10 +748,18 @@ export function DecisionCenterPage({ microservices, onRaw, apiBaseUrl = "/api" }
|
||||
}));
|
||||
}
|
||||
|
||||
function editRecord(record: any): void {
|
||||
async function editRecord(record: any): Promise<void> {
|
||||
setRecordForm(recordFormFromRecord(record));
|
||||
setRecordSaveState({ saving: false, error: "", message: `正在编辑 ${record?.id || ""}` });
|
||||
setActiveView("records");
|
||||
if (!record?.id || record?.body) return;
|
||||
try {
|
||||
const response = await requestJson(decisionApi(apiBaseUrl, `/api/records/${encodeURIComponent(record.id)}`));
|
||||
const fullRecord = response.record || record;
|
||||
setRecordForm(recordFormFromRecord(fullRecord));
|
||||
} catch (err) {
|
||||
setRecordSaveState({ saving: false, error: errorMessage(err, "记录正文加载失败"), message: "" });
|
||||
}
|
||||
}
|
||||
|
||||
async function saveRecord(event: any): Promise<void> {
|
||||
|
||||
Reference in New Issue
Block a user