commit 6111d075fa61679d2a88d62fa666705c0bb37b22
parent c39db27434d32f5ba493c99a67d01c09b80fd8cd
Author: Florian Dold <dold@taler.net>
Date: Thu, 19 Nov 2026 23:22:48 +0100
merchant web UI: show delivery history and test saved schedules
Diffstat:
5 files changed, 237 insertions(+), 30 deletions(-)
diff --git a/packages/taler-merchant-webui/src/api/hooks/useReportsAndStats.ts b/packages/taler-merchant-webui/src/api/hooks/useReportsAndStats.ts
@@ -165,24 +165,6 @@ export function useScheduledReports() {
return res;
};
- const generateReport = async (
- id: string,
- req?: TalerMerchantApi.ReportGenerationRequest,
- ) => {
- if (!token) return;
- if (
- !req ||
- typeof req.report_token !== "string" ||
- !req.report_token.trim()
- ) {
- throw new Error("report_token must be a non-empty string");
- }
- const client = merchantClient(config);
- const res = await client.generateReport(id, req);
- unwrapEmpty(res);
- return res;
- };
-
return {
reports: data || [],
error,
@@ -192,7 +174,6 @@ export function useScheduledReports() {
addReport,
updateReport,
deleteReport,
- generateReport,
};
}
diff --git a/packages/taler-merchant-webui/src/routes/ReportsRoute.tsx b/packages/taler-merchant-webui/src/routes/ReportsRoute.tsx
@@ -17,6 +17,8 @@
import type { VNode } from "preact";
import {
useScheduledReports,
+ useReportDeliveries,
+ useMerchantConfig,
useProductGroups,
useMoneyPots,
} from "../api/hooks.js";
@@ -25,6 +27,8 @@ import {
type ReportsScreenProps,
} from "../screens/ReportsScreen.js";
+import { getMerchantBackendFeatures } from "../api/merchantBackendFeatures.js";
+
export function ReportsRoute({
initialTab,
}: Pick<ReportsScreenProps, "initialTab">): VNode {
@@ -34,7 +38,6 @@ export function ReportsRoute({
resource: reportsResource,
addReport,
deleteReport,
- generateReport,
} = useScheduledReports();
const {
groups,
@@ -53,8 +56,11 @@ export function ReportsRoute({
deletePot,
} = useMoneyPots();
+ const deliveries = useReportDeliveries();
+ const { config } = useMerchantConfig();
return (
<ReportsScreen
+ key={deliveries?.instanceKey}
initialTab={initialTab}
reports={reports}
groups={groups}
@@ -67,7 +73,11 @@ export function ReportsRoute({
isPotsLoading={isPotsLoading}
onAddReport={addReport}
onDeleteReport={deleteReport}
- onGenerateReport={generateReport}
+ deliveries={
+ getMerchantBackendFeatures(config?.version).reportDeliveries
+ ? deliveries
+ : undefined
+ }
onAddGroup={addGroup}
onUpdateGroup={updateGroup}
onDeleteGroup={deleteGroup}
diff --git a/packages/taler-merchant-webui/src/screens/ReportDeliveries.tsx b/packages/taler-merchant-webui/src/screens/ReportDeliveries.tsx
@@ -160,3 +160,111 @@ export function ReportTestDialog({
</Modal>
);
}
+
+export function DeliveryHistory({
+ client,
+ schedule,
+ clear,
+}: {
+ client: ReportDeliveryClient;
+ schedule?: number;
+ clear: () => void;
+}) {
+ const { t } = useTranslation();
+ const [revision, setRevision] = useState(0);
+ const [rows, setRows] = useState<Delivery[]>([]);
+ const [offset, setOffset] = useState<number>();
+ const [error, setError] = useState<unknown>();
+ const [loading, setLoading] = useState(true);
+ const [more, setMore] = useState(false);
+
+ useEffect(() => {
+ let active = true;
+ setLoading(true);
+ setError(undefined);
+ client
+ .list(schedule, offset)
+ .then((page) => {
+ if (!active) return;
+ // A renewed credential may refetch this cursor. Replace its page.
+ setRows((prev) =>
+ offset === undefined
+ ? page
+ : [...prev.filter((row) => row.delivery_id >= offset), ...page],
+ );
+ setMore(page.length === 20);
+ })
+ .catch((err) => {
+ if (active) setError(err);
+ })
+ .finally(() => {
+ if (active) setLoading(false);
+ });
+ return () => {
+ active = false;
+ };
+ }, [client, schedule, offset, revision]);
+
+ return (
+ <section
+ class="space-y-3 rounded-xl border bg-white p-6"
+ id="report-deliveries"
+ >
+ <div class="flex items-center justify-between">
+ <h2 class="font-bold">{t`Recent deliveries`}</h2>
+ <button
+ type="button"
+ class="text-blue-700"
+ disabled={loading}
+ onClick={() => {
+ setOffset(undefined);
+ setRevision((n) => n + 1);
+ }}
+ >{t`Refresh`}</button>
+ </div>
+ {schedule !== undefined && (
+ <p>
+ {t`Reference ${schedule}`}{" "}
+ <button
+ type="button"
+ class="text-blue-700"
+ onClick={clear}
+ >{t`Show all deliveries`}</button>
+ </p>
+ )}
+ {error && (
+ <ApiErrorBanner error={error} title={t`Delivery history unavailable`} />
+ )}
+ {loading && <p role="status">{t`Loading…`}</p>}
+ {!error && !loading && rows.length === 0 && (
+ <p>{t`No deliveries recorded yet.`}</p>
+ )}
+ {rows.map((d) => (
+ <details key={d.delivery_id} class="rounded border p-3 text-sm">
+ <summary class="cursor-pointer">
+ {typeof d.created_at.t_s === "number" &&
+ new Date(d.created_at.t_s * 1000).toLocaleString()}{" "}
+ · {d.origin === "test" ? t`Test` : t`Scheduled`} · {d.description} ·{" "}
+ {d.target_address} · {statusLabel(d.status, t)}
+ </summary>
+ <p>
+ {d.program_section} · {d.mime_type} · {d.data_source}
+ </p>
+ {d.error_code !== undefined && (
+ <p>
+ {d.error_code} {d.error_detail}
+ </p>
+ )}
+ </details>
+ ))}
+ {!error && more && (
+ <button
+ type="button"
+ disabled={loading}
+ class="text-blue-700"
+ onClick={() => setOffset(rows.at(-1)?.delivery_id)}
+ >{t`Load older deliveries`}</button>
+ )}
+ </section>
+ );
+}
diff --git a/packages/taler-merchant-webui/src/screens/ReportsScreen.state.test.tsx b/packages/taler-merchant-webui/src/screens/ReportsScreen.state.test.tsx
@@ -11,7 +11,7 @@ import { test } from "node:test";
import { render } from "preact";
import { act } from "preact/test-utils";
import type { TalerMerchantApi } from "@gnu-taler/taler-util";
-import { ReportTestDialog } from "./ReportDeliveries.js";
+import { ReportTestDialog, DeliveryHistory } from "./ReportDeliveries.js";
import type { ReportDeliveryClient } from "../api/hooks.js";
import { ScheduleReportScreen } from "./ScheduleReportScreen.js";
import { ReportsScreen } from "./ReportsScreen.js";
@@ -440,3 +440,68 @@ test("the test dialog follows a queued delivery to completion", async () => {
await cleanup(root);
}
});
+
+test("delivery history loads older attempts using the last ID and schedule filter", async () => {
+ const root = mount();
+ const pages: Array<[number | undefined, number | undefined]> = [];
+ const client: ReportDeliveryClient = {
+ instanceKey: "demo",
+ get: async () => {
+ throw new Error("Unexpected status lookup");
+ },
+ send: async () => {
+ throw new Error("unexpected send");
+ },
+ list: async (schedule, offset) => {
+ pages.push([schedule, offset]);
+ return Array.from({ length: offset ? 1 : 20 }, (_, i) => ({
+ delivery_id: (offset ?? 22) - i - 1,
+ report_serial: schedule,
+ origin: "scheduled",
+ status: "failed",
+ description: "Weekly sales",
+ target_address: "books@example.test",
+ program_section: "email",
+ mime_type: "application/pdf",
+ data_source: "/private/statistics-report/transactions",
+ created_at: { t_s: 10 },
+ error_code: 1,
+ error_detail: "helper exited",
+ }));
+ },
+ };
+ try {
+ await act(() =>
+ render(
+ <DeliveryHistory client={client} schedule={5} clear={() => {}} />,
+ root,
+ ),
+ );
+ await act(async () => {
+ await settle();
+ });
+ await click(button("Load older deliveries", root));
+ await act(settle);
+ assert.deepEqual(pages, [
+ [5, undefined],
+ [5, 2],
+ ]);
+ assert.equal(root.querySelectorAll("details").length, 21);
+ await act(() =>
+ render(
+ <DeliveryHistory
+ client={{ ...client }}
+ schedule={5}
+ clear={() => {}}
+ />,
+ root,
+ ),
+ );
+ await act(settle);
+ assert.deepEqual(pages.at(-1), [5, 2]);
+ assert.equal(root.querySelectorAll("details").length, 21);
+ assert.match(root.textContent ?? "", /helper exited/);
+ } finally {
+ await cleanup(root);
+ }
+});
diff --git a/packages/taler-merchant-webui/src/screens/ReportsScreen.tsx b/packages/taler-merchant-webui/src/screens/ReportsScreen.tsx
@@ -14,6 +14,8 @@
GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
+import { DeliveryHistory, ReportTestDialog } from "./ReportDeliveries.js";
+import type { ReportDeliveryClient } from "../api/hooks.js";
import { FormActionFooter, useFormFeedback } from "../ui/FormActionFooter.js";
import type { VNode } from "preact";
import { useState } from "preact/hooks";
@@ -85,14 +87,7 @@ export interface ReportsScreenProps {
isPotsLoading?: boolean;
onAddReport?: (r: TalerMerchantApi.ReportAddRequest) => Promise<unknown>;
onDeleteReport?: (serial: string) => Promise<unknown>;
- /**
- * Accepted but unused. `POST /reports/$REPORT_ID` is an internal endpoint of
- * the report generator, gated on a `report_token` the portal is never given,
- * so a "send a test now" button could only ever fail — and the one that used
- * to be here reported success when it did. Kept in the props so the route
- * that supplies it still typechecks.
- */
- onGenerateReport?: (serial: string) => Promise<unknown>;
+ deliveries?: ReportDeliveryClient;
onAddGroup?: (g: TalerMerchantApi.GroupAddRequest) => Promise<unknown>;
onUpdateGroup?: (
serial: string,
@@ -121,6 +116,7 @@ export function ReportsScreen({
isReportsLoading = false,
isGroupsLoading = false,
isPotsLoading = false,
+ deliveries,
onAddReport,
onDeleteReport,
onAddGroup,
@@ -131,6 +127,33 @@ export function ReportsScreen({
onDeletePot,
}: ReportsScreenProps = {}): VNode {
const { t } = useTranslation();
+ const [test, setTest] = useState<TalerMerchantApi.ReportTestRequest>();
+ const [historySchedule, setHistorySchedule] = useState<number>();
+ const [historyRevision, setHistoryRevision] = useState(0);
+ const deliveryActions = (rep: TalerMerchantApi.ReportDetailResponse) =>
+ deliveries && (
+ <>
+ <button
+ type="button"
+ class={rowActionClass}
+ onClick={() =>
+ setTest({
+ type: "scheduled",
+ report_serial: rep.report_serial,
+ target_address: rep.target_address,
+ })
+ }
+ >{t`Send test report`}</button>
+ <button
+ type="button"
+ class={rowActionClass}
+ onClick={() => {
+ setHistorySchedule(rep.report_serial);
+ document.getElementById("report-deliveries")?.scrollIntoView();
+ }}
+ >{t`Recent deliveries`}</button>
+ </>
+ );
// Translators: “beverages_group” is a literal machine-readable identifier;
// translate only the “e.g.” prefix.
const groupIdentifierExample = t`e.g. beverages_group`;
@@ -545,6 +568,7 @@ export function ReportsScreen({
<p class="font-mono text-xs text-gray-500">{t`Reference ${rep.report_serial}`}</p>
</div>
<RowActions label={t`Actions for ${rep.description}`}>
+ {deliveryActions(rep)}
<button
type="button"
onClick={() =>
@@ -619,6 +643,7 @@ export function ReportsScreen({
</td>
<td class="px-3 py-3 text-right whitespace-nowrap">
<RowActions label={t`Actions for ${rep.description}`}>
+ {deliveryActions(rep)}
<button
type="button"
onClick={() =>
@@ -640,6 +665,24 @@ export function ReportsScreen({
</div>
)}
+ {deliveries && activeTab === "scheduled" && (
+ <DeliveryHistory
+ key={`${historySchedule}-${historyRevision}`}
+ client={deliveries}
+ schedule={historySchedule}
+ clear={() => setHistorySchedule(undefined)}
+ />
+ )}
+ {deliveries && test && (
+ <ReportTestDialog
+ client={deliveries}
+ request={test}
+ onClose={() => {
+ setTest(undefined);
+ setHistoryRevision((n) => n + 1);
+ }}
+ />
+ )}
{/* Groupings Tab (Spec 11 § 11.2) */}
{activeTab === "groupings" && (
<div class="space-y-6">