@object-ui/plugin-report 17.2.0 → 17.5.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 +443 -0
- package/README.md +0 -12
- package/dist/index.js +374 -356
- package/dist/index.umd.cjs +2 -2
- package/dist/useDatasetDimensionLabels.d.ts +71 -0
- package/package.json +17 -17
package/dist/index.umd.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@object-ui/core"),require("react"),require("@object-ui/types"),require("@object-ui/react"),require("@object-ui/components"),require("react/jsx-runtime"),require("lucide-react"),require("@object-ui/fields"),require("@object-ui/i18n")):typeof define==`function`&&define.amd?define([`exports`,`@object-ui/core`,`react`,`@object-ui/types`,`@object-ui/react`,`@object-ui/components`,`react/jsx-runtime`,`lucide-react`,`@object-ui/fields`,`@object-ui/i18n`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.ObjectUIPluginReport={},e.ObjectUICore,e.React,e.ObjectUITypes,e.ObjectUIReact,e.ObjectUIComponents,e.react_jsx_runtime,e.lucide_react,e._object_ui_fields,e._object_ui_i18n))})(this,function(e,t,n,r,i,a,o,s,c,l){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var u=Object.create,d=Object.defineProperty,f=Object.getOwnPropertyDescriptor,p=Object.getOwnPropertyNames,m=Object.getPrototypeOf,h=Object.prototype.hasOwnProperty,g=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=p(t),a=0,o=i.length,s;a<o;a++)s=i[a],!h.call(e,s)&&s!==n&&d(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=f(t,s))||r.enumerable});return e};n=((e,t,n)=>(n=e==null?{}:u(m(e)),g(t||!e||!e.__esModule?d(n,`default`,{value:e,enumerable:!0}):n,e)))(n,1);var _=({schema:e})=>{let{title:n,description:r,data:i,columns:s}=e;e.chart?.type;let c=!!e.chart;return(0,o.jsxs)(a.Card,{className:`h-full flex flex-col ${e.className||``}`,children:[(0,o.jsxs)(a.CardHeader,{children:[n&&(0,o.jsx)(a.CardTitle,{children:n}),r&&(0,o.jsx)(a.CardDescription,{children:r})]}),(0,o.jsxs)(a.CardContent,{className:`flex-1 overflow-auto space-y-4`,children:[c&&(()=>{let n=e.chart?.type,r=n?t.ComponentRegistry.get(n):null;return r||=t.ComponentRegistry.get(`chart`),r?(0,o.jsx)(`div`,{className:`min-h-[300px] border rounded-lg p-4 bg-background/50`,children:(0,o.jsx)(r,{schema:{...e.chart,data:e.chart.data||i}})}):(0,o.jsxs)(`div`,{className:`min-h-[100px] border rounded-md p-4 bg-muted/20 text-muted-foreground flex items-center justify-center`,children:[`Unknown component type: `,n||`chart`]})})(),i&&i.length>0&&(0,o.jsx)(`div`,{className:`border rounded-lg`,children:(()=>{let e=t.ComponentRegistry.get(`grid`)||t.ComponentRegistry.get(`table`);return e?(0,o.jsx)(e,{schema:{type:`grid`,rowData:i,columnDefs:s,domLayout:`autoHeight`}}):(0,o.jsx)(`div`,{className:`overflow-x-auto`,children:(0,o.jsxs)(`table`,{className:`w-full text-sm text-left`,children:[(0,o.jsx)(`thead`,{className:`text-xs uppercase bg-muted`,children:(0,o.jsx)(`tr`,{children:s?.map(e=>(0,o.jsx)(`th`,{className:`px-6 py-3`,children:e.headerName||e.label||e.field},e.field))})}),(0,o.jsx)(`tbody`,{children:i.map((e,t)=>(0,o.jsx)(`tr`,{className:`bg-background border-b`,children:s?.map(t=>(0,o.jsx)(`td`,{className:`px-6 py-4`,children:e[t.field]},t.field))},t))})]})})})()})]})]})};function v(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(`
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@object-ui/core"),require("react"),require("@object-ui/types"),require("@object-ui/react"),require("@object-ui/components"),require("react/jsx-runtime"),require("lucide-react"),require("@object-ui/fields"),require("@object-ui/i18n")):typeof define==`function`&&define.amd?define([`exports`,`@object-ui/core`,`react`,`@object-ui/types`,`@object-ui/react`,`@object-ui/components`,`react/jsx-runtime`,`lucide-react`,`@object-ui/fields`,`@object-ui/i18n`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.ObjectUIPluginReport={},e.ObjectUICore,e.React,e.ObjectUITypes,e.ObjectUIReact,e.ObjectUIComponents,e.react_jsx_runtime,e.lucide_react,e._object_ui_fields,e._object_ui_i18n))})(this,function(e,t,n,r,i,a,o,s,c,l){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var u=Object.create,d=Object.defineProperty,f=Object.getOwnPropertyDescriptor,p=Object.getOwnPropertyNames,m=Object.getPrototypeOf,h=Object.prototype.hasOwnProperty,g=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=p(t),a=0,o=i.length,s;a<o;a++)s=i[a],!h.call(e,s)&&s!==n&&d(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=f(t,s))||r.enumerable});return e};n=((e,t,n)=>(n=e==null?{}:u(m(e)),g(t||!e||!e.__esModule||!h.call(e,`default`)?d(n,`default`,{value:e,enumerable:!0}):n,e)))(n,1);var _=({schema:e})=>{let{title:n,description:r,data:i,columns:s}=e;e.chart?.type;let c=!!e.chart;return(0,o.jsxs)(a.Card,{className:`h-full flex flex-col ${e.className||``}`,children:[(0,o.jsxs)(a.CardHeader,{children:[n&&(0,o.jsx)(a.CardTitle,{children:n}),r&&(0,o.jsx)(a.CardDescription,{children:r})]}),(0,o.jsxs)(a.CardContent,{className:`flex-1 overflow-auto space-y-4`,children:[c&&(()=>{let n=e.chart?.type,r=n?t.ComponentRegistry.get(n):null;return r||=t.ComponentRegistry.get(`chart`),r?(0,o.jsx)(`div`,{className:`min-h-[300px] border rounded-lg p-4 bg-background/50`,children:(0,o.jsx)(r,{schema:{...e.chart,data:e.chart.data||i}})}):(0,o.jsxs)(`div`,{className:`min-h-[100px] border rounded-md p-4 bg-muted/20 text-muted-foreground flex items-center justify-center`,children:[`Unknown component type: `,n||`chart`]})})(),i&&i.length>0&&(0,o.jsx)(`div`,{className:`border rounded-lg`,children:(()=>{let e=t.ComponentRegistry.get(`grid`)||t.ComponentRegistry.get(`table`);return e?(0,o.jsx)(e,{schema:{type:`grid`,rowData:i,columnDefs:s,domLayout:`autoHeight`}}):(0,o.jsx)(`div`,{className:`overflow-x-auto`,children:(0,o.jsxs)(`table`,{className:`w-full text-sm text-left`,children:[(0,o.jsx)(`thead`,{className:`text-xs uppercase bg-muted`,children:(0,o.jsx)(`tr`,{children:s?.map(e=>(0,o.jsx)(`th`,{className:`px-6 py-3`,children:e.headerName||e.label||e.field},e.field))})}),(0,o.jsx)(`tbody`,{children:i.map((e,t)=>(0,o.jsx)(`tr`,{className:`bg-background border-b`,children:s?.map(t=>(0,o.jsx)(`td`,{className:`px-6 py-4`,children:e[t.field]},t.field))},t))})]})})})()})]})]})};function v(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(`
|
|
2
2
|
`))?`"${n.replace(/"/g,`""`)}"`:n??``}));O([...n?.includeHeaders===!1?[]:[i.join(`,`)],...a.map(e=>e.join(`,`))].join(`
|
|
3
3
|
`),n?.filename||`${e.title||`report`}.csv`,`text/csv`)}function y(e,t,n){let r={title:e.title,description:e.description,generatedAt:new Date().toISOString(),data:t};O(JSON.stringify(r,null,2),n?.filename||`${e.title||`report`}.json`,`application/json`)}function b(e,t,n){let r=e.fields||[],i=D(n?.orientation),a=E(n?.pageSize);O(`<!DOCTYPE html>
|
|
4
4
|
<html>
|
|
@@ -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)}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 ee(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}function M(e,t,n){if(!e)return 0;let r=e.map(e=>Number(e[t])||0);switch(n){case`count`:return e.length;case`sum`:return r.reduce((e,t)=>e+t,0);case`avg`:return r.length>0?(r.reduce((e,t)=>e+t,0)/r.length).toFixed(2):0;case`min`:return r.length>0?Math.min(...r):0;case`max`:return r.length>0?Math.max(...r):0;case`distinct`:return new Set(e.map(e=>e[t])).size;default:return``}}var N=({schema:e,onRefresh:t})=>{let{report:r,data:l,showToolbar:u=!0,allowExport:d=!0,allowPrint:f=!0,loading:p=!1}=e,m=e=>{if(!r){console.warn(`ReportViewer: Cannot export, no report defined`);return}C(e,r,l||[],r.exportConfigs?.[e])},h=()=>{window.print()},g=()=>{t?.()},_=(e,t)=>M(l,e,t),v=(e,t)=>{let n=r?.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}}},y=(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 r?(0,o.jsxs)(`div`,{className:`space-y-4`,children:[u&&(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:r.title}),r.description&&(0,o.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:r.description})]}),(0,o.jsxs)(`div`,{className:`flex items-center gap-2`,children:[r.refreshInterval&&(0,o.jsxs)(a.Button,{variant:`outline`,size:`sm`,onClick:g,children:[(0,o.jsx)(s.RefreshCw,{className:`h-4 w-4 mr-2`}),`Refresh`]}),f&&(0,o.jsxs)(a.Button,{variant:`outline`,size:`sm`,onClick:h,children:[(0,o.jsx)(s.Printer,{className:`h-4 w-4 mr-2`}),`Print`]}),d&&r.showExportButtons&&(0,o.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,o.jsxs)(a.Button,{variant:`outline`,size:`sm`,onClick:()=>m(`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:()=>m(`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:()=>m(`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:[!u&&r.title&&(0,o.jsx)(a.CardTitle,{children:r.title}),!u&&r.description&&(0,o.jsx)(a.CardDescription,{children:r.description})]}),(0,o.jsxs)(a.CardContent,{className:`space-y-6`,children:[p&&(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))]})]}),!p&&r.sections?.map((e,t)=>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:r.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(_(e.name,e.aggregation),e)})]})},t))}),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=ee(l||[],r.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:v(e.name,t[e.name]),children:y(t[e.name],e)},n))},n))]},t.key)):l?.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:v(e.name,t[e.name]),children:y(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})]},t)),!r.sections&&l&&l.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:r.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:l.map((e,t)=>(0,o.jsx)(`tr`,{className:`border-t hover:bg-muted/50 even:bg-muted/20`,children:r.fields?.map((t,n)=>(0,o.jsx)(`td`,{className:`px-4 py-2 ${t.type===`number`?`text-right tabular-nums`:``}`,style:v(t.name,e[t.name]),children:y(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){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 F(e,t){return e?typeof e==`string`?e:typeof e==`object`&&typeof e.default==`string`?e.default:t:t}function I(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`&&!!e):[]}function L(e){if(!Array.isArray(e))return;let t={};for(let n of e){let e=n&&typeof n==`object`?n.by:void 0;typeof e!=`string`||!e||(t[e]=n.direction===`desc`?`desc`:`asc`)}return Object.keys(t).length>0?t:void 0}function R(e,t,n){if(!e)return;let r=new Set([...t,...n]),i={};for(let[t,n]of Object.entries(e))r.has(t)&&(i[t]=n);return Object.keys(i).length>0?i:void 0}function z(e,t,r,i,a,o,s){let[c,l]=n.useState({status:`idle`,rows:[]}),u=R(s,t,r),d=JSON.stringify(i??null),f=JSON.stringify(o??null),p=JSON.stringify(u??null),m=`${e}|${t.join(`,`)}|${r.join(`,`)}|${d}|${f}|${p}`;return n.useEffect(()=>{let n=a;if(!n||typeof n.queryDataset!=`function`){l({status:`error`,rows:[],error:`This data source does not support dataset queries.`});return}if(!e||r.length===0){l({status:`idle`,rows:[]});return}let s=!1;return l({status:`loading`,rows:[]}),n.queryDataset(e,{dimensions:t,measures:r,...i&&Object.keys(i).length>0?{runtimeFilter:i}:{},...o?{totals:{groupings:o}}:{},...u?{order:u}:{}}).then(e=>{s||l({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,drillRanges:Array.isArray(e?.drillRanges)?e.drillRanges:void 0,totals:Array.isArray(e?.totals)?e.totals:void 0})}).catch(e=>{s||l({status:`error`,rows:[],error:String(e?.message??e)})}),()=>{s=!0}},[m]),c}function B({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 V({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 H(){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 U=`cursor-pointer hover:bg-accent/40`;function W({dataset:e,rows:n,values:r,runtimeFilter:i,dataSource:a,onDrill:s,order:c,withTotals:u}){let d=z(e,n,r,i,a,u&&n.length>0?[[]]:void 0,c),{fieldLabel:f}=(0,l.useSafeFieldLabel)(),p=(0,l.useSafeTranslate)();if(r.length===0)return(0,o.jsx)(B,{dataset:e});if(d.status===`loading`||d.status===`idle`)return(0,o.jsx)(V,{status:d.status});if(d.status===`error`)return(0,o.jsx)(V,{status:`error`,error:d.error});if(d.rows.length===0)return(0,o.jsx)(H,{});let m=!!s&&n.length>0,h=d.dimensionFields?n.filter(e=>e in d.dimensionFields):[],g=(r,a)=>{let o={};for(let e of n)o[e]=r[e];let c=d.drillRanges?.[a],l=!!c&&Object.keys(c).length>0,u=d.object&&(h.length>0||l)?(0,t.buildDatasetDrillFilter)(d.drillRawRows?.[a],h,d.dimensionFields??{},i,c):void 0;s({dataset:e,groupKey:o,runtimeFilter:i,object:d.object,objectFilter:u})},{measureField:_,headerLabel:v}=(0,t.buildDatasetFieldHelpers)(d.fields,d.object,f),y=[...n,...r],b=u?d.totals?.find(e=>Array.isArray(e.dimensions)&&e.dimensions.length===0)?.rows?.[0]:void 0,x=p(`report.total`,`Total`);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:y.map(e=>(0,o.jsx)(`th`,{className:`px-2 py-1.5 text-left font-medium whitespace-nowrap`,children:v(e)},e))})}),(0,o.jsxs)(`tbody`,{children:[d.rows.map((e,n)=>(0,o.jsx)(`tr`,{className:`border-t${m?` ${U}`:``}`,"data-testid":m?`dataset-drill-row`:void 0,onClick:m?()=>g(e,n):void 0,children:y.map(n=>(0,o.jsx)(`td`,{className:`px-2 py-1 tabular-nums whitespace-nowrap`,children:r.includes(n)?(0,t.formatMeasure)(e[n],_(n)?.format,_(n)?.currency,_(n)?.percentScale):(0,t.formatDimensionValue)(e[n])},n))},n)),b&&(0,o.jsxs)(`tr`,{className:`border-t bg-muted/30 font-medium`,"data-testid":`dataset-report-total-row`,children:[n.length>0&&(0,o.jsx)(`td`,{colSpan:n.length,className:`px-2 py-1 whitespace-nowrap`,children:x}),r.map(e=>(0,o.jsx)(`td`,{className:`px-2 py-1 tabular-nums whitespace-nowrap`,children:(0,t.formatMeasure)(b[e],_(e)?.format,_(e)?.currency,_(e)?.percentScale)},e))]})]})]})})}function G(e){switch(e){case`summary`:return`summary`;case`matrix`:return`matrix`;case`joined`:return`joined`;default:return`tabular`}}function te(e){switch(e){case`bar`:case`column`:case`horizontal-bar`:case`line`:case`area`:case`pie`:case`donut`:case`funnel`:case`scatter`:case`treemap`:case`sankey`:case`radar`:case`combo`:return{kind:`series`,chartType:e};case`gauge`:case`solid-gauge`:case`metric`:case`kpi`:case`bullet`:return{kind:`single_value`};case`table`:case`pivot`:return{kind:`tabular`};default:return{kind:`unsupported`,type:String(e)}}}function ne(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:n,runtimeFilter:r,dataSource:i,order:a}){let c=typeof n.xAxis==`string`?n.xAxis:``,u=typeof n.yAxis==`string`?n.yAxis:``,d=te(n.type),f=d.kind===`series`||d.kind===`single_value`,p=z(e,d.kind===`series`&&c?[c]:[],f&&u?[u]:[],r,i,void 0,a),m=ne(`chart`),{fieldLabel:h}=(0,l.useSafeFieldLabel)(),g=typeof n.title==`string`?n.title:void 0;if(d.kind===`tabular`)return null;if(d.kind===`unsupported`)return(0,o.jsxs)(`div`,{className:`rounded-md border border-dashed bg-muted/20 px-3 py-2 text-xs text-muted-foreground`,"data-testid":`dataset-report-chart-unsupported`,children:[`Chart type “`,d.type,`” is not a spec chart type — the grouped table below carries this report’s numbers.`]});if(d.kind===`series`&&!c||!u)return null;if(p.status===`loading`||p.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(p.status===`error`||p.rows.length===0)return null;if(d.kind===`single_value`){let{measureField:e,headerLabel:n}=(0,t.buildDatasetFieldHelpers)(p.fields,p.object,h),r=e(u);return(0,o.jsxs)(`div`,{className:`rounded-md border bg-card p-3`,"data-testid":`dataset-report-metric`,children:[g?(0,o.jsx)(`h3`,{className:`mb-2 text-sm font-semibold`,children:g}):null,(0,o.jsxs)(`div`,{className:`flex flex-col gap-0.5 py-2`,children:[(0,o.jsx)(`span`,{className:`text-2xl font-semibold tabular-nums`,children:(0,t.formatMeasure)(p.rows[0]?.[u],r?.format,r?.currency,r?.percentScale)}),(0,o.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:n(u)})]})]})}return m?(0,o.jsxs)(`div`,{className:`rounded-md border bg-card p-3`,"data-testid":`dataset-report-chart`,children:[g?(0,o.jsx)(`h3`,{className:`mb-2 text-sm font-semibold`,children:g}):null,(0,o.jsx)(m,{schema:{chartType:d.chartType,data:p.rows,xAxisKey:c,series:[{dataKey:u}],height:typeof n.height==`number`?n.height:280,isAnimationActive:!1}})]}):null}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,order:d}){let f=z(e,[...r,...i],a,s,c,[r,i,[]],d),p=(0,l.useSafeTranslate)(),{fieldLabel:m}=(0,l.useSafeFieldLabel)(),h=n.useMemo(()=>{if(f.status!==`ok`)return null;let e=[],t=[],n=new Set,a=new Set,o=new Map;return f.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}},[f,r,i]);if(a.length===0)return(0,o.jsx)(B,{dataset:e});if(f.status===`loading`||f.status===`idle`)return(0,o.jsx)(V,{status:f.status});if(f.status===`error`)return(0,o.jsx)(V,{status:`error`,error:f.error});if(!h||h.rowHeaders.length===0)return(0,o.jsx)(H,{});let{measureField:g,headerLabel:_}=(0,t.buildDatasetFieldHelpers)(f.fields,f.object,m),v=p(`report.total`,`Total`),y=!!u,b=f.dimensionFields?[...r,...i].filter(e=>e in f.dimensionFields):[],x=(n,r,i)=>{let a=f.drillRanges?.[i],o=!!a&&Object.keys(a).length>0,c=f.object&&(b.length>0||o)?(0,t.buildDatasetDrillFilter)(f.drillRawRows?.[i],b,f.dimensionFields??{},s,a):void 0;u({dataset:e,groupKey:{...n,...r},runtimeFilter:s,object:f.object,objectFilter:c})},S=h.colHeaders.flatMap(e=>a.map(t=>({col:e,measure:t,header:a.length===1?e.label:`${e.label} · ${_(t)}`}))),C=e=>f.totals?.find(t=>Array.isArray(t.dimensions)&&t.dimensions.join(`,`)===e.join(`,`))?.rows,w=new Map;for(let e of C(r)??[])w.set(q(r,e),e);let T=new Map;for(let e of C(i)??[])T.set(q(i,e),e);let E=C([])?.[0],D=w.size>0,O=T.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:_(e)},e)),S.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}`)),D&&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?v:`${v} · ${_(e)}`},`total-${e}`))]})}),(0,o.jsxs)(`tbody`,{children:[h.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)),S.map(n=>{let r=h.cells.get(`${e.id} ${n.col.id}`),i=r?.row[n.measure],a=y&&r!=null;return(0,o.jsx)(`td`,{className:`px-2 py-1 text-right tabular-nums whitespace-nowrap${a?` ${U}`:``}`,"data-testid":a?`dataset-drill-cell`:void 0,onClick:a?()=>x(e.key,n.col.key,r.index):void 0,children:(0,t.formatMeasure)(i,g(n.measure)?.format,g(n.measure)?.currency,g(n.measure)?.percentScale)},`${n.col.id}-${n.measure}`)}),D&&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)(w.get(e.id)?.[n],g(n)?.format,g(n)?.currency,g(n)?.percentScale)},`total-${n}`))]},e.id)),O&&(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:v}),S.map(e=>(0,o.jsx)(`td`,{className:`px-2 py-1 text-right tabular-nums whitespace-nowrap`,children:(0,t.formatMeasure)(T.get(e.col.id)?.[e.measure],g(e.measure)?.format,g(e.measure)?.currency,g(e.measure)?.percentScale)},`${e.col.id}-${e.measure}`)),D&&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)(E?.[e],g(e)?.format,g(e)?.currency,g(e)?.percentScale)},`grand-${e}`))]})]})]})})}var X=({report:e,dataSource:n,runtimeFilter:r,onDrill:i,className:a})=>{let s=(0,t.mergeFilters)(e.runtimeFilter??e.filter,r),c=e.drilldown===!1?void 0:i,l=G(e.type);if(l===`joined`&&Array.isArray(e.blocks))return(0,o.jsx)(`div`,{className:a,"data-testid":`dataset-joined-report`,"data-report-name":e.name,style:{display:`flex`,flexDirection:`column`,gap:24},children:e.blocks.map((e,r)=>{let i=(0,t.mergeFilters)(s,e.runtimeFilter??e.filter),a=I(e.columns),l=L(e.order),u=G(e.type),d=u===`matrix`&&a.length>0?(0,o.jsx)(Y,{dataset:String(e.dataset??``),rows:I(e.rows),columnsAcross:a,values:I(e.values),runtimeFilter:i,dataSource:n,onDrill:c,order:l}):(0,o.jsx)(W,{dataset:String(e.dataset??``),rows:I(e.rows),values:I(e.values),runtimeFilter:i,dataSource:n,onDrill:c,order:l,withTotals:u===`summary`||u===`matrix`});return(0,o.jsxs)(`section`,{"data-testid":`dataset-report-block`,"data-block-id":e.name??`block-${r}`,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:F(e.label,e.name??`Block ${r+1}`)}),e.description?(0,o.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:F(e.description,``)}):null]}),d]},e.name??`block-${r}`)})});let u=I(e.columns),d=L(e.order);if(l===`matrix`&&u.length>0)return(0,o.jsx)(`div`,{className:a,"data-testid":`dataset-report`,"data-report-name":e.name,children:(0,o.jsx)(Y,{dataset:String(e.dataset??``),rows:I(e.rows),columnsAcross:u,values:I(e.values),runtimeFilter:s,dataSource:n,onDrill:c,order:d})});let f=e.chart&&typeof e.chart==`object`&&e.chart.type?e.chart:null;return(0,o.jsxs)(`div`,{className:`${a??``} flex flex-col gap-3`,"data-testid":`dataset-report`,"data-report-name":e.name,"data-report-presentation":l,children:[f?(0,o.jsx)(K,{dataset:String(e.dataset??``),chart:f,runtimeFilter:s,dataSource:n,order:d}):null,(0,o.jsx)(W,{dataset:String(e.dataset??``),rows:I(e.rows),values:I(e.values),runtimeFilter:s,dataSource:n,onDrill:c,order:d,withTotals:l===`summary`||l===`matrix`})]})},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),P(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 re(e,t,n={}){let{columns:r,filename:i,includeAggregationRow:a=!1}=n,o=r||(e.fields||[]).map(ae),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 oe(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=se(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)}le(``+[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 ee(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}function M(e,t,n){if(!e)return 0;let r=e.map(e=>Number(e[t])||0);switch(n){case`count`:return e.length;case`sum`:return r.reduce((e,t)=>e+t,0);case`avg`:return r.length>0?(r.reduce((e,t)=>e+t,0)/r.length).toFixed(2):0;case`min`:return r.length>0?Math.min(...r):0;case`max`:return r.length>0?Math.max(...r):0;case`distinct`:return new Set(e.map(e=>e[t])).size;default:return``}}var N=({schema:e,onRefresh:t})=>{let{report:r,data:u,showToolbar:d=!0,allowExport:f=!0,allowPrint:p=!0,loading:m=!1}=e,h=(0,l.useSafeTranslate)(),g=e=>{if(!r){console.warn(`ReportViewer: Cannot export, no report defined`);return}C(e,r,u||[],r.exportConfigs?.[e])},_=h(`common.printDialogHint`,`Opens your browser’s print dialog (not a PDF export)`),v=()=>{window.print()},y=()=>{t?.()},b=(e,t)=>M(u,e,t),x=(e,t)=>{let n=r?.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)}if(a){let e={};return r.backgroundColor&&(e.backgroundColor=r.backgroundColor),r.textColor&&(e.color=r.textColor),e}}},S=(e,t)=>{if(e==null||e===``)return``;if(t.renderAs===`badge`&&(!t.type||t.type===`string`||t.type===`text`)){let n=t.colorMap?.[String(e)]||``;return(0,o.jsx)(a.Badge,{className:n,children:String(e)})}if(t.aggregation)return k(e,t);if(t.type){let n={...t};t.colorMap&&!n.options&&(n.options=Object.entries(t.colorMap).map(([e,t])=>({value:e,label:e,color:t})));let r=(0,c.getCellRenderer)((0,c.resolveCellRendererType)(n));return(0,o.jsx)(r,{value:e,field:n})}return k(e,t)};return r?(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:r.title}),r.description&&(0,o.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:r.description})]}),(0,o.jsxs)(`div`,{className:`flex items-center gap-2`,"data-print-hide":!0,children:[r.refreshInterval&&(0,o.jsxs)(a.Button,{variant:`outline`,size:`sm`,onClick:y,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:v,"aria-label":`Print: ${_}`,title:_,children:[(0,o.jsx)(s.Printer,{className:`h-4 w-4 mr-2`}),`Print`]}),f&&r.showExportButtons&&(0,o.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,o.jsxs)(a.Button,{variant:`outline`,size:`sm`,onClick:()=>g(`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:()=>g(`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:()=>g(`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&&r.title&&(0,o.jsx)(a.CardTitle,{children:r.title}),!d&&r.description&&(0,o.jsx)(a.CardDescription,{children:r.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&&r.sections?.map((e,t)=>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:r.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(b(e.name,e.aggregation),e)})]})},t))}),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=ee(u||[],r.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:x(e.name,t[e.name]),children:S(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:x(e.name,t[e.name]),children:S(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`}),Array.isArray(e.content)?e.content.map((e,t)=>(0,o.jsx)(i.SchemaRenderer,{schema:(0,i.toRenderableSchema)(e)},t)):e.content&&(0,o.jsx)(i.SchemaRenderer,{schema:(0,i.toRenderableSchema)(e.content)})]},t)),!r.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:r.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:r.fields?.map((t,n)=>(0,o.jsx)(`td`,{className:`px-4 py-2 ${t.type===`number`?`text-right tabular-nums`:``}`,style:x(t.name,e[t.name]),children:S(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){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 F(e,t){return e?typeof e==`string`?e:typeof e==`object`&&typeof e.default==`string`?e.default:t:t}function I(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`&&!!e):[]}function L(e){if(!Array.isArray(e))return;let t={};for(let n of e){let e=n&&typeof n==`object`?n.by:void 0;typeof e!=`string`||!e||(t[e]=n.direction===`desc`?`desc`:`asc`)}return Object.keys(t).length>0?t:void 0}function R(e,t,n){if(!e)return;let r=new Set([...t,...n]),i={};for(let[t,n]of Object.entries(e))r.has(t)&&(i[t]=n);return Object.keys(i).length>0?i:void 0}function z(e,t,r,i,a,o,s){let[c,l]=n.useState({status:`idle`,rows:[]}),u=R(s,t,r),d=JSON.stringify(i??null),f=JSON.stringify(o??null),p=JSON.stringify(u??null),m=`${e}|${t.join(`,`)}|${r.join(`,`)}|${d}|${f}|${p}`;return n.useEffect(()=>{let n=a;if(!n||typeof n.queryDataset!=`function`){l({status:`error`,rows:[],error:`This data source does not support dataset queries.`});return}if(!e||r.length===0){l({status:`idle`,rows:[]});return}let s=!1;return l({status:`loading`,rows:[]}),n.queryDataset(e,{dimensions:t,measures:r,...i&&Object.keys(i).length>0?{runtimeFilter:i}:{},...o?{totals:{groupings:o}}:{},...u?{order:u}:{}}).then(e=>{s||l({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,drillRanges:Array.isArray(e?.drillRanges)?e.drillRanges:void 0,totals:Array.isArray(e?.totals)?e.totals:void 0})}).catch(e=>{s||l({status:`error`,rows:[],error:String(e?.message??e)})}),()=>{s=!0}},[m]),c}function B({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 V({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 H(){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 U=`cursor-pointer hover:bg-accent/40`;function W({dataset:e,rows:n,values:r,runtimeFilter:a,dataSource:s,onDrill:c,order:u,withTotals:d}){let f=z(e,n,r,a,s,d&&n.length>0?[[]]:void 0,u),{fieldLabel:p}=(0,l.useSafeFieldLabel)(),m=(0,l.useSafeTranslate)(),h=(0,l.useDisplayLocale)(),g=(0,i.useDatasetDimensionLabels)(f.object,f.dimensionFields,n);if(r.length===0)return(0,o.jsx)(B,{dataset:e});if(f.status===`loading`||f.status===`idle`)return(0,o.jsx)(V,{status:f.status});if(f.status===`error`)return(0,o.jsx)(V,{status:`error`,error:f.error});if(f.rows.length===0)return(0,o.jsx)(H,{});let _=!!c&&n.length>0,v=f.dimensionFields?n.filter(e=>e in f.dimensionFields):[],y=(r,i)=>{let o={};for(let e of n)o[e]=r[e];let s=f.drillRanges?.[i],l=!!s&&Object.keys(s).length>0,u=f.object&&(v.length>0||l)?(0,t.buildDatasetDrillFilter)(f.drillRawRows?.[i],v,f.dimensionFields??{},a,s):void 0;c({dataset:e,groupKey:o,runtimeFilter:a,object:f.object,objectFilter:u})},{measureField:b,headerLabel:x}=(0,t.buildDatasetFieldHelpers)(f.fields,f.object,p),S=[...n,...r],C=(0,t.relabelDimensions)(f.rows,g),w=d?f.totals?.find(e=>Array.isArray(e.dimensions)&&e.dimensions.length===0)?.rows?.[0]:void 0,T=m(`report.total`,`Total`);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:S.map(e=>(0,o.jsx)(`th`,{className:`px-2 py-1.5 text-left font-medium whitespace-nowrap`,children:x(e)},e))})}),(0,o.jsxs)(`tbody`,{children:[C.map((e,n)=>(0,o.jsx)(`tr`,{className:`border-t${_?` ${U}`:``}`,"data-testid":_?`dataset-drill-row`:void 0,onClick:_?()=>y(f.rows[n],n):void 0,children:S.map(n=>(0,o.jsx)(`td`,{className:`px-2 py-1 tabular-nums whitespace-nowrap`,children:r.includes(n)?(0,t.formatMeasure)(e[n],b(n)?.format,b(n)?.currency,b(n)?.percentScale,h):(0,t.formatDimensionValue)(e[n],h)},n))},n)),w&&(0,o.jsxs)(`tr`,{className:`border-t bg-muted/30 font-medium`,"data-testid":`dataset-report-total-row`,children:[n.length>0&&(0,o.jsx)(`td`,{colSpan:n.length,className:`px-2 py-1 whitespace-nowrap`,children:T}),r.map(e=>(0,o.jsx)(`td`,{className:`px-2 py-1 tabular-nums whitespace-nowrap`,children:(0,t.formatMeasure)(w[e],b(e)?.format,b(e)?.currency,b(e)?.percentScale,h)},e))]})]})]})})}function G(e){switch(e){case`summary`:return`summary`;case`matrix`:return`matrix`;case`joined`:return`joined`;default:return`tabular`}}function K(e){switch(e){case`bar`:case`column`:case`horizontal-bar`:case`line`:case`area`:case`pie`:case`donut`:case`funnel`:case`scatter`:case`treemap`:case`sankey`:case`radar`:case`combo`:return{kind:`series`,chartType:e};case`gauge`:case`solid-gauge`:case`metric`:case`kpi`:case`bullet`:return{kind:`single_value`};case`table`:case`pivot`:return{kind:`tabular`};default:return{kind:`unsupported`,type:String(e)}}}function te(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 ne({dataset:e,chart:r,runtimeFilter:a,dataSource:c,order:u}){let d=typeof r.xAxis==`string`?r.xAxis:``,f=typeof r.yAxis==`string`?r.yAxis:``,p=K(r.type),m=p.kind===`series`||p.kind===`single_value`,h=z(e,p.kind===`series`&&d?[d]:[],m&&f?[f]:[],a,c,void 0,u),g=te(`chart`),{fieldLabel:_}=(0,l.useSafeFieldLabel)(),v=(0,l.useDisplayLocale)(),y=n.useMemo(()=>d?[d]:[],[d]),b=(0,i.useDatasetDimensionLabels)(h.object,h.dimensionFields,y),x=typeof r.title==`string`?r.title:void 0;if(p.kind===`tabular`)return null;if(p.kind===`unsupported`)return(0,o.jsxs)(`div`,{className:`rounded-md border border-dashed bg-muted/20 px-3 py-2 text-xs text-muted-foreground`,"data-testid":`dataset-report-chart-unsupported`,children:[`Chart type “`,p.type,`” is not a spec chart type — the grouped table below carries this report’s numbers.`]});if(p.kind===`series`&&!d||!f)return null;if(h.status===`loading`||h.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(h.status===`error`||h.rows.length===0)return null;if(p.kind===`single_value`){let{measureField:e,headerLabel:n}=(0,t.buildDatasetFieldHelpers)(h.fields,h.object,_),r=e(f);return(0,o.jsxs)(`div`,{className:`rounded-md border bg-card p-3`,"data-testid":`dataset-report-metric`,children:[x?(0,o.jsx)(`h3`,{className:`mb-2 text-sm font-semibold`,children:x}):null,(0,o.jsxs)(`div`,{className:`flex flex-col gap-0.5 py-2`,children:[(0,o.jsx)(`span`,{className:`text-2xl font-semibold tabular-nums`,children:(0,t.formatMeasure)(h.rows[0]?.[f],r?.format,r?.currency,r?.percentScale,v)}),(0,o.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:n(f)})]})]})}return g?(0,o.jsxs)(`div`,{className:`rounded-md border bg-card p-3`,"data-testid":`dataset-report-chart`,children:[x?(0,o.jsx)(`h3`,{className:`mb-2 text-sm font-semibold`,children:x}):null,(0,o.jsx)(g,{schema:{chartType:p.chartType,data:(0,t.relabelDimensions)(h.rows,b),xAxisKey:d,series:[{dataKey:f}],height:typeof r.height==`number`?r.height:280,isAnimationActive:!1}})]}):null}function q(e,n){return(0,t.pivotBucketId)(e.map(e=>(0,t.pivotDimensionValue)(n[e])))}function J(e,n,r){return e.map(e=>(0,t.formatDimensionValue)(n[e],r)).join(` / `)}function Y({dataset:e,rows:r,columnsAcross:a,values:s,runtimeFilter:c,dataSource:u,onDrill:d,order:f}){let p=z(e,[...r,...a],s,c,u,[r,a,[]],f),m=(0,l.useSafeTranslate)(),{fieldLabel:h}=(0,l.useSafeFieldLabel)(),g=(0,l.useDisplayLocale)(),_=(0,i.useDatasetDimensionLabels)(p.object,p.dimensionFields,[...r,...a]),v=n.useMemo(()=>{if(p.status!==`ok`)return null;let e=[],n=[],i=new Set,o=new Set,s=new Map;return(0,t.relabelDimensions)(p.rows,_).forEach((c,l)=>{let u=p.rows[l],d=q(r,c),f=q(a,c);if(!i.has(d)){i.add(d);let t={},n={};for(let e of r)t[e]=u[e],n[e]=c[e];e.push({id:d,label:J(r,c,g),key:t,display:n})}if(!o.has(f)){o.add(f);let e={},t={};for(let n of a)e[n]=u[n],t[n]=c[n];n.push({id:f,label:J(a,c,g),key:e,display:t})}s.set((0,t.pivotCellKey)(d,f),{row:u,index:l})}),{rowHeaders:e,colHeaders:n,cells:s}},[p,r,a,_,g]);if(s.length===0)return(0,o.jsx)(B,{dataset:e});if(p.status===`loading`||p.status===`idle`)return(0,o.jsx)(V,{status:p.status});if(p.status===`error`)return(0,o.jsx)(V,{status:`error`,error:p.error});if(!v||v.rowHeaders.length===0)return(0,o.jsx)(H,{});let{measureField:y,headerLabel:b}=(0,t.buildDatasetFieldHelpers)(p.fields,p.object,h),x=m(`report.total`,`Total`),S=!!d,C=p.dimensionFields?[...r,...a].filter(e=>e in p.dimensionFields):[],w=(n,r,i)=>{let a=p.drillRanges?.[i],o=!!a&&Object.keys(a).length>0,s=p.object&&(C.length>0||o)?(0,t.buildDatasetDrillFilter)(p.drillRawRows?.[i],C,p.dimensionFields??{},c,a):void 0;d({dataset:e,groupKey:{...n,...r},runtimeFilter:c,object:p.object,objectFilter:s})},T=v.colHeaders.flatMap(e=>s.map(t=>({col:e,measure:t,header:s.length===1?e.label:`${e.label} · ${b(t)}`}))),E=e=>{let n=p.totals?.find(t=>Array.isArray(t.dimensions)&&t.dimensions.join(`,`)===e.join(`,`))?.rows;return n&&(0,t.relabelDimensions)(n,_)},D=new Map;for(let e of E(r)??[])D.set(q(r,e),e);let O=new Map;for(let e of E(a)??[])O.set(q(a,e),e);let k=E([])?.[0],A=D.size>0,j=O.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:b(e)},e)),T.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}`)),A&&s.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:s.length===1?x:`${x} · ${b(e)}`},`total-${e}`))]})}),(0,o.jsxs)(`tbody`,{children:[v.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.display[n],g)},n)),T.map(n=>{let r=v.cells.get((0,t.pivotCellKey)(e.id,n.col.id)),i=r?.row[n.measure],a=S&&r!=null;return(0,o.jsx)(`td`,{className:`px-2 py-1 text-right tabular-nums whitespace-nowrap${a?` ${U}`:``}`,"data-testid":a?`dataset-drill-cell`:void 0,onClick:a?()=>w(e.key,n.col.key,r.index):void 0,children:(0,t.formatMeasure)(i,y(n.measure)?.format,y(n.measure)?.currency,y(n.measure)?.percentScale,g)},`${n.col.id}-${n.measure}`)}),A&&s.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)(D.get(e.id)?.[n],y(n)?.format,y(n)?.currency,y(n)?.percentScale,g)},`total-${n}`))]},e.id)),j&&(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}),T.map(e=>(0,o.jsx)(`td`,{className:`px-2 py-1 text-right tabular-nums whitespace-nowrap`,children:(0,t.formatMeasure)(O.get(e.col.id)?.[e.measure],y(e.measure)?.format,y(e.measure)?.currency,y(e.measure)?.percentScale,g)},`${e.col.id}-${e.measure}`)),A&&s.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)(k?.[e],y(e)?.format,y(e)?.currency,y(e)?.percentScale,g)},`grand-${e}`))]})]})]})})}var X=({report:e,dataSource:n,runtimeFilter:r,onDrill:i,className:a})=>{let s=(0,t.mergeFilters)(e.runtimeFilter??e.filter,r),c=e.drilldown===!1?void 0:i,l=G(e.type);if(l===`joined`&&Array.isArray(e.blocks))return(0,o.jsx)(`div`,{className:a,"data-testid":`dataset-joined-report`,"data-report-name":e.name,style:{display:`flex`,flexDirection:`column`,gap:24},children:e.blocks.map((e,r)=>{let i=(0,t.mergeFilters)(s,e.runtimeFilter??e.filter),a=I(e.columns),l=L(e.order),u=G(e.type),d=u===`matrix`&&a.length>0?(0,o.jsx)(Y,{dataset:String(e.dataset??``),rows:I(e.rows),columnsAcross:a,values:I(e.values),runtimeFilter:i,dataSource:n,onDrill:c,order:l}):(0,o.jsx)(W,{dataset:String(e.dataset??``),rows:I(e.rows),values:I(e.values),runtimeFilter:i,dataSource:n,onDrill:c,order:l,withTotals:u===`summary`||u===`matrix`});return(0,o.jsxs)(`section`,{"data-testid":`dataset-report-block`,"data-block-id":e.name??`block-${r}`,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:F(e.label,e.name??`Block ${r+1}`)}),e.description?(0,o.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:F(e.description,``)}):null]}),d]},e.name??`block-${r}`)})});let u=I(e.columns),d=L(e.order);if(l===`matrix`&&u.length>0)return(0,o.jsx)(`div`,{className:a,"data-testid":`dataset-report`,"data-report-name":e.name,children:(0,o.jsx)(Y,{dataset:String(e.dataset??``),rows:I(e.rows),columnsAcross:u,values:I(e.values),runtimeFilter:s,dataSource:n,onDrill:c,order:d})});let f=e.chart&&typeof e.chart==`object`&&e.chart.type?e.chart:null;return(0,o.jsxs)(`div`,{className:`${a??``} flex flex-col gap-3`,"data-testid":`dataset-report`,"data-report-name":e.name,"data-report-presentation":l,children:[f?(0,o.jsx)(ne,{dataset:String(e.dataset??``),chart:f,runtimeFilter:s,dataSource:n,order:d}):null,(0,o.jsx)(W,{dataset:String(e.dataset??``),rows:I(e.rows),values:I(e.values),runtimeFilter:s,dataSource:n,onDrill:c,order:d,withTotals:l===`summary`||l===`matrix`})]})},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;if(f&&typeof f==`object`&&f.type===`spec-report`&&f.report&&typeof f.report==`object`&&(f=f.report),P(f))return(0,o.jsx)(X,{report:f,dataSource:d,runtimeFilter:s,onDrill:c,className:l});if((0,r.isSpecReport)(f)){let e={type:`report-viewer`,report:(0,r.specReportToPresentation)(f),data:a??[],showToolbar:!1};return(0,o.jsx)(`div`,{className:l,"data-testid":`report-presentation-bridge`,children:(0,o.jsx)(N,{schema:e})})}return(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 re(e,t,n={}){let{columns:r,filename:i,includeAggregationRow:a=!1}=n,o=r||(e.fields||[]).map(ae),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 oe(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=se(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)}le(``+[s.join(` `),...c.map(e=>e.join(` `))].join(`
|
|
59
59
|
`),i||`${e.title||`report`}.tsv`,`text/tab-separated-values`)}function ie(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 ae(e){return{name:e.name,header:e.label||e.name}}function oe(e,t){return e==null?``:typeof e==`number`&&t?e.toLocaleString(`en-US`,$(t)):ce(String(e))}function $(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 se(e){let t=``,n=e;for(;n>=0;)t=String.fromCharCode(n%26+65)+t,n=Math.floor(n/26)-1;return t}function ce(e){if(e.length>0){let t=e.charAt(0);if(t===`=`||t===`+`||t===`-`||t===`@`||t===`|`)return`'${e}`}return e}function le(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=ie,e.exportAsCSV=v,e.exportAsExcel=S,e.exportAsHTML=b,e.exportAsJSON=y,e.exportAsPDF=x,e.exportExcelWithFormulas=re,e.exportReport=C,e.exportWithLiveData=Q,e.formatValue=k,e.isDatasetReport=P,Object.defineProperty(e,"mergeFilters",{enumerable:!0,get:function(){return t.mergeFilters}})});
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useDatasetDimensionLabels — the analytics label net for dataset-bound
|
|
3
|
+
* REPORTS (objectui#4330), now a RE-EXPORT of the shared hook (objectui#4389).
|
|
4
|
+
*
|
|
5
|
+
* ## What this is
|
|
6
|
+
*
|
|
7
|
+
* The `{dimension → {value|authoredLabel → displayLabel}}` map every surface in
|
|
8
|
+
* `DatasetReportRenderer` relabels its rows through. It is the SAME channel the
|
|
9
|
+
* dashboard's `DatasetWidget` uses, not a report-side dialect — the resolution
|
|
10
|
+
* walk, the option localization and the map construction are all the shared
|
|
11
|
+
* `@object-ui/core` helpers PR #4324 landed:
|
|
12
|
+
*
|
|
13
|
+
* `resolveDimensionFieldMeta` → `localizeFieldOptions` / `buildDimensionLabelMap`
|
|
14
|
+
* → `relabelDimensions` (applied by the caller)
|
|
15
|
+
*
|
|
16
|
+
* and the translator is `useSafeFieldLabel().fieldOptionLabel`, i.e.
|
|
17
|
+
* `{ns}.fieldOptions.<object>.<field>.<value>` — the one convention list and
|
|
18
|
+
* form surfaces already translate select options through. Nothing here decides
|
|
19
|
+
* what a label IS; it only carries the object metadata to the helpers that do.
|
|
20
|
+
*
|
|
21
|
+
* ## Why this file is now three lines (objectui#4389)
|
|
22
|
+
*
|
|
23
|
+
* It used to hold a report-local COPY of the React glue — the context read, the
|
|
24
|
+
* locale-free state, the effect, the memo — because `packages/core` was held by
|
|
25
|
+
* objectui#4040 tranche 5 while #4330 was in flight and that card's surface was
|
|
26
|
+
* the two plugin packages. `DatasetWidget` carried the same shape. The
|
|
27
|
+
* duplication was filed as objectui#4389 and is retired here.
|
|
28
|
+
*
|
|
29
|
+
* The glue did NOT land in `@object-ui/core` as the card originally proposed:
|
|
30
|
+
* that home was disproven by measurement and retired in the card's PM RULING #2
|
|
31
|
+
* — `SchemaRendererContext` is defined in `@object-ui/react`, which depends on
|
|
32
|
+
* core, so core importing it back is a cycle, and core is React-free by
|
|
33
|
+
* declaration, by content, and by AGENTS.md §3. What could legally move into
|
|
34
|
+
* core did (`loadDimensionFieldMeta`, `deriveDimensionLabelMaps`,
|
|
35
|
+
* `dimensionOptionTranslator` — all pure); the React wiring lives once in
|
|
36
|
+
* `@object-ui/react`, which both plugins already depend on.
|
|
37
|
+
*
|
|
38
|
+
* This file stays as the import path so `DatasetReportRenderer`'s three call
|
|
39
|
+
* sites are untouched, and so this rationale keeps a home next to its consumer.
|
|
40
|
+
*
|
|
41
|
+
* ## Why the read is issued at all (the #4263 boundary, amended by #4330)
|
|
42
|
+
*
|
|
43
|
+
* A dataset report renders SERVER-RESOLVED rows (ADR-0021: a local select
|
|
44
|
+
* dimension arrives carrying the object's AUTHORED English option label) and
|
|
45
|
+
* used to load no object metadata whatever, which is exactly why PR #4324
|
|
46
|
+
* carried no change to this package. With no option list on the client there is
|
|
47
|
+
* nothing for the locale bundle to translate against, so a zh-CN report read
|
|
48
|
+
* `Domestic` beside a related list reading 国内. The read is what closes that.
|
|
49
|
+
*
|
|
50
|
+
* It is not gated on "the dimension is a select", because select-ness is not
|
|
51
|
+
* observable before the read: the spec's `DatasetDimension.type` enum is
|
|
52
|
+
* `string|number|date|boolean|lookup` (no `select` member), and a select column
|
|
53
|
+
* arrives on the wire typed `'string'`. The gate lands on the read's OUTPUT
|
|
54
|
+
* instead, where it is exact — `resolveDimensionFieldMeta` returns an entry
|
|
55
|
+
* only for a terminal field that actually carries `options`, so a
|
|
56
|
+
* text/number/date/lookup dimension yields no map and `relabelDimensions`
|
|
57
|
+
* returns the caller's rows by identity.
|
|
58
|
+
*
|
|
59
|
+
* ## The two properties this surface INHERITS rather than restates
|
|
60
|
+
*
|
|
61
|
+
* Both are bug fixes, and both used to be written out here as well as in the
|
|
62
|
+
* dashboard — which is the drift objectui#4389 closed:
|
|
63
|
+
*
|
|
64
|
+
* - the read rides the host's AUTHENTICATED `apiFetch` (objectui#4121);
|
|
65
|
+
* - the fetched metadata stays LOCALE-FREE in state (objectui#4030 / PR #4324),
|
|
66
|
+
* so a language switch re-labels in place instead of re-fetching.
|
|
67
|
+
*
|
|
68
|
+
* They are pinned once, at the shared hook, in
|
|
69
|
+
* `packages/react/src/hooks/__tests__/useDatasetDimensionLabels.test.tsx`.
|
|
70
|
+
*/
|
|
71
|
+
export { useDatasetDimensionLabels, type DimensionLabelMaps } from '@object-ui/react';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@object-ui/plugin-report",
|
|
3
|
-
"version": "17.
|
|
3
|
+
"version": "17.5.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.umd.cjs",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -20,28 +20,28 @@
|
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"clsx": "^2.1.1",
|
|
23
|
-
"lucide-react": "^1.
|
|
23
|
+
"lucide-react": "^1.29.0",
|
|
24
24
|
"react-i18next": "^17.0.11",
|
|
25
25
|
"tailwind-merge": "^3.6.0",
|
|
26
|
-
"@object-ui/components": "17.
|
|
27
|
-
"@object-ui/core": "17.
|
|
28
|
-
"@object-ui/fields": "17.
|
|
29
|
-
"@object-ui/i18n": "17.
|
|
30
|
-
"@object-ui/plugin-grid": "17.
|
|
31
|
-
"@object-ui/react": "17.
|
|
32
|
-
"@object-ui/types": "17.
|
|
26
|
+
"@object-ui/components": "17.5.0",
|
|
27
|
+
"@object-ui/core": "17.5.0",
|
|
28
|
+
"@object-ui/fields": "17.5.0",
|
|
29
|
+
"@object-ui/i18n": "17.5.0",
|
|
30
|
+
"@object-ui/plugin-grid": "17.5.0",
|
|
31
|
+
"@object-ui/react": "17.5.0",
|
|
32
|
+
"@object-ui/types": "17.5.0"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
|
-
"react": "^18.0.0",
|
|
36
|
-
"react-dom": "^18.0.0"
|
|
35
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
36
|
+
"react-dom": "^18.0.0 || ^19.0.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@objectstack/spec": "^17.0.0-rc.
|
|
40
|
-
"@types/node": "^26.1.
|
|
41
|
-
"@types/react": "19.2.
|
|
42
|
-
"@types/react-dom": "19.2.
|
|
43
|
-
"@vitejs/plugin-react": "^6.0.
|
|
44
|
-
"vite": "^8.1
|
|
39
|
+
"@objectstack/spec": "^17.0.0-rc.6",
|
|
40
|
+
"@types/node": "^26.1.2",
|
|
41
|
+
"@types/react": "19.2.18",
|
|
42
|
+
"@types/react-dom": "19.2.4",
|
|
43
|
+
"@vitejs/plugin-react": "^6.0.5",
|
|
44
|
+
"vite": "^8.2.1",
|
|
45
45
|
"vite-plugin-dts": "^5.0.3",
|
|
46
46
|
"vitest": "^4.1.10"
|
|
47
47
|
},
|