Use records as the backend for a small dashboard, then write the generated report back into Coconut. A local pipeline dashboard plus a pipeline-summary page stamped with report metadata and internal links.
View source
Visualize
Use records as the backend for a small dashboard, then write the generated report back into Coconut. A local pipeline dashboard plus a pipeline-summary page stamped with report metadata and internal links.
Read the codeBefore you run it
Run Write back first so there are deal records to chart.
Use a writable space if you want the generated report saved back.
No charting dependency is required for this script.
What it does
Query the typed deal records.
Group them by stage and calculate summary numbers.
Render a small self-contained HTML dashboard.
Write a markdown summary back into the reports folder.
Patch metadata so the report itself becomes queryable.
Core SDK calls
These are intentionally smaller than the source files. They show the backend shape to copy first.
Aggregate records
const records = await coco.records.query("demo", "deal-memo", { limit: 100 });
const byStage = records.items.reduce((counts, record) => {
const stage = String(record.metadata?.stage ?? "unknown");
counts[stage] = (counts[stage] ?? 0) + 1;
return counts;
}, {} as Record<string, number>);Write the report back
const report = await coco.pages.upsert("demo/reports/pipeline-summary", {
title: "Pipeline summary",
content: renderPipelineMarkdown(byStage),
note: "Regenerated by app",
});
await coco.pages.patchMetadata(report.path, {
set: {
"report-kind": "pipeline-summary",
"record-count": records.items.length,
},
});CLI companion
Use the CLI to inspect or exercise the same backend surface from a terminal while your app code uses the SDK.
coco query --filter 'report-kind=pipeline-summary' --space demo
coco page get demo/reports/pipeline-summary