22
33import type { Dashboard } from '@objectstack/spec/ui' ;
44
5+ /**
6+ * Pipeline Dashboard — aggregate view of the sales pipeline.
7+ *
8+ * Demonstrates period-over-period comparison via `compareTo`:
9+ *
10+ * - **Won This Quarter** — metric with `compareTo: 'previousPeriod'`. The
11+ * filter uses `{current_quarter_start}` / `{current_quarter_end}`, so
12+ * the renderer issues a parallel aggregate for Q-1 and shows a delta
13+ * labelled "vs last quarter".
14+ * - **Avg Deal Size YoY** — metric with `compareTo: 'previousYear'` to
15+ * compare against the same window one year prior.
16+ * - **Pipeline Trend (90d)** — line chart with a sliding
17+ * `compareTo: { offset: '90d' }` overlay, rendered as a dashed muted
18+ * series on top of the current 90-day trend.
19+ * - **Opportunities by Stage** / **Pipeline by Industry** — bar / pie
20+ * examples without `compareTo` (pie / donut / funnel ignore overlays
21+ * even if set).
22+ */
523export const PipelineDashboard : Dashboard = {
624 name : 'pipeline_dashboard' ,
725 label : 'Pipeline Dashboard' ,
8- description : 'Aggregate view of the sales pipeline.' ,
26+ description : 'Aggregate view of the sales pipeline with period-over-period comparisons .' ,
927 columns : 12 ,
1028 widgets : [
29+ // --- Row 1: KPI tiles -------------------------------------------------
1130 {
1231 id : 'total_pipeline' ,
1332 type : 'metric' ,
@@ -17,8 +36,63 @@ export const PipelineDashboard: Dashboard = {
1736 aggregate : 'sum' ,
1837 valueField : 'amount' ,
1938 filter : { stage : { $nin : [ 'closed_won' , 'closed_lost' ] } } ,
39+ options : { format : 'currency' , currency : 'USD' } ,
2040 layout : { x : 0 , y : 0 , w : 4 , h : 2 } ,
2141 } ,
42+ {
43+ id : 'won_this_quarter' ,
44+ type : 'metric' ,
45+ title : 'Won This Quarter' ,
46+ description : 'Revenue closed-won in the current quarter, compared to the previous quarter.' ,
47+ object : 'crm_opportunity' ,
48+ aggregate : 'sum' ,
49+ valueField : 'amount' ,
50+ filter : {
51+ stage : 'closed_won' ,
52+ close_date : {
53+ $gte : '{current_quarter_start}' ,
54+ $lte : '{current_quarter_end}' ,
55+ } ,
56+ } ,
57+ compareTo : 'previousPeriod' ,
58+ options : { format : 'currency' , currency : 'USD' } ,
59+ layout : { x : 4 , y : 0 , w : 4 , h : 2 } ,
60+ } ,
61+ {
62+ id : 'avg_deal_size_yoy' ,
63+ type : 'metric' ,
64+ title : 'Avg Deal Size (YoY)' ,
65+ description : 'Average won-deal value this year vs the same window last year.' ,
66+ object : 'crm_opportunity' ,
67+ aggregate : 'avg' ,
68+ valueField : 'amount' ,
69+ filter : {
70+ stage : 'closed_won' ,
71+ close_date : {
72+ $gte : '{current_year_start}' ,
73+ $lte : '{current_year_end}' ,
74+ } ,
75+ } ,
76+ compareTo : 'previousYear' ,
77+ options : { format : 'currency' , currency : 'USD' } ,
78+ layout : { x : 8 , y : 0 , w : 4 , h : 2 } ,
79+ } ,
80+
81+ // --- Row 2: Trend + breakdown ----------------------------------------
82+ {
83+ id : 'pipeline_trend_90d' ,
84+ type : 'line' ,
85+ title : 'Pipeline Trend (90d)' ,
86+ description : 'Daily count of opportunities created in the last 90 days, with a sliding overlay of the prior 90-day window.' ,
87+ object : 'crm_opportunity' ,
88+ aggregate : 'count' ,
89+ categoryField : 'close_date' ,
90+ filter : {
91+ close_date : { $gte : '{90_days_ago}' , $lte : '{today}' } ,
92+ } ,
93+ compareTo : { offset : '90d' } ,
94+ layout : { x : 0 , y : 2 , w : 8 , h : 4 } ,
95+ } ,
2296 {
2397 id : 'opportunities_by_stage' ,
2498 type : 'bar' ,
@@ -27,7 +101,22 @@ export const PipelineDashboard: Dashboard = {
27101 object : 'crm_opportunity' ,
28102 aggregate : 'count' ,
29103 categoryField : 'stage' ,
30- layout : { x : 4 , y : 0 , w : 8 , h : 4 } ,
104+ layout : { x : 8 , y : 2 , w : 4 , h : 4 } ,
105+ } ,
106+
107+ // --- Row 3: Mix breakdown (pie ignores compareTo, even if set) -------
108+ {
109+ id : 'pipeline_by_industry' ,
110+ type : 'pie' ,
111+ title : 'Open Pipeline by Stage ($)' ,
112+ description : 'Open-pipeline revenue split by pipeline stage. Pie/donut/funnel ignore `compareTo`.' ,
113+ object : 'crm_opportunity' ,
114+ aggregate : 'sum' ,
115+ valueField : 'amount' ,
116+ categoryField : 'stage' ,
117+ filter : { stage : { $nin : [ 'closed_won' , 'closed_lost' ] } } ,
118+ layout : { x : 0 , y : 6 , w : 6 , h : 4 } ,
31119 } ,
32120 ] ,
33121} ;
122+
0 commit comments