@object-ui/plugin-report 13.1.0 → 14.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -0
- package/dist/index.js +2 -2
- package/dist/index.umd.cjs +1 -1
- package/package.json +12 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,39 @@
|
|
|
1
1
|
# @object-ui/plugin-report
|
|
2
2
|
|
|
3
|
+
## 14.0.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [443360a]
|
|
8
|
+
- Updated dependencies [c70bca7]
|
|
9
|
+
- Updated dependencies [86c69c3]
|
|
10
|
+
- Updated dependencies [05e56ca]
|
|
11
|
+
- Updated dependencies [a44e7b6]
|
|
12
|
+
- Updated dependencies [5971cc4]
|
|
13
|
+
- Updated dependencies [6a74160]
|
|
14
|
+
- @object-ui/core@14.0.0
|
|
15
|
+
- @object-ui/i18n@14.0.0
|
|
16
|
+
- @object-ui/react@14.0.0
|
|
17
|
+
- @object-ui/types@14.0.0
|
|
18
|
+
- @object-ui/plugin-grid@14.0.0
|
|
19
|
+
- @object-ui/components@14.0.0
|
|
20
|
+
- @object-ui/fields@14.0.0
|
|
21
|
+
|
|
22
|
+
## 13.2.0
|
|
23
|
+
|
|
24
|
+
### Patch Changes
|
|
25
|
+
|
|
26
|
+
- Updated dependencies [80901aa]
|
|
27
|
+
- Updated dependencies [53c40c2]
|
|
28
|
+
- Updated dependencies [e492b9d]
|
|
29
|
+
- @object-ui/components@13.2.0
|
|
30
|
+
- @object-ui/plugin-grid@13.2.0
|
|
31
|
+
- @object-ui/i18n@13.2.0
|
|
32
|
+
- @object-ui/fields@13.2.0
|
|
33
|
+
- @object-ui/react@13.2.0
|
|
34
|
+
- @object-ui/types@13.2.0
|
|
35
|
+
- @object-ui/core@13.2.0
|
|
36
|
+
|
|
3
37
|
## 13.1.0
|
|
4
38
|
|
|
5
39
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -225,7 +225,7 @@ function H(e, t) {
|
|
|
225
225
|
return String(e);
|
|
226
226
|
}
|
|
227
227
|
function te(e) {
|
|
228
|
-
return typeof e == "string"
|
|
228
|
+
return typeof e == "string" && /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2})?/.test(e);
|
|
229
229
|
}
|
|
230
230
|
function ne(e) {
|
|
231
231
|
try {
|
|
@@ -531,7 +531,7 @@ function W(e, t) {
|
|
|
531
531
|
function G(e) {
|
|
532
532
|
if (!e || typeof e != "object") return !1;
|
|
533
533
|
let t = e;
|
|
534
|
-
return typeof t.dataset == "string" && t.dataset.length > 0
|
|
534
|
+
return typeof t.dataset == "string" && t.dataset.length > 0 || t.type === "joined" && Array.isArray(t.blocks) && t.blocks.some((e) => typeof e?.dataset == "string");
|
|
535
535
|
}
|
|
536
536
|
function K(e, t) {
|
|
537
537
|
return e ? typeof e == "string" ? e : typeof e == "object" && typeof e.default == "string" ? e.default : t : t;
|
package/dist/index.umd.cjs
CHANGED
|
@@ -55,5 +55,5 @@ ${e.description?`<p class="description">${w(e.description)}</p>`:``}
|
|
|
55
55
|
</body>
|
|
56
56
|
</html>`),o.document.close(),o.onload=()=>{o.print()}}function S(e,t,n){let r=e.fields||[],i=r.map(e=>e.label||e.name),a=t.map(e=>r.map(t=>{let n=e[t.name];return n=T(n),typeof n==`string`&&(n.includes(`,`)||n.includes(`"`)||n.includes(`
|
|
57
57
|
`)||n.includes(` `))?`"${n.replace(/"/g,`""`)}"`:n??``}));O(``+[...n?.includeHeaders===!1?[]:[i.join(` `)],...a.map(e=>e.join(` `))].join(`
|
|
58
|
-
`),n?.filename||`${e.title||`report`}.tsv`,`text/tab-separated-values`)}function C(e,t,n,r){switch(e){case`csv`:v(t,n,r);break;case`json`:y(t,n,r);break;case`html`:b(t,n,r);break;case`pdf`:x(t,n,r);break;case`excel`:S(t,n,r);break;default:console.warn(`Unsupported export format: ${e}`)}}function w(e){return e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`).replace(/'/g,`'`)}function T(e){if(typeof e==`string`&&e.length>0){let t=e.charAt(0);if(t===`=`||t===`+`||t===`-`||t===`@`||t===`|`)return`\t${e}`}return e}function E(e){return[`A4`,`A3`,`Letter`,`Legal`].includes(e||``)?e:`A4`}function D(e){return e===`landscape`?`landscape`:`portrait`}function O(e,t,n){let r=new Blob([e],{type:`${n};charset=utf-8`}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=t,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i)}function k(e,t){if(e==null||e===``)return``;let n=t?.type,r=t?.format;if(n===`date`||r===`date`||A(e))return j(e);if(n===`number`||typeof e==`number`){let t=typeof e==`number`?e:Number(e);return isNaN(t)?String(e):r===`currency`||r===`currency_cny`?`¥${t.toLocaleString(`en-US`,{minimumFractionDigits:0,maximumFractionDigits:0})}`:r===`currency_usd`?`$${t.toLocaleString(`en-US`,{minimumFractionDigits:0,maximumFractionDigits:0})}`:r===`percent`?`${t.toLocaleString(`en-US`,{minimumFractionDigits:1,maximumFractionDigits:1})}%`:t.toLocaleString(`en-US`)}return String(e)}function A(e){return typeof e==`string`?/^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2})?/.test(e):!1}function j(e){try{let t=new Date(e);return isNaN(t.getTime())?String(e):`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,`0`)}-${String(t.getDate()).padStart(2,`0`)}`}catch{return String(e)}}function M(e,t){if(!t||t.length===0||!e||e.length===0)return null;let n=t[0],r=n.field,i=new Map;for(let t of e){let e=String(t[r]??`(empty)`);i.has(e)||i.set(e,[]),i.get(e).push(t)}let a=[];for(let[e,t]of i)a.push({key:e,label:`${n.label||r}: ${e}`,rows:t});let o=n.sort===`desc`?-1:1;return a.sort((e,t)=>e.key.localeCompare(t.key)*o),a}var N=({schema:e,onRefresh:r})=>{let{report:l,data:u,showToolbar:d=!0,allowExport:f=!0,allowPrint:p=!0,loading:m=!1}=e,h=e=>{if(!l){console.warn(`ReportViewer: Cannot export, no report defined`);return}C(e,l,u||[],l.exportConfigs?.[e])},g=()=>{window.print()},_=()=>{r?.()},v=(e,t)=>{if(!u)return 0;let n=u.map(t=>Number(t[e])||0);switch(t){case`count`:return u.length;case`sum`:return n.reduce((e,t)=>e+t,0);case`avg`:return n.length>0?(n.reduce((e,t)=>e+t,0)/n.length).toFixed(2):0;case`min`:return n.length>0?Math.min(...n):0;case`max`:return n.length>0?Math.max(...n):0;default:return``}},y=(e,t)=>{let n=l?.conditionalFormatting;if(!(!n||!Array.isArray(n)))for(let r of n){if(r.field!==e)continue;let n=String(t??``),i=String(r.value??``),a=!1;switch(r.operator){case`equals`:a=n===i;break;case`not_equals`:a=n!==i;break;case`contains`:a=n.includes(i);break;case`greater_than`:a=Number(t)>Number(r.value);break;case`less_than`:a=Number(t)<Number(r.value);break}if(a){let e={};return r.backgroundColor&&(e.backgroundColor=r.backgroundColor),r.textColor&&(e.color=r.textColor),e}}},b=(e,t)=>{if(e==null||e===``)return``;if(t.renderAs===`badge`&&(!t.type||t.type===`string`||t.type===`text`))return(0,o.jsx)(a.Badge,{className:t.colorMap?.[String(e)]||``,children:String(e)});if(t.aggregation)return k(e,t);if(t.type){let n={...t};return t.colorMap&&!n.options&&(n.options=Object.entries(t.colorMap).map(([e,t])=>({value:e,label:e,color:t}))),(0,o.jsx)((0,c.getCellRenderer)((0,c.resolveCellRendererType)(n)),{value:e,field:n})}return k(e,t)};return l?(0,o.jsxs)(`div`,{className:`space-y-4`,children:[d&&(0,o.jsxs)(`div`,{className:`flex items-center justify-between gap-2 p-4 bg-card rounded-lg border`,children:[(0,o.jsxs)(`div`,{children:[(0,o.jsx)(`h2`,{className:`text-lg font-semibold`,children:l.title}),l.description&&(0,o.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:l.description})]}),(0,o.jsxs)(`div`,{className:`flex items-center gap-2`,children:[l.refreshInterval&&(0,o.jsxs)(a.Button,{variant:`outline`,size:`sm`,onClick:_,children:[(0,o.jsx)(s.RefreshCw,{className:`h-4 w-4 mr-2`}),`Refresh`]}),p&&(0,o.jsxs)(a.Button,{variant:`outline`,size:`sm`,onClick:g,children:[(0,o.jsx)(s.Printer,{className:`h-4 w-4 mr-2`}),`Print`]}),f&&l.showExportButtons&&(0,o.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,o.jsxs)(a.Button,{variant:`outline`,size:`sm`,onClick:()=>h(`pdf`),children:[(0,o.jsx)(s.Download,{className:`h-4 w-4 mr-2`}),`PDF`]}),(0,o.jsxs)(a.Button,{variant:`outline`,size:`sm`,onClick:()=>h(`excel`),children:[(0,o.jsx)(s.Download,{className:`h-4 w-4 mr-2`}),`Excel`]}),(0,o.jsxs)(a.Button,{variant:`outline`,size:`sm`,onClick:()=>h(`csv`),children:[(0,o.jsx)(s.Download,{className:`h-4 w-4 mr-2`}),`CSV`]})]})]})]}),(0,o.jsxs)(a.Card,{children:[(0,o.jsxs)(a.CardHeader,{children:[!d&&l.title&&(0,o.jsx)(a.CardTitle,{children:l.title}),!d&&l.description&&(0,o.jsx)(a.CardDescription,{children:l.description})]}),(0,o.jsxs)(a.CardContent,{className:`space-y-6`,children:[m&&(0,o.jsxs)(`div`,{className:`space-y-6`,children:[(0,o.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:[1,2,3].map(e=>(0,o.jsx)(a.Card,{children:(0,o.jsxs)(a.CardContent,{className:`p-4 space-y-2`,children:[(0,o.jsx)(a.Skeleton,{className:`h-4 w-20`}),(0,o.jsx)(a.Skeleton,{className:`h-8 w-28`})]})},e))}),(0,o.jsxs)(`div`,{className:`space-y-2`,children:[(0,o.jsx)(a.Skeleton,{className:`h-10 w-full`}),[1,2,3,4,5].map(e=>(0,o.jsx)(a.Skeleton,{className:`h-8 w-full`},e))]})]}),!m&&l.sections?.map((e,r)=>e.visible===!1?null:(0,o.jsxs)(`div`,{className:`space-y-2`,children:[e.title&&e.type!==`header`&&(0,o.jsx)(`h3`,{className:`text-lg font-semibold border-b pb-2`,children:e.title}),e.type===`header`&&e.title&&(0,o.jsx)(`div`,{className:`text-2xl font-bold py-4`,children:e.title}),e.type===`summary`&&(0,o.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:l.fields?.filter(e=>e.showInSummary).map((e,t)=>(0,o.jsx)(a.Card,{children:(0,o.jsxs)(a.CardContent,{className:`p-4`,children:[(0,o.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:e.label||e.name}),(0,o.jsx)(`div`,{className:`text-2xl font-bold`,children:k(v(e.name,e.aggregation),e)})]})},t))}),e.type===`chart`&&e.chart&&(0,o.jsx)(`div`,{className:`min-h-[300px]`,children:(()=>{let n=e.chart.type,r=!!e.chart.chartType;!n&&r&&(n=`chart`),n&&t.ComponentRegistry.get(n)||(n=`chart`);let a=n===`chart`?{xAxisKey:e.chart.xAxisKey||e.chart.xAxisField||`name`,series:e.chart.series||(e.chart.yAxisFields?e.chart.yAxisFields.map(e=>({dataKey:e})):[]),chartType:e.chart.chartType||`bar`}:{};return(0,o.jsx)(i.SchemaRenderer,{schema:{...e.chart,type:n,...a,data:u||e.chart.data,className:e.chart.className||`w-full h-[350px]`}})})()}),e.type===`table`&&(0,o.jsx)(`div`,{className:`border rounded-lg overflow-x-auto`,children:(0,o.jsxs)(`table`,{className:`w-full text-sm min-w-[600px]`,children:[(0,o.jsx)(`thead`,{className:`bg-muted`,children:(0,o.jsx)(`tr`,{children:e.columns?.map((e,t)=>(0,o.jsx)(`th`,{className:`px-4 py-2 font-medium ${e.type===`number`?`text-right`:`text-left`}`,children:e.label||e.name},t))})}),(0,o.jsx)(`tbody`,{children:(()=>{let t=M(u||[],l.groupBy||[]);return t?t.map(t=>(0,o.jsxs)(n.default.Fragment,{children:[(0,o.jsx)(`tr`,{className:`bg-muted/60`,children:(0,o.jsxs)(`td`,{colSpan:e.columns?.length||1,className:`px-4 py-2 font-semibold text-sm`,children:[t.label,` (`,t.rows.length,`)`]})}),t.rows.map((t,n)=>(0,o.jsx)(`tr`,{className:`border-t hover:bg-muted/50 even:bg-muted/20`,children:e.columns?.map((e,n)=>(0,o.jsx)(`td`,{className:`px-4 py-2 ${e.type===`number`?`text-right tabular-nums`:``}`,style:y(e.name,t[e.name]),children:b(t[e.name],e)},n))},n))]},t.key)):u?.map((t,n)=>(0,o.jsx)(`tr`,{className:`border-t hover:bg-muted/50 even:bg-muted/20`,children:e.columns?.map((e,n)=>(0,o.jsx)(`td`,{className:`px-4 py-2 ${e.type===`number`?`text-right tabular-nums`:``}`,style:y(e.name,t[e.name]),children:b(t[e.name],e)},n))},n))})()})]})}),e.type===`text`&&e.text&&(0,o.jsx)(`div`,{className:`prose max-w-none`,children:(0,o.jsx)(`p`,{children:e.text})}),e.type===`page-break`&&(0,o.jsx)(`div`,{className:`border-t-2 border-dashed my-8 print:page-break-after-always`}),e.content&&(0,o.jsx)(i.SchemaRenderer,{schema:e.content})]},r)),!l.sections&&u&&u.length>0&&(0,o.jsx)(`div`,{className:`border rounded-lg overflow-x-auto`,children:(0,o.jsxs)(`table`,{className:`w-full text-sm min-w-[600px]`,children:[(0,o.jsx)(`thead`,{className:`bg-muted`,children:(0,o.jsx)(`tr`,{children:l.fields?.map((e,t)=>(0,o.jsx)(`th`,{className:`px-4 py-2 font-medium ${e.type===`number`?`text-right`:`text-left`}`,children:e.label||e.name},t))})}),(0,o.jsx)(`tbody`,{children:u.map((e,t)=>(0,o.jsx)(`tr`,{className:`border-t hover:bg-muted/50 even:bg-muted/20`,children:l.fields?.map((t,n)=>(0,o.jsx)(`td`,{className:`px-4 py-2 ${t.type===`number`?`text-right tabular-nums`:``}`,style:y(t.name,e[t.name]),children:b(e[t.name],t)},n))},t))})]})})]})]})]}):(0,o.jsx)(a.Card,{children:(0,o.jsx)(a.CardContent,{className:`p-8 text-center text-muted-foreground`,children:`No report to display`})})};function P(e,t){let n=e&&Object.keys(e).length>0,r=t&&Object.keys(t).length>0;if(n&&r)return{$and:[e,t]};if(n)return e;if(r)return t}function F(e){if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.dataset==`string`&&t.dataset.length>0?!0:t.type===`joined`&&Array.isArray(t.blocks)&&t.blocks.some(e=>typeof e?.dataset==`string`)}function I(e,t){return e?typeof e==`string`?e:typeof e==`object`&&typeof e.default==`string`?e.default:t:t}function L(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`&&!!e):[]}function R(e,t,r,i,a,o){let[s,c]=n.useState({status:`idle`,rows:[]}),l=JSON.stringify(i??null),u=JSON.stringify(o??null),d=`${e}|${t.join(`,`)}|${r.join(`,`)}|${l}|${u}`;return n.useEffect(()=>{let n=a;if(!n||typeof n.queryDataset!=`function`){c({status:`error`,rows:[],error:`This data source does not support dataset queries.`});return}if(!e||r.length===0){c({status:`idle`,rows:[]});return}let s=!1;return c({status:`loading`,rows:[]}),n.queryDataset(e,{dimensions:t,measures:r,...i&&Object.keys(i).length>0?{runtimeFilter:i}:{},...o?{totals:{groupings:o}}:{}}).then(e=>{s||c({status:`ok`,rows:Array.isArray(e?.rows)?e.rows:[],fields:Array.isArray(e?.fields)?e.fields:[],object:e?.object,dimensionFields:e?.dimensionFields,drillRawRows:Array.isArray(e?.drillRawRows)?e.drillRawRows:void 0,totals:Array.isArray(e?.totals)?e.totals:void 0})}).catch(e=>{s||c({status:`error`,rows:[],error:String(e?.message??e)})}),()=>{s=!0}},[d]),s}function z({dataset:e}){return(0,o.jsxs)(`div`,{className:`flex items-center justify-center rounded-md border border-dashed bg-muted/20 p-4 text-xs text-muted-foreground`,children:[`This report binds the “`,e,`” dataset — choose at least one measure (values) to render.`]})}function B({status:e,error:t}){return e===`error`?(0,o.jsxs)(`div`,{role:`alert`,className:`flex items-start gap-2 rounded-md border border-destructive/40 bg-destructive/5 px-3 py-2 text-xs text-destructive`,children:[(0,o.jsx)(s.AlertTriangle,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),(0,o.jsx)(`span`,{className:`break-words`,children:t})]}):(0,o.jsxs)(`div`,{className:`flex items-center gap-2 p-4 text-xs text-muted-foreground`,children:[(0,o.jsx)(s.Loader2,{className:`h-4 w-4 animate-spin`}),` Running report…`]})}function V(){return(0,o.jsxs)(`div`,{className:`flex flex-col items-center justify-center gap-2 rounded-md border border-dashed bg-muted/20 p-6 text-xs text-muted-foreground`,children:[(0,o.jsx)(s.Table2,{className:`h-6 w-6`}),` The dataset returned no rows for this report’s scope.`]})}var H=`cursor-pointer hover:bg-accent/40`;function U({dataset:e,rows:n,values:r,runtimeFilter:i,dataSource:a,onDrill:s}){let c=R(e,n,r,i,a),{fieldLabel:u}=(0,l.useSafeFieldLabel)();if(r.length===0)return(0,o.jsx)(z,{dataset:e});if(c.status===`loading`||c.status===`idle`)return(0,o.jsx)(B,{status:c.status});if(c.status===`error`)return(0,o.jsx)(B,{status:`error`,error:c.error});if(c.rows.length===0)return(0,o.jsx)(V,{});let d=!!s&&n.length>0,f=c.dimensionFields?n.filter(e=>e in c.dimensionFields):[],p=(r,a)=>{let o={};for(let e of n)o[e]=r[e];let l=c.object&&c.dimensionFields&&f.length>0?(0,t.buildDatasetDrillFilter)(c.drillRawRows?.[a],f,c.dimensionFields,i):void 0;s({dataset:e,groupKey:o,runtimeFilter:i,object:c.object,objectFilter:l})},{measureField:m,headerLabel:h}=(0,t.buildDatasetFieldHelpers)(c.fields,c.object,u),g=[...n,...r];return(0,o.jsx)(`div`,{className:`overflow-auto max-h-[70vh] rounded-md border`,children:(0,o.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,o.jsx)(`thead`,{className:`bg-muted/40`,children:(0,o.jsx)(`tr`,{children:g.map(e=>(0,o.jsx)(`th`,{className:`px-2 py-1.5 text-left font-medium whitespace-nowrap`,children:h(e)},e))})}),(0,o.jsx)(`tbody`,{children:c.rows.map((e,n)=>(0,o.jsx)(`tr`,{className:`border-t${d?` ${H}`:``}`,"data-testid":d?`dataset-drill-row`:void 0,onClick:d?()=>p(e,n):void 0,children:g.map(n=>(0,o.jsx)(`td`,{className:`px-2 py-1 tabular-nums whitespace-nowrap`,children:r.includes(n)?(0,t.formatMeasure)(e[n],m(n)?.format,m(n)?.currency):(0,t.formatDimensionValue)(e[n])},n))},n))})]})})}function W(e){switch(e){case`line`:return`line`;case`area`:return`area`;case`pie`:return`pie`;case`donut`:return`donut`;case`radar`:return`radar`;case`scatter`:return`scatter`;default:return`bar`}}function G(e){let[,r]=n.useReducer(e=>e+1,0);return n.useEffect(()=>{if(t.ComponentRegistry.get(e))return;let n=typeof t.ComponentRegistry.subscribe==`function`?t.ComponentRegistry.subscribe(()=>{t.ComponentRegistry.get(e)&&r()}):void 0,i=t.ComponentRegistry.loadLazy?.(e);return i&&typeof i.then==`function`&&i.then(()=>r()).catch(()=>{}),n},[e]),t.ComponentRegistry.get(e)}function K({dataset:e,chart:t,runtimeFilter:n,dataSource:r}){let i=typeof t.xAxis==`string`?t.xAxis:``,a=typeof t.yAxis==`string`?t.yAxis:``,c=R(e,i?[i]:[],a?[a]:[],n,r),l=G(`chart`);if(!i||!a)return null;if(c.status===`loading`||c.status===`idle`)return(0,o.jsxs)(`div`,{className:`flex items-center gap-2 p-4 text-xs text-muted-foreground`,children:[(0,o.jsx)(s.Loader2,{className:`h-4 w-4 animate-spin`}),` Loading chart…`]});if(c.status===`error`||c.rows.length===0||!l)return null;let u=typeof t.title==`string`?t.title:void 0;return(0,o.jsxs)(`div`,{className:`rounded-md border bg-card p-3`,"data-testid":`dataset-report-chart`,children:[u?(0,o.jsx)(`h3`,{className:`mb-2 text-sm font-semibold`,children:u}):null,(0,o.jsx)(l,{schema:{chartType:W(t.type),data:c.rows,xAxisKey:i,series:[{dataKey:a}],height:typeof t.height==`number`?t.height:280,isAnimationActive:!1}})]})}function q(e,t){return e.map(e=>String(t[e]??`∅`)).join(``)}function J(e,n){return e.map(e=>(0,t.formatDimensionValue)(n[e])).join(` / `)}function Y({dataset:e,rows:r,columnsAcross:i,values:a,runtimeFilter:s,dataSource:c,onDrill:u}){let d=R(e,[...r,...i],a,s,c,[r,i,[]]),f=(0,l.useSafeTranslate)(),{fieldLabel:p}=(0,l.useSafeFieldLabel)(),m=n.useMemo(()=>{if(d.status!==`ok`)return null;let e=[],t=[],n=new Set,a=new Set,o=new Map;return d.rows.forEach((s,c)=>{let l=q(r,s),u=q(i,s);if(!n.has(l)){n.add(l);let t={};for(let e of r)t[e]=s[e];e.push({id:l,label:J(r,s),key:t})}if(!a.has(u)){a.add(u);let e={};for(let t of i)e[t]=s[t];t.push({id:u,label:J(i,s),key:e})}o.set(`${l} ${u}`,{row:s,index:c})}),{rowHeaders:e,colHeaders:t,cells:o}},[d,r,i]);if(a.length===0)return(0,o.jsx)(z,{dataset:e});if(d.status===`loading`||d.status===`idle`)return(0,o.jsx)(B,{status:d.status});if(d.status===`error`)return(0,o.jsx)(B,{status:`error`,error:d.error});if(!m||m.rowHeaders.length===0)return(0,o.jsx)(V,{});let{measureField:h,headerLabel:g}=(0,t.buildDatasetFieldHelpers)(d.fields,d.object,p),_=f(`report.total`,`Total`),v=!!u,y=d.dimensionFields?[...r,...i].filter(e=>e in d.dimensionFields):[],b=(n,r,i)=>{let a=d.object&&d.dimensionFields&&y.length>0?(0,t.buildDatasetDrillFilter)(d.drillRawRows?.[i],y,d.dimensionFields,s):void 0;u({dataset:e,groupKey:{...n,...r},runtimeFilter:s,object:d.object,objectFilter:a})},x=m.colHeaders.flatMap(e=>a.map(t=>({col:e,measure:t,header:a.length===1?e.label:`${e.label} · ${g(t)}`}))),S=e=>d.totals?.find(t=>Array.isArray(t.dimensions)&&t.dimensions.join(`,`)===e.join(`,`))?.rows,C=new Map;for(let e of S(r)??[])C.set(q(r,e),e);let w=new Map;for(let e of S(i)??[])w.set(q(i,e),e);let T=S([])?.[0],E=C.size>0,D=w.size>0;return(0,o.jsx)(`div`,{className:`overflow-auto max-h-[70vh] rounded-md border`,"data-testid":`dataset-matrix`,children:(0,o.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,o.jsx)(`thead`,{className:`bg-muted/40`,children:(0,o.jsxs)(`tr`,{children:[r.map(e=>(0,o.jsx)(`th`,{className:`px-2 py-1.5 text-left font-medium whitespace-nowrap`,children:g(e)},e)),x.map(e=>(0,o.jsx)(`th`,{className:`px-2 py-1.5 text-right font-medium whitespace-nowrap`,children:e.header},`${e.col.id}-${e.measure}`)),E&&a.map(e=>(0,o.jsx)(`th`,{className:`px-2 py-1.5 text-right font-medium whitespace-nowrap`,"data-testid":`matrix-total-col-header`,children:a.length===1?_:`${_} · ${g(e)}`},`total-${e}`))]})}),(0,o.jsxs)(`tbody`,{children:[m.rowHeaders.map(e=>(0,o.jsxs)(`tr`,{className:`border-t`,children:[r.map(n=>(0,o.jsx)(`td`,{className:`px-2 py-1 whitespace-nowrap font-medium`,children:(0,t.formatDimensionValue)(e.key[n])},n)),x.map(n=>{let r=m.cells.get(`${e.id} ${n.col.id}`),i=r?.row[n.measure],a=v&&r!=null;return(0,o.jsx)(`td`,{className:`px-2 py-1 text-right tabular-nums whitespace-nowrap${a?` ${H}`:``}`,"data-testid":a?`dataset-drill-cell`:void 0,onClick:a?()=>b(e.key,n.col.key,r.index):void 0,children:(0,t.formatMeasure)(i,h(n.measure)?.format,h(n.measure)?.currency)},`${n.col.id}-${n.measure}`)}),E&&a.map(n=>(0,o.jsx)(`td`,{className:`px-2 py-1 text-right tabular-nums whitespace-nowrap font-medium`,"data-testid":`matrix-row-total`,children:(0,t.formatMeasure)(C.get(e.id)?.[n],h(n)?.format,h(n)?.currency)},`total-${n}`))]},e.id)),D&&(0,o.jsxs)(`tr`,{className:`border-t bg-muted/30 font-medium`,"data-testid":`matrix-total-row`,children:[r.length>0&&(0,o.jsx)(`td`,{colSpan:r.length,className:`px-2 py-1 whitespace-nowrap`,children:_}),x.map(e=>(0,o.jsx)(`td`,{className:`px-2 py-1 text-right tabular-nums whitespace-nowrap`,children:(0,t.formatMeasure)(w.get(e.col.id)?.[e.measure],h(e.measure)?.format,h(e.measure)?.currency)},`${e.col.id}-${e.measure}`)),E&&a.map(e=>(0,o.jsx)(`td`,{className:`px-2 py-1 text-right tabular-nums whitespace-nowrap`,"data-testid":`matrix-grand-total`,children:(0,t.formatMeasure)(T?.[e],h(e)?.format,h(e)?.currency)},`grand-${e}`))]})]})]})})}var X=({report:e,dataSource:t,runtimeFilter:n,onDrill:r,className:i})=>{let a=P(e.runtimeFilter??e.filter,n),s=e.drilldown===!1?void 0:r;if(e.type===`joined`&&Array.isArray(e.blocks))return(0,o.jsx)(`div`,{className:i,"data-testid":`dataset-joined-report`,"data-report-name":e.name,style:{display:`flex`,flexDirection:`column`,gap:24},children:e.blocks.map((e,n)=>{let r=P(a,e.runtimeFilter??e.filter),i=L(e.columns),c=e.type===`matrix`&&i.length>0?(0,o.jsx)(Y,{dataset:String(e.dataset??``),rows:L(e.rows),columnsAcross:i,values:L(e.values),runtimeFilter:r,dataSource:t,onDrill:s}):(0,o.jsx)(U,{dataset:String(e.dataset??``),rows:L(e.rows),values:L(e.values),runtimeFilter:r,dataSource:t,onDrill:s});return(0,o.jsxs)(`section`,{"data-testid":`dataset-report-block`,"data-block-id":e.name??`block-${n}`,className:`flex flex-col gap-2 rounded-lg border bg-card p-4`,children:[(0,o.jsxs)(`header`,{className:`flex flex-col gap-0.5`,children:[(0,o.jsx)(`h3`,{className:`text-sm font-semibold`,children:I(e.label,e.name??`Block ${n+1}`)}),e.description?(0,o.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:I(e.description,``)}):null]}),c]},e.name??`block-${n}`)})});let c=L(e.columns);if(e.type===`matrix`&&c.length>0)return(0,o.jsx)(`div`,{className:i,"data-testid":`dataset-report`,"data-report-name":e.name,children:(0,o.jsx)(Y,{dataset:String(e.dataset??``),rows:L(e.rows),columnsAcross:c,values:L(e.values),runtimeFilter:a,dataSource:t,onDrill:s})});let l=e.chart&&typeof e.chart==`object`&&e.chart.type?e.chart:null;return(0,o.jsxs)(`div`,{className:`${i??``} flex flex-col gap-3`,"data-testid":`dataset-report`,"data-report-name":e.name,children:[l?(0,o.jsx)(K,{dataset:String(e.dataset??``),chart:l,runtimeFilter:a,dataSource:t}):null,(0,o.jsx)(U,{dataset:String(e.dataset??``),rows:L(e.rows),values:L(e.values),runtimeFilter:a,dataSource:t,onDrill:s})]})},Z=e=>{let{dataSource:t,rows:a,runtimeFilter:s,onDrill:c,className:l}=e,u=n.useContext(i.SchemaRendererContext),d=t??u?.dataSource,f=e.schema;return f&&typeof f==`object`&&f.type===`spec-report`&&f.report&&typeof f.report==`object`&&(f=f.report),F(f)?(0,o.jsx)(X,{report:f,dataSource:d,runtimeFilter:s,onDrill:c,className:l}):(0,r.isSpecReport)(f)?(0,o.jsx)(`div`,{className:l,"data-testid":`report-presentation-bridge`,children:(0,o.jsx)(N,{schema:{type:`report-viewer`,report:(0,r.specReportToPresentation)(f),data:a??[],showToolbar:!1}})}):(0,o.jsx)(_,{schema:f})};async function Q(e,t){let{dataSource:n,resource:r,queryParams:i,format:a,exportConfig:o}=t,s=a||e.defaultExportFormat||`pdf`;try{let t=(await n.find(r,i)).data||[];return C(s,e,t,{format:s,...e.exportConfigs?.[s],...o}),{success:!0,recordCount:t.length,format:s}}catch(e){return{success:!1,recordCount:0,format:s,error:e.message}}}function $(e,t,n={}){let{columns:r,filename:i,includeAggregationRow:a=!1}=n,o=r||(e.fields||[]).map(te),s=o.map(e=>e.header),c=t.map((e,t)=>o.map(n=>{if(n.formula)return n.formula.replace(/\{ROW\}/g,String(t+2));let r=e[n.name];return ne(r,n.numberFormat)}));if(a&&t.length>0){let n=o.map((n,r)=>{let i=(e.fields||[]).find(e=>e.name===n.name);if(i?.aggregation){let e=ie(r),n=t.length+1;switch(i.aggregation){case`sum`:return`=SUM(${e}2:${e}${n})`;case`avg`:return`=AVERAGE(${e}2:${e}${n})`;case`count`:return`=COUNTA(${e}2:${e}${n})`;case`min`:return`=MIN(${e}2:${e}${n})`;case`max`:return`=MAX(${e}2:${e}${n})`;default:return``}}return``});c.push(n)}oe(``+[s.join(` `),...c.map(e=>e.join(` `))].join(`
|
|
58
|
+
`),n?.filename||`${e.title||`report`}.tsv`,`text/tab-separated-values`)}function C(e,t,n,r){switch(e){case`csv`:v(t,n,r);break;case`json`:y(t,n,r);break;case`html`:b(t,n,r);break;case`pdf`:x(t,n,r);break;case`excel`:S(t,n,r);break;default:console.warn(`Unsupported export format: ${e}`)}}function w(e){return e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`).replace(/'/g,`'`)}function T(e){if(typeof e==`string`&&e.length>0){let t=e.charAt(0);if(t===`=`||t===`+`||t===`-`||t===`@`||t===`|`)return`\t${e}`}return e}function E(e){return[`A4`,`A3`,`Letter`,`Legal`].includes(e||``)?e:`A4`}function D(e){return e===`landscape`?`landscape`:`portrait`}function O(e,t,n){let r=new Blob([e],{type:`${n};charset=utf-8`}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=t,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i)}function k(e,t){if(e==null||e===``)return``;let n=t?.type,r=t?.format;if(n===`date`||r===`date`||A(e))return j(e);if(n===`number`||typeof e==`number`){let t=typeof e==`number`?e:Number(e);return isNaN(t)?String(e):r===`currency`||r===`currency_cny`?`¥${t.toLocaleString(`en-US`,{minimumFractionDigits:0,maximumFractionDigits:0})}`:r===`currency_usd`?`$${t.toLocaleString(`en-US`,{minimumFractionDigits:0,maximumFractionDigits:0})}`:r===`percent`?`${t.toLocaleString(`en-US`,{minimumFractionDigits:1,maximumFractionDigits:1})}%`:t.toLocaleString(`en-US`)}return String(e)}function A(e){return typeof e==`string`&&/^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2})?/.test(e)}function j(e){try{let t=new Date(e);return isNaN(t.getTime())?String(e):`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,`0`)}-${String(t.getDate()).padStart(2,`0`)}`}catch{return String(e)}}function M(e,t){if(!t||t.length===0||!e||e.length===0)return null;let n=t[0],r=n.field,i=new Map;for(let t of e){let e=String(t[r]??`(empty)`);i.has(e)||i.set(e,[]),i.get(e).push(t)}let a=[];for(let[e,t]of i)a.push({key:e,label:`${n.label||r}: ${e}`,rows:t});let o=n.sort===`desc`?-1:1;return a.sort((e,t)=>e.key.localeCompare(t.key)*o),a}var N=({schema:e,onRefresh:r})=>{let{report:l,data:u,showToolbar:d=!0,allowExport:f=!0,allowPrint:p=!0,loading:m=!1}=e,h=e=>{if(!l){console.warn(`ReportViewer: Cannot export, no report defined`);return}C(e,l,u||[],l.exportConfigs?.[e])},g=()=>{window.print()},_=()=>{r?.()},v=(e,t)=>{if(!u)return 0;let n=u.map(t=>Number(t[e])||0);switch(t){case`count`:return u.length;case`sum`:return n.reduce((e,t)=>e+t,0);case`avg`:return n.length>0?(n.reduce((e,t)=>e+t,0)/n.length).toFixed(2):0;case`min`:return n.length>0?Math.min(...n):0;case`max`:return n.length>0?Math.max(...n):0;default:return``}},y=(e,t)=>{let n=l?.conditionalFormatting;if(!(!n||!Array.isArray(n)))for(let r of n){if(r.field!==e)continue;let n=String(t??``),i=String(r.value??``),a=!1;switch(r.operator){case`equals`:a=n===i;break;case`not_equals`:a=n!==i;break;case`contains`:a=n.includes(i);break;case`greater_than`:a=Number(t)>Number(r.value);break;case`less_than`:a=Number(t)<Number(r.value);break}if(a){let e={};return r.backgroundColor&&(e.backgroundColor=r.backgroundColor),r.textColor&&(e.color=r.textColor),e}}},b=(e,t)=>{if(e==null||e===``)return``;if(t.renderAs===`badge`&&(!t.type||t.type===`string`||t.type===`text`))return(0,o.jsx)(a.Badge,{className:t.colorMap?.[String(e)]||``,children:String(e)});if(t.aggregation)return k(e,t);if(t.type){let n={...t};return t.colorMap&&!n.options&&(n.options=Object.entries(t.colorMap).map(([e,t])=>({value:e,label:e,color:t}))),(0,o.jsx)((0,c.getCellRenderer)((0,c.resolveCellRendererType)(n)),{value:e,field:n})}return k(e,t)};return l?(0,o.jsxs)(`div`,{className:`space-y-4`,children:[d&&(0,o.jsxs)(`div`,{className:`flex items-center justify-between gap-2 p-4 bg-card rounded-lg border`,children:[(0,o.jsxs)(`div`,{children:[(0,o.jsx)(`h2`,{className:`text-lg font-semibold`,children:l.title}),l.description&&(0,o.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:l.description})]}),(0,o.jsxs)(`div`,{className:`flex items-center gap-2`,children:[l.refreshInterval&&(0,o.jsxs)(a.Button,{variant:`outline`,size:`sm`,onClick:_,children:[(0,o.jsx)(s.RefreshCw,{className:`h-4 w-4 mr-2`}),`Refresh`]}),p&&(0,o.jsxs)(a.Button,{variant:`outline`,size:`sm`,onClick:g,children:[(0,o.jsx)(s.Printer,{className:`h-4 w-4 mr-2`}),`Print`]}),f&&l.showExportButtons&&(0,o.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,o.jsxs)(a.Button,{variant:`outline`,size:`sm`,onClick:()=>h(`pdf`),children:[(0,o.jsx)(s.Download,{className:`h-4 w-4 mr-2`}),`PDF`]}),(0,o.jsxs)(a.Button,{variant:`outline`,size:`sm`,onClick:()=>h(`excel`),children:[(0,o.jsx)(s.Download,{className:`h-4 w-4 mr-2`}),`Excel`]}),(0,o.jsxs)(a.Button,{variant:`outline`,size:`sm`,onClick:()=>h(`csv`),children:[(0,o.jsx)(s.Download,{className:`h-4 w-4 mr-2`}),`CSV`]})]})]})]}),(0,o.jsxs)(a.Card,{children:[(0,o.jsxs)(a.CardHeader,{children:[!d&&l.title&&(0,o.jsx)(a.CardTitle,{children:l.title}),!d&&l.description&&(0,o.jsx)(a.CardDescription,{children:l.description})]}),(0,o.jsxs)(a.CardContent,{className:`space-y-6`,children:[m&&(0,o.jsxs)(`div`,{className:`space-y-6`,children:[(0,o.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:[1,2,3].map(e=>(0,o.jsx)(a.Card,{children:(0,o.jsxs)(a.CardContent,{className:`p-4 space-y-2`,children:[(0,o.jsx)(a.Skeleton,{className:`h-4 w-20`}),(0,o.jsx)(a.Skeleton,{className:`h-8 w-28`})]})},e))}),(0,o.jsxs)(`div`,{className:`space-y-2`,children:[(0,o.jsx)(a.Skeleton,{className:`h-10 w-full`}),[1,2,3,4,5].map(e=>(0,o.jsx)(a.Skeleton,{className:`h-8 w-full`},e))]})]}),!m&&l.sections?.map((e,r)=>e.visible===!1?null:(0,o.jsxs)(`div`,{className:`space-y-2`,children:[e.title&&e.type!==`header`&&(0,o.jsx)(`h3`,{className:`text-lg font-semibold border-b pb-2`,children:e.title}),e.type===`header`&&e.title&&(0,o.jsx)(`div`,{className:`text-2xl font-bold py-4`,children:e.title}),e.type===`summary`&&(0,o.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:l.fields?.filter(e=>e.showInSummary).map((e,t)=>(0,o.jsx)(a.Card,{children:(0,o.jsxs)(a.CardContent,{className:`p-4`,children:[(0,o.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:e.label||e.name}),(0,o.jsx)(`div`,{className:`text-2xl font-bold`,children:k(v(e.name,e.aggregation),e)})]})},t))}),e.type===`chart`&&e.chart&&(0,o.jsx)(`div`,{className:`min-h-[300px]`,children:(()=>{let n=e.chart.type,r=!!e.chart.chartType;!n&&r&&(n=`chart`),n&&t.ComponentRegistry.get(n)||(n=`chart`);let a=n===`chart`?{xAxisKey:e.chart.xAxisKey||e.chart.xAxisField||`name`,series:e.chart.series||(e.chart.yAxisFields?e.chart.yAxisFields.map(e=>({dataKey:e})):[]),chartType:e.chart.chartType||`bar`}:{};return(0,o.jsx)(i.SchemaRenderer,{schema:{...e.chart,type:n,...a,data:u||e.chart.data,className:e.chart.className||`w-full h-[350px]`}})})()}),e.type===`table`&&(0,o.jsx)(`div`,{className:`border rounded-lg overflow-x-auto`,children:(0,o.jsxs)(`table`,{className:`w-full text-sm min-w-[600px]`,children:[(0,o.jsx)(`thead`,{className:`bg-muted`,children:(0,o.jsx)(`tr`,{children:e.columns?.map((e,t)=>(0,o.jsx)(`th`,{className:`px-4 py-2 font-medium ${e.type===`number`?`text-right`:`text-left`}`,children:e.label||e.name},t))})}),(0,o.jsx)(`tbody`,{children:(()=>{let t=M(u||[],l.groupBy||[]);return t?t.map(t=>(0,o.jsxs)(n.default.Fragment,{children:[(0,o.jsx)(`tr`,{className:`bg-muted/60`,children:(0,o.jsxs)(`td`,{colSpan:e.columns?.length||1,className:`px-4 py-2 font-semibold text-sm`,children:[t.label,` (`,t.rows.length,`)`]})}),t.rows.map((t,n)=>(0,o.jsx)(`tr`,{className:`border-t hover:bg-muted/50 even:bg-muted/20`,children:e.columns?.map((e,n)=>(0,o.jsx)(`td`,{className:`px-4 py-2 ${e.type===`number`?`text-right tabular-nums`:``}`,style:y(e.name,t[e.name]),children:b(t[e.name],e)},n))},n))]},t.key)):u?.map((t,n)=>(0,o.jsx)(`tr`,{className:`border-t hover:bg-muted/50 even:bg-muted/20`,children:e.columns?.map((e,n)=>(0,o.jsx)(`td`,{className:`px-4 py-2 ${e.type===`number`?`text-right tabular-nums`:``}`,style:y(e.name,t[e.name]),children:b(t[e.name],e)},n))},n))})()})]})}),e.type===`text`&&e.text&&(0,o.jsx)(`div`,{className:`prose max-w-none`,children:(0,o.jsx)(`p`,{children:e.text})}),e.type===`page-break`&&(0,o.jsx)(`div`,{className:`border-t-2 border-dashed my-8 print:page-break-after-always`}),e.content&&(0,o.jsx)(i.SchemaRenderer,{schema:e.content})]},r)),!l.sections&&u&&u.length>0&&(0,o.jsx)(`div`,{className:`border rounded-lg overflow-x-auto`,children:(0,o.jsxs)(`table`,{className:`w-full text-sm min-w-[600px]`,children:[(0,o.jsx)(`thead`,{className:`bg-muted`,children:(0,o.jsx)(`tr`,{children:l.fields?.map((e,t)=>(0,o.jsx)(`th`,{className:`px-4 py-2 font-medium ${e.type===`number`?`text-right`:`text-left`}`,children:e.label||e.name},t))})}),(0,o.jsx)(`tbody`,{children:u.map((e,t)=>(0,o.jsx)(`tr`,{className:`border-t hover:bg-muted/50 even:bg-muted/20`,children:l.fields?.map((t,n)=>(0,o.jsx)(`td`,{className:`px-4 py-2 ${t.type===`number`?`text-right tabular-nums`:``}`,style:y(t.name,e[t.name]),children:b(e[t.name],t)},n))},t))})]})})]})]})]}):(0,o.jsx)(a.Card,{children:(0,o.jsx)(a.CardContent,{className:`p-8 text-center text-muted-foreground`,children:`No report to display`})})};function P(e,t){let n=e&&Object.keys(e).length>0,r=t&&Object.keys(t).length>0;if(n&&r)return{$and:[e,t]};if(n)return e;if(r)return t}function F(e){if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.dataset==`string`&&t.dataset.length>0||t.type===`joined`&&Array.isArray(t.blocks)&&t.blocks.some(e=>typeof e?.dataset==`string`)}function I(e,t){return e?typeof e==`string`?e:typeof e==`object`&&typeof e.default==`string`?e.default:t:t}function L(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`&&!!e):[]}function R(e,t,r,i,a,o){let[s,c]=n.useState({status:`idle`,rows:[]}),l=JSON.stringify(i??null),u=JSON.stringify(o??null),d=`${e}|${t.join(`,`)}|${r.join(`,`)}|${l}|${u}`;return n.useEffect(()=>{let n=a;if(!n||typeof n.queryDataset!=`function`){c({status:`error`,rows:[],error:`This data source does not support dataset queries.`});return}if(!e||r.length===0){c({status:`idle`,rows:[]});return}let s=!1;return c({status:`loading`,rows:[]}),n.queryDataset(e,{dimensions:t,measures:r,...i&&Object.keys(i).length>0?{runtimeFilter:i}:{},...o?{totals:{groupings:o}}:{}}).then(e=>{s||c({status:`ok`,rows:Array.isArray(e?.rows)?e.rows:[],fields:Array.isArray(e?.fields)?e.fields:[],object:e?.object,dimensionFields:e?.dimensionFields,drillRawRows:Array.isArray(e?.drillRawRows)?e.drillRawRows:void 0,totals:Array.isArray(e?.totals)?e.totals:void 0})}).catch(e=>{s||c({status:`error`,rows:[],error:String(e?.message??e)})}),()=>{s=!0}},[d]),s}function z({dataset:e}){return(0,o.jsxs)(`div`,{className:`flex items-center justify-center rounded-md border border-dashed bg-muted/20 p-4 text-xs text-muted-foreground`,children:[`This report binds the “`,e,`” dataset — choose at least one measure (values) to render.`]})}function B({status:e,error:t}){return e===`error`?(0,o.jsxs)(`div`,{role:`alert`,className:`flex items-start gap-2 rounded-md border border-destructive/40 bg-destructive/5 px-3 py-2 text-xs text-destructive`,children:[(0,o.jsx)(s.AlertTriangle,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),(0,o.jsx)(`span`,{className:`break-words`,children:t})]}):(0,o.jsxs)(`div`,{className:`flex items-center gap-2 p-4 text-xs text-muted-foreground`,children:[(0,o.jsx)(s.Loader2,{className:`h-4 w-4 animate-spin`}),` Running report…`]})}function V(){return(0,o.jsxs)(`div`,{className:`flex flex-col items-center justify-center gap-2 rounded-md border border-dashed bg-muted/20 p-6 text-xs text-muted-foreground`,children:[(0,o.jsx)(s.Table2,{className:`h-6 w-6`}),` The dataset returned no rows for this report’s scope.`]})}var H=`cursor-pointer hover:bg-accent/40`;function U({dataset:e,rows:n,values:r,runtimeFilter:i,dataSource:a,onDrill:s}){let c=R(e,n,r,i,a),{fieldLabel:u}=(0,l.useSafeFieldLabel)();if(r.length===0)return(0,o.jsx)(z,{dataset:e});if(c.status===`loading`||c.status===`idle`)return(0,o.jsx)(B,{status:c.status});if(c.status===`error`)return(0,o.jsx)(B,{status:`error`,error:c.error});if(c.rows.length===0)return(0,o.jsx)(V,{});let d=!!s&&n.length>0,f=c.dimensionFields?n.filter(e=>e in c.dimensionFields):[],p=(r,a)=>{let o={};for(let e of n)o[e]=r[e];let l=c.object&&c.dimensionFields&&f.length>0?(0,t.buildDatasetDrillFilter)(c.drillRawRows?.[a],f,c.dimensionFields,i):void 0;s({dataset:e,groupKey:o,runtimeFilter:i,object:c.object,objectFilter:l})},{measureField:m,headerLabel:h}=(0,t.buildDatasetFieldHelpers)(c.fields,c.object,u),g=[...n,...r];return(0,o.jsx)(`div`,{className:`overflow-auto max-h-[70vh] rounded-md border`,children:(0,o.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,o.jsx)(`thead`,{className:`bg-muted/40`,children:(0,o.jsx)(`tr`,{children:g.map(e=>(0,o.jsx)(`th`,{className:`px-2 py-1.5 text-left font-medium whitespace-nowrap`,children:h(e)},e))})}),(0,o.jsx)(`tbody`,{children:c.rows.map((e,n)=>(0,o.jsx)(`tr`,{className:`border-t${d?` ${H}`:``}`,"data-testid":d?`dataset-drill-row`:void 0,onClick:d?()=>p(e,n):void 0,children:g.map(n=>(0,o.jsx)(`td`,{className:`px-2 py-1 tabular-nums whitespace-nowrap`,children:r.includes(n)?(0,t.formatMeasure)(e[n],m(n)?.format,m(n)?.currency):(0,t.formatDimensionValue)(e[n])},n))},n))})]})})}function W(e){switch(e){case`line`:return`line`;case`area`:return`area`;case`pie`:return`pie`;case`donut`:return`donut`;case`radar`:return`radar`;case`scatter`:return`scatter`;default:return`bar`}}function G(e){let[,r]=n.useReducer(e=>e+1,0);return n.useEffect(()=>{if(t.ComponentRegistry.get(e))return;let n=typeof t.ComponentRegistry.subscribe==`function`?t.ComponentRegistry.subscribe(()=>{t.ComponentRegistry.get(e)&&r()}):void 0,i=t.ComponentRegistry.loadLazy?.(e);return i&&typeof i.then==`function`&&i.then(()=>r()).catch(()=>{}),n},[e]),t.ComponentRegistry.get(e)}function K({dataset:e,chart:t,runtimeFilter:n,dataSource:r}){let i=typeof t.xAxis==`string`?t.xAxis:``,a=typeof t.yAxis==`string`?t.yAxis:``,c=R(e,i?[i]:[],a?[a]:[],n,r),l=G(`chart`);if(!i||!a)return null;if(c.status===`loading`||c.status===`idle`)return(0,o.jsxs)(`div`,{className:`flex items-center gap-2 p-4 text-xs text-muted-foreground`,children:[(0,o.jsx)(s.Loader2,{className:`h-4 w-4 animate-spin`}),` Loading chart…`]});if(c.status===`error`||c.rows.length===0||!l)return null;let u=typeof t.title==`string`?t.title:void 0;return(0,o.jsxs)(`div`,{className:`rounded-md border bg-card p-3`,"data-testid":`dataset-report-chart`,children:[u?(0,o.jsx)(`h3`,{className:`mb-2 text-sm font-semibold`,children:u}):null,(0,o.jsx)(l,{schema:{chartType:W(t.type),data:c.rows,xAxisKey:i,series:[{dataKey:a}],height:typeof t.height==`number`?t.height:280,isAnimationActive:!1}})]})}function q(e,t){return e.map(e=>String(t[e]??`∅`)).join(``)}function J(e,n){return e.map(e=>(0,t.formatDimensionValue)(n[e])).join(` / `)}function Y({dataset:e,rows:r,columnsAcross:i,values:a,runtimeFilter:s,dataSource:c,onDrill:u}){let d=R(e,[...r,...i],a,s,c,[r,i,[]]),f=(0,l.useSafeTranslate)(),{fieldLabel:p}=(0,l.useSafeFieldLabel)(),m=n.useMemo(()=>{if(d.status!==`ok`)return null;let e=[],t=[],n=new Set,a=new Set,o=new Map;return d.rows.forEach((s,c)=>{let l=q(r,s),u=q(i,s);if(!n.has(l)){n.add(l);let t={};for(let e of r)t[e]=s[e];e.push({id:l,label:J(r,s),key:t})}if(!a.has(u)){a.add(u);let e={};for(let t of i)e[t]=s[t];t.push({id:u,label:J(i,s),key:e})}o.set(`${l} ${u}`,{row:s,index:c})}),{rowHeaders:e,colHeaders:t,cells:o}},[d,r,i]);if(a.length===0)return(0,o.jsx)(z,{dataset:e});if(d.status===`loading`||d.status===`idle`)return(0,o.jsx)(B,{status:d.status});if(d.status===`error`)return(0,o.jsx)(B,{status:`error`,error:d.error});if(!m||m.rowHeaders.length===0)return(0,o.jsx)(V,{});let{measureField:h,headerLabel:g}=(0,t.buildDatasetFieldHelpers)(d.fields,d.object,p),_=f(`report.total`,`Total`),v=!!u,y=d.dimensionFields?[...r,...i].filter(e=>e in d.dimensionFields):[],b=(n,r,i)=>{let a=d.object&&d.dimensionFields&&y.length>0?(0,t.buildDatasetDrillFilter)(d.drillRawRows?.[i],y,d.dimensionFields,s):void 0;u({dataset:e,groupKey:{...n,...r},runtimeFilter:s,object:d.object,objectFilter:a})},x=m.colHeaders.flatMap(e=>a.map(t=>({col:e,measure:t,header:a.length===1?e.label:`${e.label} · ${g(t)}`}))),S=e=>d.totals?.find(t=>Array.isArray(t.dimensions)&&t.dimensions.join(`,`)===e.join(`,`))?.rows,C=new Map;for(let e of S(r)??[])C.set(q(r,e),e);let w=new Map;for(let e of S(i)??[])w.set(q(i,e),e);let T=S([])?.[0],E=C.size>0,D=w.size>0;return(0,o.jsx)(`div`,{className:`overflow-auto max-h-[70vh] rounded-md border`,"data-testid":`dataset-matrix`,children:(0,o.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,o.jsx)(`thead`,{className:`bg-muted/40`,children:(0,o.jsxs)(`tr`,{children:[r.map(e=>(0,o.jsx)(`th`,{className:`px-2 py-1.5 text-left font-medium whitespace-nowrap`,children:g(e)},e)),x.map(e=>(0,o.jsx)(`th`,{className:`px-2 py-1.5 text-right font-medium whitespace-nowrap`,children:e.header},`${e.col.id}-${e.measure}`)),E&&a.map(e=>(0,o.jsx)(`th`,{className:`px-2 py-1.5 text-right font-medium whitespace-nowrap`,"data-testid":`matrix-total-col-header`,children:a.length===1?_:`${_} · ${g(e)}`},`total-${e}`))]})}),(0,o.jsxs)(`tbody`,{children:[m.rowHeaders.map(e=>(0,o.jsxs)(`tr`,{className:`border-t`,children:[r.map(n=>(0,o.jsx)(`td`,{className:`px-2 py-1 whitespace-nowrap font-medium`,children:(0,t.formatDimensionValue)(e.key[n])},n)),x.map(n=>{let r=m.cells.get(`${e.id} ${n.col.id}`),i=r?.row[n.measure],a=v&&r!=null;return(0,o.jsx)(`td`,{className:`px-2 py-1 text-right tabular-nums whitespace-nowrap${a?` ${H}`:``}`,"data-testid":a?`dataset-drill-cell`:void 0,onClick:a?()=>b(e.key,n.col.key,r.index):void 0,children:(0,t.formatMeasure)(i,h(n.measure)?.format,h(n.measure)?.currency)},`${n.col.id}-${n.measure}`)}),E&&a.map(n=>(0,o.jsx)(`td`,{className:`px-2 py-1 text-right tabular-nums whitespace-nowrap font-medium`,"data-testid":`matrix-row-total`,children:(0,t.formatMeasure)(C.get(e.id)?.[n],h(n)?.format,h(n)?.currency)},`total-${n}`))]},e.id)),D&&(0,o.jsxs)(`tr`,{className:`border-t bg-muted/30 font-medium`,"data-testid":`matrix-total-row`,children:[r.length>0&&(0,o.jsx)(`td`,{colSpan:r.length,className:`px-2 py-1 whitespace-nowrap`,children:_}),x.map(e=>(0,o.jsx)(`td`,{className:`px-2 py-1 text-right tabular-nums whitespace-nowrap`,children:(0,t.formatMeasure)(w.get(e.col.id)?.[e.measure],h(e.measure)?.format,h(e.measure)?.currency)},`${e.col.id}-${e.measure}`)),E&&a.map(e=>(0,o.jsx)(`td`,{className:`px-2 py-1 text-right tabular-nums whitespace-nowrap`,"data-testid":`matrix-grand-total`,children:(0,t.formatMeasure)(T?.[e],h(e)?.format,h(e)?.currency)},`grand-${e}`))]})]})]})})}var X=({report:e,dataSource:t,runtimeFilter:n,onDrill:r,className:i})=>{let a=P(e.runtimeFilter??e.filter,n),s=e.drilldown===!1?void 0:r;if(e.type===`joined`&&Array.isArray(e.blocks))return(0,o.jsx)(`div`,{className:i,"data-testid":`dataset-joined-report`,"data-report-name":e.name,style:{display:`flex`,flexDirection:`column`,gap:24},children:e.blocks.map((e,n)=>{let r=P(a,e.runtimeFilter??e.filter),i=L(e.columns),c=e.type===`matrix`&&i.length>0?(0,o.jsx)(Y,{dataset:String(e.dataset??``),rows:L(e.rows),columnsAcross:i,values:L(e.values),runtimeFilter:r,dataSource:t,onDrill:s}):(0,o.jsx)(U,{dataset:String(e.dataset??``),rows:L(e.rows),values:L(e.values),runtimeFilter:r,dataSource:t,onDrill:s});return(0,o.jsxs)(`section`,{"data-testid":`dataset-report-block`,"data-block-id":e.name??`block-${n}`,className:`flex flex-col gap-2 rounded-lg border bg-card p-4`,children:[(0,o.jsxs)(`header`,{className:`flex flex-col gap-0.5`,children:[(0,o.jsx)(`h3`,{className:`text-sm font-semibold`,children:I(e.label,e.name??`Block ${n+1}`)}),e.description?(0,o.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:I(e.description,``)}):null]}),c]},e.name??`block-${n}`)})});let c=L(e.columns);if(e.type===`matrix`&&c.length>0)return(0,o.jsx)(`div`,{className:i,"data-testid":`dataset-report`,"data-report-name":e.name,children:(0,o.jsx)(Y,{dataset:String(e.dataset??``),rows:L(e.rows),columnsAcross:c,values:L(e.values),runtimeFilter:a,dataSource:t,onDrill:s})});let l=e.chart&&typeof e.chart==`object`&&e.chart.type?e.chart:null;return(0,o.jsxs)(`div`,{className:`${i??``} flex flex-col gap-3`,"data-testid":`dataset-report`,"data-report-name":e.name,children:[l?(0,o.jsx)(K,{dataset:String(e.dataset??``),chart:l,runtimeFilter:a,dataSource:t}):null,(0,o.jsx)(U,{dataset:String(e.dataset??``),rows:L(e.rows),values:L(e.values),runtimeFilter:a,dataSource:t,onDrill:s})]})},Z=e=>{let{dataSource:t,rows:a,runtimeFilter:s,onDrill:c,className:l}=e,u=n.useContext(i.SchemaRendererContext),d=t??u?.dataSource,f=e.schema;return f&&typeof f==`object`&&f.type===`spec-report`&&f.report&&typeof f.report==`object`&&(f=f.report),F(f)?(0,o.jsx)(X,{report:f,dataSource:d,runtimeFilter:s,onDrill:c,className:l}):(0,r.isSpecReport)(f)?(0,o.jsx)(`div`,{className:l,"data-testid":`report-presentation-bridge`,children:(0,o.jsx)(N,{schema:{type:`report-viewer`,report:(0,r.specReportToPresentation)(f),data:a??[],showToolbar:!1}})}):(0,o.jsx)(_,{schema:f})};async function Q(e,t){let{dataSource:n,resource:r,queryParams:i,format:a,exportConfig:o}=t,s=a||e.defaultExportFormat||`pdf`;try{let t=(await n.find(r,i)).data||[];return C(s,e,t,{format:s,...e.exportConfigs?.[s],...o}),{success:!0,recordCount:t.length,format:s}}catch(e){return{success:!1,recordCount:0,format:s,error:e.message}}}function $(e,t,n={}){let{columns:r,filename:i,includeAggregationRow:a=!1}=n,o=r||(e.fields||[]).map(te),s=o.map(e=>e.header),c=t.map((e,t)=>o.map(n=>{if(n.formula)return n.formula.replace(/\{ROW\}/g,String(t+2));let r=e[n.name];return ne(r,n.numberFormat)}));if(a&&t.length>0){let n=o.map((n,r)=>{let i=(e.fields||[]).find(e=>e.name===n.name);if(i?.aggregation){let e=ie(r),n=t.length+1;switch(i.aggregation){case`sum`:return`=SUM(${e}2:${e}${n})`;case`avg`:return`=AVERAGE(${e}2:${e}${n})`;case`count`:return`=COUNTA(${e}2:${e}${n})`;case`min`:return`=MIN(${e}2:${e}${n})`;case`max`:return`=MAX(${e}2:${e}${n})`;default:return``}}return``});c.push(n)}oe(``+[s.join(` `),...c.map(e=>e.join(` `))].join(`
|
|
59
59
|
`),i||`${e.title||`report`}.tsv`,`text/tab-separated-values`)}function ee(e,t,n,r){return async()=>{let i=e.schedule;if(!i?.enabled)return[];let a=i.formats||[e.defaultExportFormat||`pdf`],o=[];for(let r of a){let i=await Q(e,{dataSource:t,resource:n,format:r});o.push(i)}return r(e,i),o}}function te(e){return{name:e.name,header:e.label||e.name}}function ne(e,t){return e==null?``:typeof e==`number`&&t?e.toLocaleString(`en-US`,re(t)):ae(String(e))}function re(e){if(e.includes(`%`))return{style:`percent`,minimumFractionDigits:0};let t=(e.match(/0/g)||[]).length;return{minimumFractionDigits:Math.max(0,t-1),maximumFractionDigits:Math.max(0,t-1)}}function ie(e){let t=``,n=e;for(;n>=0;)t=String.fromCharCode(n%26+65)+t,n=Math.floor(n/26)-1;return t}function ae(e){if(e.length>0){let t=e.charAt(0);if(t===`=`||t===`+`||t===`-`||t===`@`||t===`|`)return`'${e}`}return e}function oe(e,t,n){let r=new Blob([e],{type:`${n};charset=utf-8`}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=t,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i)}t.ComponentRegistry.register(`report`,Z,{namespace:`report`,label:`Report`,category:`Report`,inputs:[{name:`title`,type:`string`,label:`Title`},{name:`description`,type:`string`,label:`Description`},{name:`chart`,type:`code`,label:`Chart Configuration`}]}),t.ComponentRegistry.register(`spec-report`,Z,{namespace:`report`,label:`Spec Report`,category:`Report`,inputs:[{name:`dataset`,type:`string`,label:`Dataset`},{name:`type`,type:`string`,label:`Report Type`}]}),t.ComponentRegistry.register(`report-viewer`,N,{namespace:`report`,label:`Report Viewer`,category:`Report`,inputs:[{name:`report`,type:`code`,label:`Report Definition`},{name:`showToolbar`,type:`boolean`,label:`Show Toolbar`}]}),e.DatasetReportRenderer=X,e.LegacyReportRenderer=_,e.ReportRenderer=Z,e.ReportViewer=N,e.createScheduleTrigger=ee,e.exportAsCSV=v,e.exportAsExcel=S,e.exportAsHTML=b,e.exportAsJSON=y,e.exportAsPDF=x,e.exportExcelWithFormulas=$,e.exportReport=C,e.exportWithLiveData=Q,e.formatValue=k,e.isDatasetReport=F,e.mergeFilters=P});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@object-ui/plugin-report",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "14.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.umd.cjs",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -20,27 +20,27 @@
|
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"clsx": "^2.1.1",
|
|
23
|
-
"lucide-react": "^1.
|
|
24
|
-
"react-i18next": "^17.0.
|
|
23
|
+
"lucide-react": "^1.24.0",
|
|
24
|
+
"react-i18next": "^17.0.9",
|
|
25
25
|
"tailwind-merge": "^3.6.0",
|
|
26
|
-
"@object-ui/
|
|
27
|
-
"@object-ui/
|
|
28
|
-
"@object-ui/
|
|
29
|
-
"@object-ui/
|
|
30
|
-
"@object-ui/
|
|
31
|
-
"@object-ui/react": "
|
|
32
|
-
"@object-ui/types": "
|
|
26
|
+
"@object-ui/core": "14.0.0",
|
|
27
|
+
"@object-ui/components": "14.0.0",
|
|
28
|
+
"@object-ui/i18n": "14.0.0",
|
|
29
|
+
"@object-ui/plugin-grid": "14.0.0",
|
|
30
|
+
"@object-ui/fields": "14.0.0",
|
|
31
|
+
"@object-ui/react": "14.0.0",
|
|
32
|
+
"@object-ui/types": "14.0.0"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
35
|
"react": "^18.0.0",
|
|
36
36
|
"react-dom": "^18.0.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@types/node": "^26.1.
|
|
39
|
+
"@types/node": "^26.1.1",
|
|
40
40
|
"@types/react": "19.2.17",
|
|
41
41
|
"@types/react-dom": "19.2.3",
|
|
42
42
|
"@vitejs/plugin-react": "^6.0.3",
|
|
43
|
-
"vite": "^8.1.
|
|
43
|
+
"vite": "^8.1.4",
|
|
44
44
|
"vite-plugin-dts": "^5.0.3",
|
|
45
45
|
"vitest": "^4.1.10"
|
|
46
46
|
},
|