@object-ui/plugin-report 4.0.11 → 4.2.1
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 +83 -0
- package/README.md +104 -22
- package/dist/index.js +1695 -551
- package/dist/index.umd.cjs +18 -18
- package/dist/packages/plugin-report/src/JoinedReportRenderer.d.ts +47 -0
- package/dist/packages/plugin-report/src/LegacyReportRenderer.d.ts +14 -0
- package/dist/packages/plugin-report/src/MatrixRenderer.d.ts +51 -0
- package/dist/packages/plugin-report/src/MatrixRenderer.stories.d.ts +24 -0
- package/dist/packages/plugin-report/src/ReportRenderer.d.ts +41 -11
- package/dist/packages/plugin-report/src/SpecReportGrid.d.ts +49 -0
- package/dist/packages/plugin-report/src/SpecReportGrid.stories.d.ts +31 -0
- package/dist/packages/plugin-report/src/buildChartData.d.ts +38 -0
- package/dist/packages/plugin-report/src/drill.d.ts +63 -0
- package/dist/packages/plugin-report/src/hooks/useReportData.d.ts +131 -0
- package/dist/packages/plugin-report/src/index.d.ts +14 -1
- package/package.json +13 -10
package/dist/index.umd.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@object-ui/core`),require(`react`),require(`@object-ui/components`),require(`react/jsx-runtime`),require(`@object-ui/react`),require(`lucide-react`),require(`@object-ui/fields`)):typeof define==`function`&&define.amd?define([`exports`,`@object-ui/core`,`react`,`@object-ui/components`,`react/jsx-runtime`,`@object-ui/react`,`lucide-react`,`@object-ui/fields`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.ObjectUIPluginReport={},e.ObjectUICore,e.React,e.ObjectUIComponents,e.react_jsx_runtime,e.ObjectUIReact,e.lucide_react,e._object_ui_fields))})(this,function(e,t,n,r,i,a,o,s){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var c=Object.create,l=Object.defineProperty,u=Object.getOwnPropertyDescriptor,d=Object.getOwnPropertyNames,f=Object.getPrototypeOf,p=Object.prototype.hasOwnProperty,m=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=d(t),a=0,o=i.length,s;a<o;a++)s=i[a],!p.call(e,s)&&s!==n&&l(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=u(t,s))||r.enumerable});return e};n=((e,t,n)=>(n=e==null?{}:c(f(e)),m(t||!e||!e.__esModule?l(n,`default`,{value:e,enumerable:!0}):n,e)))(n,1);var h=({schema:e})=>{let{title:n,description:a,data:o,columns:s}=e;e.chart?.type;let c=!!e.chart;return(0,i.jsxs)(r.Card,{className:`h-full flex flex-col ${e.className||``}`,children:[(0,i.jsxs)(r.CardHeader,{children:[n&&(0,i.jsx)(r.CardTitle,{children:n}),a&&(0,i.jsx)(r.CardDescription,{children:a})]}),(0,i.jsxs)(r.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,i.jsx)(`div`,{className:`min-h-[300px] border rounded-lg p-4 bg-background/50`,children:(0,i.jsx)(r,{schema:{...e.chart,data:e.chart.data||o}})}):(0,i.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`]})})(),o&&o.length>0&&(0,i.jsx)(`div`,{className:`border rounded-lg`,children:(()=>{let e=t.ComponentRegistry.get(`aggrid`)||t.ComponentRegistry.get(`table`);return e?(0,i.jsx)(e,{schema:{type:`aggrid`,rowData:o,columnDefs:s,domLayout:`autoHeight`}}):(0,i.jsx)(`div`,{className:`overflow-x-auto`,children:(0,i.jsxs)(`table`,{className:`w-full text-sm text-left`,children:[(0,i.jsx)(`thead`,{className:`text-xs uppercase bg-muted`,children:(0,i.jsx)(`tr`,{children:s?.map(e=>(0,i.jsx)(`th`,{className:`px-6 py-3`,children:e.headerName||e.label||e.field},e.field))})}),(0,i.jsx)(`tbody`,{children:o.map((e,t)=>(0,i.jsx)(`tr`,{className:`bg-background border-b`,children:s?.map(t=>(0,i.jsx)(`td`,{className:`px-6 py-4`,children:e[t.field]},t.field))},t))})]})})})()})]})]})};function g(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=C(n),typeof n==`string`&&(n.includes(`,`)||n.includes(`"`)||n.includes(`
|
|
2
|
-
`))?`"${n.replace(/"/g,`""`)}"`:n??``}));
|
|
3
|
-
`),n?.filename||`${e.title||`report`}.csv`,`text/csv`)}function
|
|
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/components`),require(`react/jsx-runtime`),require(`react-i18next`),require(`@object-ui/plugin-grid`),require(`@object-ui/i18n`),require(`@object-ui/react`),require(`lucide-react`),require(`@object-ui/fields`)):typeof define==`function`&&define.amd?define([`exports`,`@object-ui/core`,`react`,`@object-ui/types`,`@object-ui/components`,`react/jsx-runtime`,`react-i18next`,`@object-ui/plugin-grid`,`@object-ui/i18n`,`@object-ui/react`,`lucide-react`,`@object-ui/fields`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.ObjectUIPluginReport={},e.ObjectUICore,e.React,e.ObjectUITypes,e.ObjectUIComponents,e.react_jsx_runtime,e.react_i18next,e._object_ui_plugin_grid,e._object_ui_i18n,e.ObjectUIReact,e.lucide_react,e._object_ui_fields))})(this,function(e,t,n,r,i,a,o,s,c,l,u,d){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var f=Object.create,p=Object.defineProperty,m=Object.getOwnPropertyDescriptor,h=Object.getOwnPropertyNames,g=Object.getPrototypeOf,_=Object.prototype.hasOwnProperty,v=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=h(t),a=0,o=i.length,s;a<o;a++)s=i[a],!_.call(e,s)&&s!==n&&p(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=m(t,s))||r.enumerable});return e};n=((e,t,n)=>(n=e==null?{}:f(g(e)),v(t||!e||!e.__esModule?p(n,`default`,{value:e,enumerable:!0}):n,e)))(n,1);var y=({schema:e})=>{let{title:n,description:r,data:o,columns:s}=e;e.chart?.type;let c=!!e.chart;return(0,a.jsxs)(i.Card,{className:`h-full flex flex-col ${e.className||``}`,children:[(0,a.jsxs)(i.CardHeader,{children:[n&&(0,a.jsx)(i.CardTitle,{children:n}),r&&(0,a.jsx)(i.CardDescription,{children:r})]}),(0,a.jsxs)(i.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,a.jsx)(`div`,{className:`min-h-[300px] border rounded-lg p-4 bg-background/50`,children:(0,a.jsx)(r,{schema:{...e.chart,data:e.chart.data||o}})}):(0,a.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`]})})(),o&&o.length>0&&(0,a.jsx)(`div`,{className:`border rounded-lg`,children:(()=>{let e=t.ComponentRegistry.get(`aggrid`)||t.ComponentRegistry.get(`table`);return e?(0,a.jsx)(e,{schema:{type:`aggrid`,rowData:o,columnDefs:s,domLayout:`autoHeight`}}):(0,a.jsx)(`div`,{className:`overflow-x-auto`,children:(0,a.jsxs)(`table`,{className:`w-full text-sm text-left`,children:[(0,a.jsx)(`thead`,{className:`text-xs uppercase bg-muted`,children:(0,a.jsx)(`tr`,{children:s?.map(e=>(0,a.jsx)(`th`,{className:`px-6 py-3`,children:e.headerName||e.label||e.field},e.field))})}),(0,a.jsx)(`tbody`,{children:o.map((e,t)=>(0,a.jsx)(`tr`,{className:`bg-background border-b`,children:s?.map(t=>(0,a.jsx)(`td`,{className:`px-6 py-4`,children:e[t.field]},t.field))},t))})]})})})()})]})]})};function b(e){return e.aggregate?`${e.field}__${e.aggregate}`:e.field}function x(e,t){if(e==null)return null;let n=e instanceof Date?e:new Date(String(e));if(Number.isNaN(n.getTime()))return null;let r=n.getUTCFullYear(),i=n.getUTCMonth(),a=n.getUTCDate();switch(t){case`year`:return String(r);case`quarter`:return`${r}-Q${Math.floor(i/3)+1}`;case`month`:return`${r}-${String(i+1).padStart(2,`0`)}`;case`week`:{let e=new Date(Date.UTC(r,i,a)),t=e.getUTCDay()||7;e.setUTCDate(e.getUTCDate()+4-t);let n=new Date(Date.UTC(e.getUTCFullYear(),0,1)),o=Math.ceil(((e.getTime()-n.getTime())/864e5+1)/7);return`${e.getUTCFullYear()}-W${String(o).padStart(2,`0`)}`}case`day`:return`${r}-${String(i+1).padStart(2,`0`)}-${String(a).padStart(2,`0`)}`;default:return String(e)}}function S(e,t){let n=e[t.field];return t.dateGranularity?x(n,t.dateGranularity)??`(empty)`:n==null||n===``?`(empty)`:String(n)}function C(e,t){let n={};for(let r of t){if(!r.aggregate){let t=e.find(e=>e[r.field]!=null);n[b(r)]=t?t[r.field]:null;continue}let t=e.map(e=>e[r.field]);switch(r.aggregate){case`count`:n[b(r)]=t.length;break;case`unique`:{let e=new Set;for(let n of t)n!=null&&e.add(n);n[b(r)]=e.size;break}case`sum`:{let e=0;for(let n of t)e+=Number(n)||0;n[b(r)]=e;break}case`avg`:{let e=0,i=0;for(let n of t){if(n==null||n===``)continue;let t=Number(n);Number.isNaN(t)||(e+=t,i+=1)}n[b(r)]=i===0?null:e/i;break}case`min`:{let e=null;for(let n of t){if(n==null)continue;let t=Number(n);Number.isNaN(t)||(e===null||t<e)&&(e=t)}n[b(r)]=e;break}case`max`:{let e=null;for(let n of t){if(n==null)continue;let t=Number(n);Number.isNaN(t)||(e===null||t>e)&&(e=t)}n[b(r)]=e;break}default:n[b(r)]=null}}return n}function w(e,t,n,r={},i=[]){if(t.length===0)return[];let[a,...o]=t,s=new Map;for(let t of e){let e=S(t,a),n=s.get(e);n||(n=[],s.set(e,n)),n.push(t)}let c=[];for(let[e,t]of s){let s={...r,[a.field]:e},l=[...i,e],u=C(t,n),d=o.length>0?w(t,o,n,s,l):void 0;c.push({groupKey:s,groupPath:l,values:u,count:t.length,children:d})}let l=a.sort===`desc`?-1:1;return c.sort((e,t)=>{let n=String(e.groupPath[e.groupPath.length-1]),r=String(t.groupPath[t.groupPath.length-1]);return n.localeCompare(r)*l}),typeof a.limit==`number`&&a.limit>0?c.slice(0,a.limit):c}function T(e,t,n,r){let i=E(e,n),a=E(e,r),o={},s={},c={};for(let c of i){o[c.id]={};let i=D(e,c.key,n);s[c.id]=C(i,t);for(let e of a){let n=D(i,e.key,r);n.length!==0&&(o[c.id][e.id]=C(n,t))}}for(let n of a){let i=D(e,n.key,r);c[n.id]=C(i,t)}return{rowHeaders:i,colHeaders:a,cells:o,rowTotals:s,colTotals:c,grandTotal:C(e,t),columns:t,downGroupings:n,acrossGroupings:r}}function E(e,t){if(t.length===0)return[{key:{},path:[],id:``}];let n=new Map;for(let r of e){let e=[],i={};for(let n of t){let t=S(r,n);e.push(t),i[n.field]=t}let a=e.join(``);n.has(a)||n.set(a,{key:i,path:e,id:a})}let r=Array.from(n.values());r.sort((e,n)=>{for(let r=0;r<t.length;r++){let i=t[r].sort===`desc`?-1:1,a=e.path[r].localeCompare(n.path[r])*i;if(a!==0)return a}return 0});let i=t[0].limit;if(typeof i==`number`&&i>0){let e=new Set;for(let t of r)e.size>=i&&!e.has(t.path[0])||e.add(t.path[0]);return r.filter(t=>e.has(t.path[0]))}return r}function D(e,t,n){let r=Object.entries(t);if(r.length===0)return e;let i=new Map;for(let e of n)i.set(e.field,e);return e.filter(e=>{for(let[t,n]of r){let r=i.get(t);if((r?S(e,r):e[t]==null?`(null)`:String(e[t]))!==String(n))return!1}return!0})}function O(e,t){let n={};for(let r of t){if(!r.aggregate)continue;let t=b(r),i=0,a=0,o=null,s=null;for(let n of e){let e=n[t];typeof e==`number`&&(i+=e,a+=1,(o==null||e<o)&&(o=e),(s==null||e>s)&&(s=e))}r.aggregate===`min`?n[t]=o:r.aggregate===`max`?n[t]=s:r.aggregate===`avg`?n[t]=a===0?null:i/a:n[t]=i}return n}function k(e,t,n,r){let i=A(e,n),a=A(e,r),o={},s={},c={};for(let n of i){o[n.id]={};let r=e.filter(e=>j(e,n.key));s[n.id]=O(r,t);for(let e of a){let i=r.filter(t=>j(t,e.key));if(i.length===0)continue;let a={};for(let e of t){if(!e.aggregate)continue;let t=b(e);a[t]=i[0][t]}o[n.id][e.id]=a}}for(let n of a){let r=e.filter(e=>j(e,n.key));c[n.id]=O(r,t)}return{rowHeaders:i,colHeaders:a,cells:o,rowTotals:s,colTotals:c,grandTotal:O(e,t),columns:t,downGroupings:n,acrossGroupings:r}}function A(e,t){if(t.length===0)return[{key:{},path:[],id:``}];let n=new Map;for(let r of e){let e=[],i={};for(let n of t){let t=r[n.field],a=t==null?`(null)`:String(t);e.push(a),i[n.field]=a}let a=e.join(``);n.has(a)||n.set(a,{key:i,path:e,id:a})}let r=Array.from(n.values());return r.sort((e,n)=>{for(let r=0;r<t.length;r++){let i=t[r].sort===`desc`?-1:1,a=e.path[r].localeCompare(n.path[r])*i;if(a!==0)return a}return 0}),r}function j(e,t){for(let[n,r]of Object.entries(t))if((e[n]==null?`(null)`:String(e[n]))!==String(r))return!1;return!0}function M(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 N(e){let t=new Set;for(let n of e.groupingsDown??[])t.add(n.field);for(let n of e.groupingsAcross??[])t.add(n.field);for(let n of e.columns??[])t.add(n.field);for(let n of e.sort??[])t.add(n.field);return Array.from(t)}function P(e,t,n){let r=[...e.groupingsDown??[],...e.groupingsAcross??[]],i=(e.columns??[]).filter(e=>!!e.aggregate);if(r.length===0&&i.length===0)return null;let a=r.map(e=>e.dateGranularity?{field:e.field,dateGranularity:e.dateGranularity}:e.field),o=i.map(e=>({function:e.aggregate===`unique`?`count_distinct`:e.aggregate,field:e.field,alias:b(e)})),s=M(e.filter,t),c={object:e.objectName,limit:n};return a.length>0&&(c.groupBy=a),o.length>0&&(c.aggregations=o),s&&(c.where=s),c}function F(e,t,n){for(let[r,i]of Object.entries(t)){let t=n.find(e=>e.field===r);if((t?S(e,t):String(e[r]??`(empty)`))!==String(i))return!1}return!0}var I=[];function L(e,t={}){let{dataSource:r,runtimeFilter:i,maxRows:a=5e3,enabled:o=!0,rows:s,preferServerAggregation:c=!0}=t,[l,u]=(0,n.useState)(s??I),[d,f]=(0,n.useState)(!1),[p,m]=(0,n.useState)(!1),[h,g]=(0,n.useState)(null),_=(0,n.useRef)(0),v=(0,n.useCallback)(async()=>{if(!e||!o)return;if(s){u(s),f(!1);return}if(!r){u(I);return}let t=++_.current;m(!0),g(null);try{let n=c?P(e,i,a):null;if(n&&typeof r.aggregate==`function`)try{let i=R(await r.aggregate(e.objectName,n));if(t!==_.current)return;u(i),f(!0);return}catch(e){typeof console<`u`&&console.warn&&console.warn(`[useReportData] dataSource.aggregate() failed, falling back to find():`,e)}if(typeof r.find!=`function`){u(I),f(!1);return}let o=M(e.filter,i),s=N(e),l={$top:a};o&&(l.$filter=o),s.length>0&&(l.$select=s),e.sort&&e.sort.length>0&&(l.$orderBy=e.sort.map(e=>`${e.field} ${e.direction??`asc`}`).join(`,`));let d=R(await r.find(e.objectName,l));if(t!==_.current)return;u(d),f(!1)}catch(e){if(t!==_.current)return;g(e instanceof Error?e:Error(String(e))),u(I),f(!1)}finally{t===_.current&&m(!1)}},[e,o,s,r,i,a,c]);(0,n.useEffect)(()=>{v()},[v]);let{rows:y,totals:b,pivot:x}=(0,n.useMemo)(()=>{if(!e)return{rows:[],totals:{},pivot:null};let t=e.groupingsDown??[],n=e.groupingsAcross??[],r=e.columns??[],i=n.length>0;if(d){let e=[...t,...n],a=l.map(t=>{let n={},r=[];for(let i of e){let e=t[i.field];n[i.field]=e,r.push(e==null?`(null)`:String(e))}let i={...t};for(let t of e)delete i[t.field];return{groupKey:n,groupPath:r,values:i,count:1}}),o=O(l,r),s=i?k(l,r,t,n):null;return{rows:i&&s?s.rowHeaders.map(e=>({groupKey:e.key,groupPath:e.path,values:s.rowTotals[e.id]??{},count:1})):a,totals:o,pivot:s}}let a=i?t:[...t,...n];return{rows:a.length>0?w(l,a,r):l.map(e=>({groupKey:{},groupPath:[],values:r.length>0?C([e],r):{...e},count:1})),totals:C(l,r),pivot:i?T(l,r,t,n):null}},[e,l,d]);return{rows:y,rawRows:l,totals:b,pivot:x,serverAggregated:d,loading:p,error:h,refetch:v,drillDown:(0,n.useCallback)(t=>{if(!e)return[];let n=[...e.groupingsDown??[],...e.groupingsAcross??[]];return l.filter(e=>F(e,t,n))},[e,l])}}function R(e){if(Array.isArray(e))return e;if(e&&typeof e==`object`){let t=e;if(Array.isArray(t.data))return t.data;if(Array.isArray(t.records))return t.records;if(Array.isArray(t.results))return t.results;if(Array.isArray(t.value))return t.value}return I}function ee(e){return e.aggregate?`${e.field}__${e.aggregate}`:e.field}function te(e){let t=[],n=e=>{e.children&&e.children.length>0?e.children.forEach(n):t.push(e)};return e.forEach(n),t}function ne({report:e,rows:t,labels:n}){let r=e.chart;if(!r||!r.type)return{schema:null};let i=e.groupingsDown??[],a=r.xAxis||(i.length>0?i[0]?.field:void 0);if(!a)return{schema:null,diagnostic:`chart.xAxis missing and no groupingsDown[0] to default to.`};let o=e.columns??[],s=r.yAxis,c=`count`,l=`Count`,u=!0;if(s){let e=o.find(e=>e.field===s&&e.aggregate);e?(c=ee(e),l=n?.resolveColumnLabel?.(e)??(typeof e.label==`string`?e.label:`${e.aggregate}(${e.field})`),u=!1):(c=`count`,l=n?.resolveCountLabel?.(s)??`Count of ${s}`)}let d=te(t),f=new Map;for(let e of d){let t=e.groupKey[a];if(t===void 0)continue;let n=String(t??``),r=u?e.count:Number(e.values[c]??0),i=f.get(n);i?i.measure+=Number.isFinite(r)?r:0:f.set(n,{x:t,measure:Number.isFinite(r)?r:0})}let p=Array.from(f.values()).map(e=>{let t=n?.resolveAxisValue?.(a,e.x)??e.x??`(null)`;return{[a]:t,[c]:e.measure}});return(r.type===`pie`||r.type===`donut`||r.type===`funnel`)&&(p=[...p].sort((e,t)=>Number(t[c]??0)-Number(e[c]??0))),{schema:{type:`chart`,chartType:r.type,data:p,xAxisKey:a,series:[{dataKey:c,label:l}],title:r.title,showLegend:r.showLegend??!0,showDataLabels:r.showDataLabels??!1,className:`w-full h-[320px]`}}}function z(e,t,n={}){let r=M(M(e.filter,n.runtimeFilter),Object.keys(t).length>0?t:void 0);return{type:`drill`,name:`drill-${e.name}`,objectName:e.objectName,...r?{filter:r}:{},view:n.view??`list`,...n.recordId===void 0?{}:{recordId:n.recordId},openIn:n.openIn??`current`}}function re(e){return!!e&&e.type===`drill`}function ie(e){return async t=>{if(!re(t))return{success:!1,error:`drill handler invoked with non-drill action`};try{return await e.navigate({objectName:t.objectName,filter:t.filter,view:t.view,recordId:t.recordId,openIn:t.openIn}),{success:!0}}catch(e){return{success:!1,error:e instanceof Error?e.message:String(e)}}}}function ae(e,t){return e.registerHandler(`drill`,ie(t)),()=>e.unregisterHandler(`drill`)}function oe(e){return e?e===`unique`?`count_distinct`:e:null}function se(e){if(!(!e||e.length===0))return{fields:e.map(e=>({field:e.field,order:e.sort??`asc`,collapsed:!1}))}}function ce(e){return(e.columns??[]).map(e=>{let t={field:e.field};return e.label&&(t.label=typeof e.label==`string`?e.label:String(e.label)),e.format&&(t.format=e.format),e.width&&(t.width=e.width),t})}var le={padding:`12px 16px`,border:`1px dashed rgb(203 213 225)`,borderRadius:8,color:`rgb(100 116 139)`,fontSize:14},B=({report:e,dataSource:t,rows:r,runtimeFilter:i,onDrillDown:u,actionRunner:d,drillView:f,drillOpenIn:p,className:m})=>{let h=e.type??`tabular`,{t:g}=(0,o.useTranslation)(),{fieldLabel:_,translateOptions:v}=(0,c.useSafeFieldLabel)(),[y,x]=n.useState(null);n.useEffect(()=>{let n=t;if(!n||typeof n.getObjectSchema!=`function`||!e.objectName)return;let r=!1;return n.getObjectSchema(e.objectName).then(e=>{r||x(e??null)}).catch(()=>{}),()=>{r=!0}},[t,e.objectName]);let S=n.useCallback(t=>{if(t.label)return String(t.label);let n=y?.fields?.[t.field]?.label??t.field,r=_(e.objectName,t.field,n);return t.aggregate?`${r} · ${g(`report.aggregate.${t.aggregate}`,t.aggregate)}`:r},[y,e.objectName,_,g]),C=n.useCallback((t,n)=>{if(n==null)return;let r=y?.fields?.[t];if(!r||!(r.type===`select`||r.type===`status`)||!Array.isArray(r.options)||r.options.length===0)return;let i=v(e.objectName,t,r.options),a=String(n);for(let e of i)if(e&&e.value!==void 0&&e.value!==null&&String(e.value)===a)return e.label==null?a:String(e.label)},[y,e.objectName,v]),{rawRows:w,rows:T,totals:E,serverAggregated:D,loading:O,error:k,drillDown:A}=L(e,{dataSource:t,rows:r,runtimeFilter:i});if(h===`matrix`||h===`joined`)return(0,a.jsxs)(`div`,{className:m,style:le,children:[`Report type `,(0,a.jsx)(`code`,{children:h}),` is not yet supported by SpecReportGrid. It will be rendered by a dedicated component in M2 (matrix) / M3 (joined).`]});let j=n.useMemo(()=>{if(D){let t=(e.groupingsDown??[]).map(e=>({field:e.field,label:e.field.replace(/_/g,` `).replace(/\b\w/g,e=>e.toUpperCase())})),n=(e.columns??[]).filter(e=>e.aggregate).map(e=>({field:b(e),label:`${(typeof e.label==`string`?e.label:null)??e.field} (${e.aggregate})`,...e.format?{format:e.format}:{}}));return{type:`object-grid`,objectName:e.objectName,columns:[...t,...n]}}let t=h===`summary`?se(e.groupingsDown):void 0,n=(e.columns??[]).map(e=>{let t=oe(e.aggregate);return t?{field:e.field,type:t}:null}).filter(e=>e!==null);return{type:`object-grid`,objectName:e.objectName,columns:ce(e),grouping:t,aggregations:n.length>0?n:void 0}},[e,h,D]),M=w,N=n.useCallback(t=>{let n=e.groupingsDown??[],r={};for(let e of n)r[e.field]=t[e.field];if(d){let t=z(e,r,{runtimeFilter:i,view:f,openIn:p});d.execute(t)}u&&u(r,A(r))},[d,A,p,f,u,e,i]),P=!!u||!!d,F=(e.columns??[]).filter(e=>e.aggregate),I=F.length>0&&E&&Object.keys(E).length>0,R=n.useMemo(()=>h!==`summary`||!e.chart||!e.chart.type?null:ne({report:e,rows:T,labels:{resolveColumnLabel:S,resolveCountLabel:t=>{let n=y?.fields?.[t]?.label??t;return`${_(e.objectName,t,n)} · ${g(`report.aggregate.count`,`Count`)}`},resolveAxisValue:C}}).schema,[e,T,h,S,C,y,_,g]);return(0,a.jsxs)(`div`,{className:m,"data-testid":`spec-report-grid`,"aria-busy":O||void 0,children:[k?(0,a.jsx)(`div`,{role:`alert`,style:{...le,color:`rgb(190 18 60)`},children:k.message}):null,I?(0,a.jsxs)(`div`,{"data-testid":`spec-report-totals`,className:`mb-3 flex flex-wrap items-baseline gap-x-6 gap-y-1 rounded-md border bg-muted/40 px-3 py-2 text-sm`,children:[(0,a.jsx)(`span`,{className:`text-xs font-medium uppercase tracking-wide text-muted-foreground`,children:g(`report.totals`,`Totals`)}),F.map(e=>{let t=b(e),n=E[t],r=S(e),i=typeof n==`number`?n.toLocaleString(void 0,{maximumFractionDigits:2}):String(n??`—`);return(0,a.jsxs)(`span`,{"data-testid":`spec-report-total-${t}`,className:`inline-flex items-baseline gap-1.5`,children:[(0,a.jsxs)(`span`,{className:`text-muted-foreground`,children:[r,`:`]}),(0,a.jsx)(`span`,{className:`font-mono font-medium tabular-nums`,children:i})]},t)})]}):null,R?(0,a.jsx)(`div`,{className:`mb-4`,"data-testid":`spec-report-chart`,children:(0,a.jsx)(l.SchemaRenderer,{schema:R})}):null,(0,a.jsx)(s.ObjectGrid,{schema:j,data:M,dataSource:t,onRowClick:P?N:void 0})]})};B.displayName=`SpecReportGrid`;var V=`—`;function H(e){return e==null?V:typeof e==`number`?e.toLocaleString():String(e)}function ue(e,t,n){if(e==null||e===``||e===`(null)`)return n;let r=t?.options;if(r){let t=r.get(e);if(t!==void 0&&t!==``)return t}return e}function U({header:e,groupings:t,metaByField:n,fallback:r,emptyLabel:i}){return e.path.length===0?(0,a.jsx)(a.Fragment,{children:r}):(0,a.jsx)(a.Fragment,{children:e.path.map((e,r)=>{let a=t[r]?.field;return ue(e,a?n.get(a):void 0,i)}).join(` / `)})}var de=({report:e,dataSource:t,rows:r,runtimeFilter:i,onCellClick:s,actionRunner:l,drillView:u,drillOpenIn:d,className:f,emptyCellText:p=V})=>{let{pivot:m,loading:h,error:g}=L(e,{dataSource:t,rows:r,runtimeFilter:i}),_=e.columns??[],v=_.length>1,{fieldLabel:y,translateOptions:x}=(0,c.useSafeFieldLabel)(),{t:S}=(0,o.useTranslation)(),C=S(`report.emptyLabel`,`(Empty)`),w=S(`report.allLabel`,`(All)`),[T,E]=n.useState(null);n.useEffect(()=>{let n=t;if(!n||typeof n.getObjectSchema!=`function`||!e.objectName)return;let r=!1;return n.getObjectSchema(e.objectName).then(e=>{r||E(e??null)}).catch(()=>{}),()=>{r=!0}},[t,e.objectName]);let D=e.groupingsDown??[],O=e.groupingsAcross??[],k=n.useMemo(()=>{let t=new Map,n=T?.fields??{},r=[...D,...O];for(let i of r){let r=n[i.field],a=r?.label??i.field,o=y(e.objectName,i.field,a),s=r?.type===`select`||r?.type===`status`,c;if(s&&Array.isArray(r?.options)&&r.options.length>0){let t=x(e.objectName,i.field,r.options);c=new Map;for(let e of t)e&&e.value!==void 0&&e.value!==null&&c.set(String(e.value),e.label==null?String(e.value):String(e.label))}t.set(i.field,{fieldLabel:o,options:c})}return t},[T,D,O,e.objectName,y,x]),A=n.useMemo(()=>{let t=new Map,n=T?.fields??{};for(let r of _){let i=b(r);if(r.label){t.set(i,String(r.label));continue}let a=n[r.field]?.label??r.field,o=y(e.objectName,r.field,a);if(r.aggregate){let e=S(`report.aggregate.${r.aggregate}`,r.aggregate);t.set(i,`${o} · ${e}`)}else t.set(i,o)}return t},[_,T,e.objectName,y,S]),j=n.useCallback((t,n,r)=>{let a={...t.key,...n.key};if(l){let t=z(e,a,{runtimeFilter:i,view:u,openIn:d});l.execute(t)}s&&s({rowKey:t.key,colKey:n.key,combinedKey:a,values:r})},[l,d,u,s,e,i]);if(g)return(0,a.jsx)(`div`,{className:f,role:`alert`,"data-testid":`matrix-error`,children:S(`report.failedToLoad`,`Failed to load matrix: {{message}}`,{message:g.message})});if(!m)return(0,a.jsx)(`div`,{className:f,"aria-busy":h||void 0,"data-testid":`matrix-empty`,children:h?S(`report.loading`,`Loading…`):S(`report.needsAcross`,"Matrix report requires at least one `groupingsAcross` field.")});let M=!!s||!!l,N=D.map(e=>k.get(e.field)?.fieldLabel??e.field).join(` / `)||S(`report.rowsLabel`,`Row`),P=O.map(e=>k.get(e.field)?.fieldLabel??e.field).join(` / `)||S(`report.columnsLabel`,`Column`);return(0,a.jsx)(`div`,{className:f,"data-testid":`matrix-renderer`,"aria-busy":h||void 0,style:{overflow:`auto`},children:(0,a.jsxs)(`table`,{role:`table`,style:{borderCollapse:`collapse`,minWidth:`100%`,fontSize:13},children:[(0,a.jsx)(`thead`,{children:(0,a.jsxs)(`tr`,{children:[(0,a.jsxs)(`th`,{scope:`col`,style:G({header:!0,bold:!0}),"aria-label":`${N} \u2192 ${P}`,children:[N,` \\ `,P]}),m.colHeaders.map(e=>(0,a.jsx)(`th`,{scope:`col`,style:G({header:!0}),children:(0,a.jsx)(U,{header:e,groupings:O,metaByField:k,fallback:w,emptyLabel:C})},`col-${e.id}`)),(0,a.jsx)(`th`,{scope:`col`,style:G({header:!0,total:!0}),children:S(`report.rowTotal`,`Row Total`)})]})}),(0,a.jsx)(`tbody`,{children:m.rowHeaders.map(e=>(0,a.jsxs)(`tr`,{children:[(0,a.jsx)(`th`,{scope:`row`,style:G({header:!0}),children:(0,a.jsx)(U,{header:e,groupings:D,metaByField:k,fallback:w,emptyLabel:C})}),m.colHeaders.map(t=>{let n=m.cells[e.id]?.[t.id],r=!n;return(0,a.jsx)(`td`,{style:G({interactive:M&&!r,empty:r}),onClick:M&&!r?()=>j(e,t,n):void 0,"data-row":e.id,"data-col":t.id,children:r?p:W(_,n,v,A)},`cell-${e.id}-${t.id}`)}),(0,a.jsx)(`td`,{style:G({total:!0}),children:W(_,m.rowTotals[e.id]??{},v,A)})]},`row-${e.id}`))}),(0,a.jsx)(`tfoot`,{children:(0,a.jsxs)(`tr`,{children:[(0,a.jsx)(`th`,{scope:`row`,style:G({header:!0,total:!0}),children:S(`report.columnTotal`,`Column Total`)}),m.colHeaders.map(e=>(0,a.jsx)(`td`,{style:G({total:!0}),children:W(_,m.colTotals[e.id]??{},v,A)},`coltotal-${e.id}`)),(0,a.jsx)(`td`,{style:G({total:!0,grand:!0}),children:W(_,m.grandTotal,v,A)})]})})]})})};function W(e,t,n,r){return e.length?n?(0,a.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:2},children:e.map(e=>{let n=b(e);return(0,a.jsxs)(`div`,{style:{display:`flex`,justifyContent:`space-between`,gap:8},children:[(0,a.jsx)(`span`,{style:{color:`var(--color-muted-foreground, #71717a)`},children:r?.get(n)??e.label??n}),(0,a.jsx)(`span`,{children:H(t[n])})]},n)})}):H(t[b(e[0])]):V}function G(e){return{border:`1px solid var(--color-border, #e4e4e7)`,padding:`6px 10px`,textAlign:e.header?`left`:`right`,fontWeight:e.bold||e.grand?700:e.header||e.total?600:400,background:e.grand?`var(--color-muted, #f4f4f5)`:e.total?`var(--color-muted, #fafafa)`:e.header?`var(--color-muted, #f9fafb)`:e.empty?`transparent`:`var(--color-background, #ffffff)`,color:e.empty?`var(--color-muted-foreground, #a1a1aa)`:void 0,cursor:e.interactive?`pointer`:void 0,whiteSpace:`nowrap`}}function fe(e,t){return e?typeof e==`string`?e:typeof e==`object`&&typeof e.default==`string`?e.default:t:t}function pe(e,t){if(!t||Object.keys(t).length===0)return e;let n=M(t,e.filter);return{...e,filter:n}}var me=({report:e,dataSource:t,runtimeFilter:n,actionRunner:i,drillView:o,drillOpenIn:s,className:c,renderBlock:l})=>{if(!(0,r.isJoinedSpecReport)(e))return(0,a.jsxs)(`div`,{className:c,"data-testid":`joined-report-invalid`,style:{color:`var(--color-destructive, #b91c1c)`,fontSize:13,padding:12},children:[`JoinedReportRenderer requires a report with `,(0,a.jsx)(`code`,{children:`type: 'joined'`}),` and a `,(0,a.jsx)(`code`,{children:`blocks`}),` array.`]});let u=e.blocks??[],d=e.filter,f=e.objectName;return(0,a.jsx)(`div`,{className:c,"data-testid":`joined-report`,"data-report-name":e.name,style:{display:`flex`,flexDirection:`column`,gap:24},children:u.map((e,r)=>{let c=e.objectName??f??``,u=pe({...e,objectName:c,type:e.type??`tabular`,columns:e.columns??[]},d),p=fe(e.label,e.name),m=e.description?fe(e.description,``):``,h=e.name??`block-${r}`,g=(0,a.jsxs)(`section`,{"data-testid":`joined-report-block`,"data-block-id":h,style:{display:`flex`,flexDirection:`column`,gap:8,border:`1px solid var(--color-border, #e4e4e7)`,borderRadius:8,padding:16,background:`var(--color-card, #ffffff)`},children:[(0,a.jsxs)(`header`,{style:{display:`flex`,flexDirection:`column`,gap:2},children:[(0,a.jsx)(`h3`,{style:{margin:0,fontSize:16,fontWeight:600},children:p}),m?(0,a.jsx)(`p`,{style:{margin:0,fontSize:13,color:`var(--color-muted-foreground, #71717a)`},children:m}):null]}),(0,a.jsx)(K,{schema:u,dataSource:t,runtimeFilter:n,actionRunner:i,drillView:o,drillOpenIn:s})]},h);return l?l(e,r,g):g})})},he={border:`1px dashed var(--color-border, #d4d4d8)`,borderRadius:8,padding:16,color:`var(--color-muted-foreground, #71717a)`,background:`var(--color-muted, #f4f4f5)`,fontSize:13},K=e=>{let{dataSource:t,rows:n,runtimeFilter:i,actionRunner:o,drillView:s,drillOpenIn:c,className:l}=e,u=e.schema;if(u&&typeof u==`object`&&u.type===`spec-report`&&u.report&&typeof u.report==`object`&&(u=u.report),(0,r.isSpecReport)(u)){let e=u.type??`tabular`;return e===`matrix`?(0,a.jsx)(de,{report:u,dataSource:t,rows:n,runtimeFilter:i,actionRunner:o,drillView:s,drillOpenIn:c,className:l}):e===`joined`?(0,r.isJoinedSpecReport)(u)?(0,a.jsx)(me,{report:u,dataSource:t,runtimeFilter:i,actionRunner:o,drillView:s,drillOpenIn:c,className:l}):(0,a.jsxs)(`div`,{className:l,style:he,"data-testid":`report-joined-placeholder`,children:[`Joined report (`,(0,a.jsx)(`code`,{children:u.name}),`) is missing a `,(0,a.jsx)(`code`,{children:`blocks`}),` array.`]}):(0,a.jsx)(B,{report:u,dataSource:t,rows:n,runtimeFilter:i,actionRunner:o,drillView:s,drillOpenIn:c,className:l})}return(0,a.jsx)(y,{schema:u})};function ge(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=be(n),typeof n==`string`&&(n.includes(`,`)||n.includes(`"`)||n.includes(`
|
|
2
|
+
`))?`"${n.replace(/"/g,`""`)}"`:n??``}));X([...n?.includeHeaders===!1?[]:[i.join(`,`)],...a.map(e=>e.join(`,`))].join(`
|
|
3
|
+
`),n?.filename||`${e.title||`report`}.csv`,`text/csv`)}function _e(e,t,n){let r={title:e.title,description:e.description,generatedAt:new Date().toISOString(),data:t};X(JSON.stringify(r,null,2),n?.filename||`${e.title||`report`}.json`,`application/json`)}function q(e,t,n){let r=e.fields||[],i=Se(n?.orientation),a=xe(n?.pageSize);X(`<!DOCTYPE html>
|
|
4
4
|
<html>
|
|
5
5
|
<head>
|
|
6
6
|
<meta charset="utf-8">
|
|
7
|
-
<title>${
|
|
7
|
+
<title>${Y(e.title||`Report`)}</title>
|
|
8
8
|
<style>
|
|
9
9
|
@page { size: ${a} ${i}; margin: 20mm; }
|
|
10
10
|
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; color: #333; }
|
|
@@ -18,19 +18,19 @@
|
|
|
18
18
|
</style>
|
|
19
19
|
</head>
|
|
20
20
|
<body>
|
|
21
|
-
<h1>${
|
|
22
|
-
${e.description?`<p class="description">${
|
|
21
|
+
<h1>${Y(e.title||`Report`)}</h1>
|
|
22
|
+
${e.description?`<p class="description">${Y(e.description)}</p>`:``}
|
|
23
23
|
<p class="meta">Generated: ${new Date().toLocaleString()}</p>
|
|
24
24
|
<table>
|
|
25
|
-
<thead><tr>${r.map(e=>`<th>${
|
|
26
|
-
<tbody>${t.map(e=>`<tr>${r.map(t=>`<td>${
|
|
25
|
+
<thead><tr>${r.map(e=>`<th>${Y(e.label||e.name)}</th>`).join(``)}</tr></thead>
|
|
26
|
+
<tbody>${t.map(e=>`<tr>${r.map(t=>`<td>${Y(String(e[t.name]??``))}</td>`).join(``)}</tr>`).join(``)}</tbody>
|
|
27
27
|
</table>
|
|
28
28
|
</body>
|
|
29
|
-
</html>`,n?.filename||`${e.title||`report`}.html`,`text/html`)}function
|
|
29
|
+
</html>`,n?.filename||`${e.title||`report`}.html`,`text/html`)}function ve(e,t,n){let r=e.fields||[],i=Se(n?.orientation),a=xe(n?.pageSize),o=window.open(``,`_blank`);if(!o){q(e,t,{...n,format:`html`,filename:n?.filename?.replace(/\.pdf$/,`.html`)||`${e.title||`report`}.html`});return}o.document.write(`<!DOCTYPE html>
|
|
30
30
|
<html>
|
|
31
31
|
<head>
|
|
32
32
|
<meta charset="utf-8">
|
|
33
|
-
<title>${
|
|
33
|
+
<title>${Y(e.title||`Report`)}</title>
|
|
34
34
|
<style>
|
|
35
35
|
@page { size: ${a} ${i}; margin: 20mm; }
|
|
36
36
|
@media print { .no-print { display: none; } }
|
|
@@ -45,15 +45,15 @@ ${e.description?`<p class="description">${S(e.description)}</p>`:``}
|
|
|
45
45
|
</style>
|
|
46
46
|
</head>
|
|
47
47
|
<body>
|
|
48
|
-
<h1>${
|
|
49
|
-
${e.description?`<p class="description">${
|
|
48
|
+
<h1>${Y(e.title||`Report`)}</h1>
|
|
49
|
+
${e.description?`<p class="description">${Y(e.description)}</p>`:``}
|
|
50
50
|
<p class="meta">Generated: ${new Date().toLocaleString()}</p>
|
|
51
51
|
<table>
|
|
52
|
-
<thead><tr>${r.map(e=>`<th>${
|
|
53
|
-
<tbody>${t.map(e=>`<tr>${r.map(t=>`<td>${
|
|
52
|
+
<thead><tr>${r.map(e=>`<th>${Y(e.label||e.name)}</th>`).join(``)}</tr></thead>
|
|
53
|
+
<tbody>${t.map(e=>`<tr>${r.map(t=>`<td>${Y(String(e[t.name]??``))}</td>`).join(``)}</tr>`).join(``)}</tbody>
|
|
54
54
|
</table>
|
|
55
55
|
</body>
|
|
56
|
-
</html>`),o.document.close(),o.onload=()=>{o.print()}}function
|
|
57
|
-
`)||n.includes(` `))?`"${n.replace(/"/g,`""`)}"`:n??``}));
|
|
58
|
-
`),n?.filename||`${e.title||`report`}.tsv`,`text/tab-separated-values`)}function x(e,t,n,r){switch(e){case`csv`:g(t,n,r);break;case`json`:_(t,n,r);break;case`html`:v(t,n,r);break;case`pdf`:y(t,n,r);break;case`excel`:b(t,n,r);break;default:console.warn(`Unsupported export format: ${e}`)}}function S(e){return e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`).replace(/'/g,`'`)}function C(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 w(e){return[`A4`,`A3`,`Letter`,`Legal`].includes(e||``)?e:`A4`}function T(e){return e===`landscape`?`landscape`:`portrait`}function E(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 D(e,t){if(e==null||e===``)return``;let n=t?.type,r=t?.format;if(n===`date`||r===`date`||O(e))return k(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 O(e){return typeof e==`string`?/^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2})?/.test(e):!1}function k(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 A(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 j=({schema:e,onRefresh:c})=>{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}x(e,l,u||[],l.exportConfigs?.[e])},g=()=>{window.print()},_=()=>{c?.()},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,i.jsx)(r.Badge,{className:t.colorMap?.[String(e)]||``,children:String(e)});if(t.aggregation)return D(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,i.jsx)((0,s.getCellRenderer)((0,s.resolveCellRendererType)(n)),{value:e,field:n})}return D(e,t)};return l?(0,i.jsxs)(`div`,{className:`space-y-4`,children:[d&&(0,i.jsxs)(`div`,{className:`flex items-center justify-between gap-2 p-4 bg-card rounded-lg border`,children:[(0,i.jsxs)(`div`,{children:[(0,i.jsx)(`h2`,{className:`text-lg font-semibold`,children:l.title}),l.description&&(0,i.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:l.description})]}),(0,i.jsxs)(`div`,{className:`flex items-center gap-2`,children:[l.refreshInterval&&(0,i.jsxs)(r.Button,{variant:`outline`,size:`sm`,onClick:_,children:[(0,i.jsx)(o.RefreshCw,{className:`h-4 w-4 mr-2`}),`Refresh`]}),p&&(0,i.jsxs)(r.Button,{variant:`outline`,size:`sm`,onClick:g,children:[(0,i.jsx)(o.Printer,{className:`h-4 w-4 mr-2`}),`Print`]}),f&&l.showExportButtons&&(0,i.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,i.jsxs)(r.Button,{variant:`outline`,size:`sm`,onClick:()=>h(`pdf`),children:[(0,i.jsx)(o.Download,{className:`h-4 w-4 mr-2`}),`PDF`]}),(0,i.jsxs)(r.Button,{variant:`outline`,size:`sm`,onClick:()=>h(`excel`),children:[(0,i.jsx)(o.Download,{className:`h-4 w-4 mr-2`}),`Excel`]}),(0,i.jsxs)(r.Button,{variant:`outline`,size:`sm`,onClick:()=>h(`csv`),children:[(0,i.jsx)(o.Download,{className:`h-4 w-4 mr-2`}),`CSV`]})]})]})]}),(0,i.jsxs)(r.Card,{children:[(0,i.jsxs)(r.CardHeader,{children:[!d&&l.title&&(0,i.jsx)(r.CardTitle,{children:l.title}),!d&&l.description&&(0,i.jsx)(r.CardDescription,{children:l.description})]}),(0,i.jsxs)(r.CardContent,{className:`space-y-6`,children:[m&&(0,i.jsxs)(`div`,{className:`space-y-6`,children:[(0,i.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:[1,2,3].map(e=>(0,i.jsx)(r.Card,{children:(0,i.jsxs)(r.CardContent,{className:`p-4 space-y-2`,children:[(0,i.jsx)(r.Skeleton,{className:`h-4 w-20`}),(0,i.jsx)(r.Skeleton,{className:`h-8 w-28`})]})},e))}),(0,i.jsxs)(`div`,{className:`space-y-2`,children:[(0,i.jsx)(r.Skeleton,{className:`h-10 w-full`}),[1,2,3,4,5].map(e=>(0,i.jsx)(r.Skeleton,{className:`h-8 w-full`},e))]})]}),!m&&l.sections?.map((e,o)=>e.visible===!1?null:(0,i.jsxs)(`div`,{className:`space-y-2`,children:[e.title&&e.type!==`header`&&(0,i.jsx)(`h3`,{className:`text-lg font-semibold border-b pb-2`,children:e.title}),e.type===`header`&&e.title&&(0,i.jsx)(`div`,{className:`text-2xl font-bold py-4`,children:e.title}),e.type===`summary`&&(0,i.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:l.fields?.filter(e=>e.showInSummary).map((e,t)=>(0,i.jsx)(r.Card,{children:(0,i.jsxs)(r.CardContent,{className:`p-4`,children:[(0,i.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:e.label||e.name}),(0,i.jsx)(`div`,{className:`text-2xl font-bold`,children:D(v(e.name,e.aggregation),e)})]})},t))}),e.type===`chart`&&e.chart&&(0,i.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 o=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,i.jsx)(a.SchemaRenderer,{schema:{...e.chart,type:n,...o,data:u||e.chart.data,className:e.chart.className||`w-full h-[350px]`}})})()}),e.type===`table`&&(0,i.jsx)(`div`,{className:`border rounded-lg overflow-x-auto`,children:(0,i.jsxs)(`table`,{className:`w-full text-sm min-w-[600px]`,children:[(0,i.jsx)(`thead`,{className:`bg-muted`,children:(0,i.jsx)(`tr`,{children:e.columns?.map((e,t)=>(0,i.jsx)(`th`,{className:`px-4 py-2 font-medium ${e.type===`number`?`text-right`:`text-left`}`,children:e.label||e.name},t))})}),(0,i.jsx)(`tbody`,{children:(()=>{let t=A(u||[],l.groupBy||[]);return t?t.map(t=>(0,i.jsxs)(n.default.Fragment,{children:[(0,i.jsx)(`tr`,{className:`bg-muted/60`,children:(0,i.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,i.jsx)(`tr`,{className:`border-t hover:bg-muted/50 even:bg-muted/20`,children:e.columns?.map((e,n)=>(0,i.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,i.jsx)(`tr`,{className:`border-t hover:bg-muted/50 even:bg-muted/20`,children:e.columns?.map((e,n)=>(0,i.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,i.jsx)(`div`,{className:`prose max-w-none`,children:(0,i.jsx)(`p`,{children:e.text})}),e.type===`page-break`&&(0,i.jsx)(`div`,{className:`border-t-2 border-dashed my-8 print:page-break-after-always`}),e.content&&(0,i.jsx)(a.SchemaRenderer,{schema:e.content})]},o)),!l.sections&&u&&u.length>0&&(0,i.jsx)(`div`,{className:`border rounded-lg overflow-x-auto`,children:(0,i.jsxs)(`table`,{className:`w-full text-sm min-w-[600px]`,children:[(0,i.jsx)(`thead`,{className:`bg-muted`,children:(0,i.jsx)(`tr`,{children:l.fields?.map((e,t)=>(0,i.jsx)(`th`,{className:`px-4 py-2 font-medium ${e.type===`number`?`text-right`:`text-left`}`,children:e.label||e.name},t))})}),(0,i.jsx)(`tbody`,{children:u.map((e,t)=>(0,i.jsx)(`tr`,{className:`border-t hover:bg-muted/50 even:bg-muted/20`,children:l.fields?.map((t,n)=>(0,i.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,i.jsx)(r.Card,{children:(0,i.jsx)(r.CardContent,{className:`p-8 text-center text-muted-foreground`,children:`No report to display`})})},M=({schedule:e,onChange:t})=>{let[a,s]=(0,n.useState)(e||{enabled:!1,frequency:`weekly`,time:`09:00`,timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,recipients:[],formats:[`pdf`]}),c=e=>{let n={...a,...e};s(n),t?.(n)};return(0,i.jsxs)(r.Card,{children:[(0,i.jsx)(r.CardHeader,{children:(0,i.jsxs)(r.CardTitle,{className:`flex items-center gap-2`,children:[(0,i.jsx)(o.Calendar,{className:`h-5 w-5`}),`Schedule Configuration`]})}),(0,i.jsxs)(r.CardContent,{className:`space-y-4`,children:[(0,i.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,i.jsx)(`input`,{type:`checkbox`,id:`schedule-enabled`,checked:a.enabled||!1,onChange:e=>c({enabled:e.target.checked}),className:`rounded`}),(0,i.jsx)(r.Label,{htmlFor:`schedule-enabled`,children:`Enable Scheduled Report`})]}),a.enabled&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(`div`,{className:`space-y-2`,children:[(0,i.jsx)(r.Label,{children:`Frequency`}),(0,i.jsx)(`select`,{className:`w-full border rounded-md p-2 bg-background`,value:a.frequency||`weekly`,onChange:e=>c({frequency:e.target.value}),children:[{value:`once`,label:`Once`},{value:`daily`,label:`Daily`},{value:`weekly`,label:`Weekly`},{value:`monthly`,label:`Monthly`},{value:`quarterly`,label:`Quarterly`},{value:`yearly`,label:`Yearly`}].map(e=>(0,i.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),a.frequency===`weekly`&&(0,i.jsxs)(`div`,{className:`space-y-2`,children:[(0,i.jsx)(r.Label,{children:`Day of Week`}),(0,i.jsx)(`select`,{className:`w-full border rounded-md p-2 bg-background`,value:a.dayOfWeek??1,onChange:e=>c({dayOfWeek:Number(e.target.value)}),children:[{value:0,label:`Sunday`},{value:1,label:`Monday`},{value:2,label:`Tuesday`},{value:3,label:`Wednesday`},{value:4,label:`Thursday`},{value:5,label:`Friday`},{value:6,label:`Saturday`}].map(e=>(0,i.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),a.frequency===`monthly`&&(0,i.jsxs)(`div`,{className:`space-y-2`,children:[(0,i.jsx)(r.Label,{children:`Day of Month`}),(0,i.jsx)(r.Input,{type:`number`,min:1,max:31,value:a.dayOfMonth??1,onChange:e=>c({dayOfMonth:Number(e.target.value)})})]}),(0,i.jsxs)(`div`,{className:`space-y-2`,children:[(0,i.jsxs)(r.Label,{className:`flex items-center gap-2`,children:[(0,i.jsx)(o.Clock,{className:`h-4 w-4`}),`Time`]}),(0,i.jsx)(r.Input,{type:`time`,value:a.time||`09:00`,onChange:e=>c({time:e.target.value})})]}),(0,i.jsxs)(`div`,{className:`space-y-2`,children:[(0,i.jsx)(r.Label,{children:`Timezone`}),(0,i.jsx)(r.Input,{value:a.timezone||``,onChange:e=>c({timezone:e.target.value}),placeholder:`e.g. America/New_York`})]}),(0,i.jsxs)(`div`,{className:`space-y-2`,children:[(0,i.jsx)(r.Label,{children:`Export Formats`}),(0,i.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:[{value:`pdf`,label:`PDF`},{value:`excel`,label:`Excel`},{value:`csv`,label:`CSV`},{value:`html`,label:`HTML`}].map(e=>(0,i.jsxs)(`label`,{className:`flex items-center gap-1.5 px-3 py-1.5 border rounded-md cursor-pointer hover:bg-muted/50`,children:[(0,i.jsx)(`input`,{type:`checkbox`,checked:a.formats?.includes(e.value)||!1,onChange:t=>{let n=a.formats||[];c({formats:t.target.checked?[...n,e.value]:n.filter(t=>t!==e.value)})},className:`rounded`}),(0,i.jsx)(`span`,{className:`text-sm`,children:e.label})]},e.value))})]}),(0,i.jsxs)(`div`,{className:`space-y-2`,children:[(0,i.jsxs)(r.Label,{className:`flex items-center gap-2`,children:[(0,i.jsx)(o.Mail,{className:`h-4 w-4`}),`Email Recipients`]}),(0,i.jsx)(r.Input,{placeholder:`email1@example.com, email2@example.com`,value:a.recipients?.join(`, `)||``,onChange:e=>c({recipients:e.target.value.split(`,`).map(e=>e.trim()).filter(Boolean)})})]}),(0,i.jsxs)(`div`,{className:`space-y-2`,children:[(0,i.jsx)(r.Label,{children:`Email Subject`}),(0,i.jsx)(r.Input,{value:a.subject||``,onChange:e=>c({subject:e.target.value}),placeholder:`Scheduled Report: {report_title}`})]})]})]})]})},N=({schema:e})=>{let{report:t,dataSources:a=[],availableFields:s=[],showPreview:c=!0,onSave:l,onCancel:u}=e,[d,f]=(0,n.useState)(t||{type:`report`,title:`New Report`,fields:[],filters:[],groupBy:[],sections:[],showExportButtons:!0,showPrintButton:!0}),[p,m]=(0,n.useState)(d.fields||[]),[h,g]=(0,n.useState)(d.filters||[]),[_,v]=(0,n.useState)(d.groupBy||[]),[y,b]=(0,n.useState)(d.sections||[]),x=()=>{if(s.length>0&&p.length<s.length){let e=s.find(e=>!p.some(t=>t.name===e.name));if(e){let t=[...p,e];m(t),f({...d,fields:t})}}},S=e=>{let t=p.filter((t,n)=>n!==e);m(t),f({...d,fields:t})},C=(e,t)=>{let n=[...p];n[e]=t,m(n),f({...d,fields:n})},w=()=>{let e={field:s[0]?.name||``,operator:`equals`,value:``},t=[...h,e];g(t),f({...d,filters:t})},T=e=>{let t=h.filter((t,n)=>n!==e);g(t),f({...d,filters:t})},E=(e,t)=>{let n=[...h];n[e]=t,g(n),f({...d,filters:n})},D=()=>{let e={field:s[0]?.name||``,sort:`asc`},t=[..._,e];v(t),f({...d,groupBy:t})},O=e=>{let t=_.filter((t,n)=>n!==e);v(t),f({...d,groupBy:t})},k=(e,t)=>{let n=[..._];n[e]=t,v(n),f({...d,groupBy:n})},A=e=>{let t={type:e,title:`New ${e} Section`},n=[...y,t];b(n),f({...d,sections:n})},N=e=>{let t=y.filter((t,n)=>n!==e);b(t),f({...d,sections:t})},P=(e,t)=>{let n=[...y];n[e]=t,b(n),f({...d,sections:n})};return(0,i.jsxs)(`div`,{className:`space-y-4`,children:[(0,i.jsxs)(r.Card,{children:[(0,i.jsxs)(r.CardHeader,{children:[(0,i.jsx)(r.CardTitle,{children:`Report Builder`}),(0,i.jsx)(r.CardDescription,{children:`Configure your report settings, fields, filters, and sections`})]}),(0,i.jsxs)(r.CardContent,{children:[(0,i.jsxs)(r.Tabs,{defaultValue:`basic`,className:`w-full`,children:[(0,i.jsxs)(r.TabsList,{className:`grid w-full grid-cols-6`,children:[(0,i.jsxs)(r.TabsTrigger,{value:`basic`,children:[(0,i.jsx)(o.Settings,{className:`h-4 w-4 mr-2`}),`Basic`]}),(0,i.jsxs)(r.TabsTrigger,{value:`fields`,children:[(0,i.jsx)(o.Layers,{className:`h-4 w-4 mr-2`}),`Fields`]}),(0,i.jsxs)(r.TabsTrigger,{value:`filters`,children:[(0,i.jsx)(o.Filter,{className:`h-4 w-4 mr-2`}),`Filters`]}),(0,i.jsxs)(r.TabsTrigger,{value:`grouping`,children:[(0,i.jsx)(o.Layers,{className:`h-4 w-4 mr-2`}),`Group By`]}),(0,i.jsxs)(r.TabsTrigger,{value:`sections`,children:[(0,i.jsx)(o.Layers,{className:`h-4 w-4 mr-2`}),`Sections`]}),(0,i.jsxs)(r.TabsTrigger,{value:`schedule`,children:[(0,i.jsx)(o.Calendar,{className:`h-4 w-4 mr-2`}),`Schedule`]})]}),(0,i.jsx)(r.TabsContent,{value:`basic`,className:`space-y-4 mt-4`,children:(0,i.jsxs)(`div`,{className:`space-y-4`,children:[(0,i.jsxs)(`div`,{className:`space-y-2`,children:[(0,i.jsx)(r.Label,{htmlFor:`report-title`,children:`Report Title`}),(0,i.jsx)(r.Input,{id:`report-title`,value:d.title||``,onChange:e=>f({...d,title:e.target.value}),placeholder:`Enter report title`})]}),(0,i.jsxs)(`div`,{className:`space-y-2`,children:[(0,i.jsx)(r.Label,{htmlFor:`report-description`,children:`Description`}),(0,i.jsx)(r.Input,{id:`report-description`,value:d.description||``,onChange:e=>f({...d,description:e.target.value}),placeholder:`Enter report description`})]}),a.length>0&&(0,i.jsxs)(`div`,{className:`space-y-2`,children:[(0,i.jsx)(r.Label,{children:`Data Source`}),(0,i.jsxs)(`select`,{className:`w-full border rounded-md p-2`,children:[(0,i.jsx)(`option`,{value:``,children:`Select a data source`}),a.map((e,t)=>(0,i.jsxs)(`option`,{value:t,children:[`Data Source `,t+1]},t))]})]}),(0,i.jsxs)(`div`,{className:`space-y-2`,children:[(0,i.jsx)(r.Label,{children:`Export Options`}),(0,i.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,i.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,i.jsx)(`input`,{type:`checkbox`,checked:d.showExportButtons||!1,onChange:e=>f({...d,showExportButtons:e.target.checked})}),(0,i.jsx)(`span`,{className:`text-sm`,children:`Show Export Buttons`})]}),(0,i.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,i.jsx)(`input`,{type:`checkbox`,checked:d.showPrintButton||!1,onChange:e=>f({...d,showPrintButton:e.target.checked})}),(0,i.jsx)(`span`,{className:`text-sm`,children:`Show Print Button`})]})]})]}),(0,i.jsxs)(`div`,{className:`space-y-2`,children:[(0,i.jsx)(r.Label,{htmlFor:`export-format`,children:`Default Export Format`}),(0,i.jsxs)(`select`,{id:`export-format`,className:`w-full border rounded-md p-2`,value:d.defaultExportFormat||`pdf`,onChange:e=>f({...d,defaultExportFormat:e.target.value}),children:[(0,i.jsx)(`option`,{value:`pdf`,children:`PDF`}),(0,i.jsx)(`option`,{value:`excel`,children:`Excel`}),(0,i.jsx)(`option`,{value:`csv`,children:`CSV`}),(0,i.jsx)(`option`,{value:`json`,children:`JSON`}),(0,i.jsx)(`option`,{value:`html`,children:`HTML`})]})]})]})}),(0,i.jsxs)(r.TabsContent,{value:`fields`,className:`space-y-4 mt-4`,children:[(0,i.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,i.jsx)(r.Label,{children:`Report Fields`}),(0,i.jsxs)(r.Button,{size:`sm`,variant:`outline`,onClick:x,disabled:p.length>=s.length,children:[(0,i.jsx)(o.Plus,{className:`h-4 w-4 mr-2`}),`Add Field`]})]}),(0,i.jsxs)(`div`,{className:`space-y-2`,children:[p.map((e,t)=>(0,i.jsx)(`div`,{className:`flex items-center gap-2 p-3 border rounded-lg`,children:(0,i.jsxs)(`div`,{className:`flex-1 grid grid-cols-4 gap-2`,children:[(0,i.jsxs)(`div`,{children:[(0,i.jsx)(r.Label,{className:`text-xs`,children:`Field Name`}),(0,i.jsx)(`div`,{className:`text-sm font-medium`,children:e.name})]}),(0,i.jsxs)(`div`,{children:[(0,i.jsx)(r.Label,{className:`text-xs`,children:`Label`}),(0,i.jsx)(r.Input,{className:`h-8 text-sm`,value:e.label||e.name,onChange:n=>C(t,{...e,label:n.target.value})})]}),(0,i.jsxs)(`div`,{children:[(0,i.jsx)(r.Label,{className:`text-xs`,children:`Aggregation`}),(0,i.jsxs)(`select`,{className:`w-full border rounded-md h-8 text-sm px-2`,value:e.aggregation||``,onChange:n=>C(t,{...e,aggregation:n.target.value}),children:[(0,i.jsx)(`option`,{value:``,children:`None`}),(0,i.jsx)(`option`,{value:`sum`,children:`Sum`}),(0,i.jsx)(`option`,{value:`count`,children:`Count`}),(0,i.jsx)(`option`,{value:`avg`,children:`Average`}),(0,i.jsx)(`option`,{value:`min`,children:`Min`}),(0,i.jsx)(`option`,{value:`max`,children:`Max`})]})]}),(0,i.jsx)(`div`,{className:`flex items-end justify-end`,children:(0,i.jsx)(r.Button,{size:`sm`,variant:`ghost`,className:`text-red-500 hover:text-red-700 hover:bg-red-50`,onClick:()=>S(t),children:(0,i.jsx)(o.Trash2,{className:`h-4 w-4`})})})]})},t)),p.length===0&&(0,i.jsx)(`div`,{className:`text-center py-8 text-muted-foreground border-2 border-dashed rounded-lg`,children:`No fields selected. Click "Add Field" to begin.`})]})]}),(0,i.jsxs)(r.TabsContent,{value:`filters`,className:`space-y-4 mt-4`,children:[(0,i.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,i.jsx)(r.Label,{children:`Report Filters`}),(0,i.jsxs)(r.Button,{size:`sm`,variant:`outline`,onClick:w,children:[(0,i.jsx)(o.Plus,{className:`h-4 w-4 mr-2`}),`Add Filter`]})]}),(0,i.jsxs)(`div`,{className:`space-y-2`,children:[h.map((e,t)=>(0,i.jsxs)(`div`,{className:`flex items-center gap-2 p-3 border rounded-lg`,children:[(0,i.jsxs)(`div`,{className:`flex-1 grid grid-cols-3 gap-2`,children:[(0,i.jsxs)(`div`,{children:[(0,i.jsx)(r.Label,{className:`text-xs`,children:`Field`}),(0,i.jsx)(`select`,{className:`w-full border rounded-md h-8 text-sm px-2`,value:e.field,onChange:n=>E(t,{...e,field:n.target.value}),children:s.map((e,t)=>(0,i.jsx)(`option`,{value:e.name,children:e.label||e.name},t))})]}),(0,i.jsxs)(`div`,{children:[(0,i.jsx)(r.Label,{className:`text-xs`,children:`Operator`}),(0,i.jsxs)(`select`,{className:`w-full border rounded-md h-8 text-sm px-2`,value:e.operator,onChange:n=>E(t,{...e,operator:n.target.value}),children:[(0,i.jsx)(`option`,{value:`equals`,children:`Equals`}),(0,i.jsx)(`option`,{value:`contains`,children:`Contains`}),(0,i.jsx)(`option`,{value:`gt`,children:`Greater Than`}),(0,i.jsx)(`option`,{value:`lt`,children:`Less Than`}),(0,i.jsx)(`option`,{value:`between`,children:`Between`})]})]}),(0,i.jsxs)(`div`,{children:[(0,i.jsx)(r.Label,{className:`text-xs`,children:`Value`}),(0,i.jsx)(r.Input,{className:`h-8 text-sm`,value:String(e.value),onChange:n=>E(t,{...e,value:n.target.value})})]})]}),(0,i.jsx)(r.Button,{size:`sm`,variant:`ghost`,className:`text-red-500 hover:text-red-700 hover:bg-red-50 self-end`,onClick:()=>T(t),children:(0,i.jsx)(o.Trash2,{className:`h-4 w-4`})})]},t)),h.length===0&&(0,i.jsx)(`div`,{className:`text-center py-8 text-muted-foreground border-2 border-dashed rounded-lg`,children:`No filters defined.`})]})]}),(0,i.jsxs)(r.TabsContent,{value:`grouping`,className:`space-y-4 mt-4`,children:[(0,i.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,i.jsx)(r.Label,{children:`Grouping Rules`}),(0,i.jsxs)(r.Button,{size:`sm`,variant:`outline`,onClick:D,children:[(0,i.jsx)(o.Plus,{className:`h-4 w-4 mr-2`}),`Add Group`]})]}),(0,i.jsxs)(`div`,{className:`space-y-2`,children:[_.map((e,t)=>(0,i.jsxs)(`div`,{className:`flex items-center gap-2 p-3 border rounded-lg`,children:[(0,i.jsxs)(`div`,{className:`flex-1 grid grid-cols-2 gap-2`,children:[(0,i.jsxs)(`div`,{children:[(0,i.jsx)(r.Label,{className:`text-xs`,children:`Field`}),(0,i.jsx)(`select`,{className:`w-full border rounded-md h-8 text-sm px-2`,value:e.field,onChange:n=>k(t,{...e,field:n.target.value}),children:s.map((e,t)=>(0,i.jsx)(`option`,{value:e.name,children:e.label||e.name},t))})]}),(0,i.jsxs)(`div`,{children:[(0,i.jsx)(r.Label,{className:`text-xs`,children:`Sort Order`}),(0,i.jsxs)(`select`,{className:`w-full border rounded-md h-8 text-sm px-2`,value:e.sort||`asc`,onChange:n=>k(t,{...e,sort:n.target.value}),children:[(0,i.jsx)(`option`,{value:`asc`,children:`Ascending`}),(0,i.jsx)(`option`,{value:`desc`,children:`Descending`})]})]})]}),(0,i.jsx)(r.Button,{size:`sm`,variant:`ghost`,className:`text-red-500 hover:text-red-700 hover:bg-red-50 self-end`,onClick:()=>O(t),children:(0,i.jsx)(o.Trash2,{className:`h-4 w-4`})})]},t)),_.length===0&&(0,i.jsx)(`div`,{className:`text-center py-8 text-muted-foreground border-2 border-dashed rounded-lg`,children:`No grouping rules applied.`})]})]}),(0,i.jsxs)(r.TabsContent,{value:`sections`,className:`space-y-4 mt-4`,children:[(0,i.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,i.jsx)(r.Label,{children:`Report Sections`}),(0,i.jsxs)(`div`,{className:`flex gap-2`,children:[(0,i.jsxs)(r.Button,{size:`sm`,variant:`outline`,onClick:()=>A(`header`),children:[(0,i.jsx)(o.Plus,{className:`h-4 w-4 mr-2`}),`Header`]}),(0,i.jsxs)(r.Button,{size:`sm`,variant:`outline`,onClick:()=>A(`chart`),children:[(0,i.jsx)(o.Plus,{className:`h-4 w-4 mr-2`}),`Chart`]}),(0,i.jsxs)(r.Button,{size:`sm`,variant:`outline`,onClick:()=>A(`table`),children:[(0,i.jsx)(o.Plus,{className:`h-4 w-4 mr-2`}),`Table`]})]})]}),(0,i.jsxs)(`div`,{className:`space-y-2`,children:[y.map((e,t)=>(0,i.jsxs)(`div`,{className:`p-3 border rounded-lg space-y-2`,children:[(0,i.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,i.jsxs)(`div`,{className:`font-medium flex items-center gap-2`,children:[(0,i.jsx)(`div`,{className:`text-xs bg-muted px-2 py-0.5 rounded uppercase`,children:e.type}),e.title]}),(0,i.jsx)(r.Button,{size:`sm`,variant:`ghost`,className:`text-red-500 hover:text-red-700 hover:bg-red-50`,onClick:()=>N(t),children:(0,i.jsx)(o.Trash2,{className:`h-4 w-4`})})]}),(0,i.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,i.jsxs)(`div`,{children:[(0,i.jsx)(r.Label,{className:`text-xs`,children:`Title`}),(0,i.jsx)(r.Input,{className:`h-8 text-sm`,value:e.title||``,onChange:n=>P(t,{...e,title:n.target.value})})]}),e.type===`text`&&(0,i.jsxs)(`div`,{className:`col-span-2`,children:[(0,i.jsx)(r.Label,{className:`text-xs`,children:`Content`}),(0,i.jsx)(r.Input,{className:`h-8 text-sm`,value:e.text||``,onChange:n=>P(t,{...e,text:n.target.value})})]}),e.type===`chart`&&(0,i.jsxs)(`div`,{className:`col-span-2 grid grid-cols-2 gap-2 mt-2 p-2 bg-muted/20 rounded`,children:[(0,i.jsx)(`div`,{className:`col-span-2`,children:(0,i.jsx)(r.Label,{className:`text-xs font-semibold`,children:`Chart Configuration`})}),(0,i.jsxs)(`div`,{children:[(0,i.jsx)(r.Label,{className:`text-xs`,children:`Chart Type`}),(0,i.jsxs)(`select`,{className:`flex h-8 w-full rounded-md border border-input bg-background px-3 py-1 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,value:e.chart?.chartType||`bar`,onChange:n=>P(t,{...e,chart:{...e.chart,type:`chart`,chartType:n.target.value}}),children:[(0,i.jsx)(`option`,{value:`bar`,children:`Bar`}),(0,i.jsx)(`option`,{value:`line`,children:`Line`}),(0,i.jsx)(`option`,{value:`area`,children:`Area`}),(0,i.jsx)(`option`,{value:`pie`,children:`Pie`})]})]}),(0,i.jsxs)(`div`,{children:[(0,i.jsx)(r.Label,{className:`text-xs`,children:`X-Axis Field`}),(0,i.jsxs)(`select`,{className:`flex h-8 w-full rounded-md border border-input bg-background px-3 py-1 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,value:e.chart?.xAxisField||``,onChange:n=>P(t,{...e,chart:{...e.chart,type:`chart`,xAxisField:n.target.value}}),children:[(0,i.jsx)(`option`,{value:``,children:`Select Field...`}),s.map(e=>(0,i.jsx)(`option`,{value:e.name,children:e.label||e.name},e.name)),s.length===0&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(`option`,{value:`name`,children:`Name`}),(0,i.jsx)(`option`,{value:`month`,children:`Month`})]})]})]}),(0,i.jsxs)(`div`,{className:`col-span-2`,children:[(0,i.jsx)(r.Label,{className:`text-xs`,children:`Y-Axis Fields (comma separated)`}),(0,i.jsx)(r.Input,{className:`h-8 text-sm`,placeholder:`e.g. value, count`,value:e.chart?.yAxisFields?.join(`, `)||``,onChange:n=>P(t,{...e,chart:{...e.chart,type:`chart`,yAxisFields:n.target.value.split(`,`).map(e=>e.trim()).filter(Boolean)}})})]})]})]})]},t)),y.length===0&&(0,i.jsx)(`div`,{className:`text-center py-8 text-muted-foreground border-2 border-dashed rounded-lg`,children:`No customized sections. The default report layout will be used.`})]})]}),(0,i.jsx)(r.TabsContent,{value:`schedule`,className:`space-y-4 mt-4`,children:(0,i.jsx)(M,{schedule:d.schedule,onChange:e=>f({...d,schedule:e})})})]}),(0,i.jsxs)(`div`,{className:`flex items-center justify-end gap-2 mt-6 pt-4 border-t`,children:[(0,i.jsx)(r.Button,{variant:`outline`,onClick:()=>{u&&console.log(`Report cancelled:`,u)},children:`Cancel`}),(0,i.jsxs)(r.Button,{onClick:()=>{console.log(`Saving report:`,d),l&&alert(`Report saved! (Handler: `+l+`)`)},children:[(0,i.jsx)(o.Save,{className:`h-4 w-4 mr-2`}),`Save Report`]})]})]})]}),c&&(0,i.jsxs)(r.Card,{className:`mt-8 border-2 border-blue-100`,children:[(0,i.jsx)(r.CardHeader,{className:`bg-blue-50/50`,children:(0,i.jsx)(r.CardTitle,{className:`text-blue-900 text-sm uppercase tracking-wide`,children:`Live Preview`})}),(0,i.jsx)(r.CardContent,{className:`pt-6`,children:(0,i.jsx)(j,{schema:{type:`report-viewer`,report:{...d,fields:p,filters:h,groupBy:_,sections:y},data:[{id:1,name:`Sample Item A`,value:100,status:`New`},{id:2,name:`Sample Item B`,value:250,status:`Active`},{id:3,name:`Sample Item C`,value:75,status:`Closed`}]}})})]})]})},P=[{value:``,label:`None`},{value:`sum`,label:`Sum`},{value:`count`,label:`Count`},{value:`avg`,label:`Average`},{value:`min`,label:`Min`},{value:`max`,label:`Max`}];function F({availableFields:e,value:t,onChange:n}){let a=Array.isArray(t)?t.map(e=>typeof e==`string`?{field:e,label:e,type:`string`}:{field:e.field||e.name||e.value,label:e.label||e.name||e.field||``,type:e.type||`string`,aggregate:e.aggregate??e.aggregation}):[],o=a.map(e=>e.field),s=t=>{let r=o.includes(t),i;if(r)i=a.filter(e=>e.field!==t);else{let n=e.find(e=>e.value===t);i=[...a,{field:t,label:n?.label||t,type:n?.type||`string`}]}n(i)},c=(e,t)=>{n(a.map(n=>n.field===e?{...n,aggregate:t||void 0}:n))};return e.length===0?(0,i.jsx)(`div`,{className:`text-xs text-muted-foreground py-2`,"data-testid":`field-picker-empty`,children:`No fields available`}):(0,i.jsx)(`div`,{className:`space-y-1 py-1`,"data-testid":`field-picker`,children:e.map(e=>{let t=o.includes(e.value),n=a.find(t=>t.field===e.value);return(0,i.jsxs)(`div`,{className:`flex items-center gap-2 px-1 py-0.5 rounded hover:bg-muted/50 text-xs`,children:[(0,i.jsxs)(`label`,{className:`flex items-center gap-2 flex-1 cursor-pointer`,children:[(0,i.jsx)(r.Checkbox,{checked:t,onCheckedChange:()=>s(e.value),"data-testid":`field-picker-${e.value}`}),(0,i.jsx)(`span`,{className:`flex-1`,children:e.label}),e.type&&(0,i.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:e.type})]}),t&&(0,i.jsx)(`select`,{className:`h-5 text-[10px] border rounded px-1 bg-background`,value:n?.aggregate||``,onChange:t=>c(e.value,t.target.value),"data-testid":`field-agg-${e.value}`,children:P.map(e=>(0,i.jsx)(`option`,{value:e.value,children:e.label},e.value))})]},e.value)})})}var I=[{value:``,label:`None`},{value:`bar`,label:`Bar Chart`},{value:`line`,label:`Line Chart`},{value:`pie`,label:`Pie Chart`},{value:`area`,label:`Area Chart`},{value:`donut`,label:`Donut Chart`},{value:`scatter`,label:`Scatter Plot`}];function L({availableFields:e,value:t,onChange:n}){let r=t||{},a=r.type??r.chartType??``,o=r.xAxis??r.xAxisField??``,s=r.yAxis??r.yAxisFields?.[0]??``,c=e=>{let t={...r,...e};`type`in e&&delete t.chartType,`xAxis`in e&&delete t.xAxisField,`yAxis`in e&&delete t.yAxisFields,n(t)};return(0,i.jsxs)(`div`,{className:`space-y-2 py-1`,"data-testid":`chart-config`,children:[(0,i.jsxs)(`div`,{children:[(0,i.jsx)(`label`,{className:`text-[10px] text-muted-foreground`,children:`Chart type`}),(0,i.jsx)(`select`,{className:`w-full h-7 text-xs border rounded px-2 bg-background`,value:a,onChange:e=>c({type:e.target.value||void 0}),"data-testid":`chart-type-select`,children:I.map(e=>(0,i.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),a&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(`div`,{children:[(0,i.jsx)(`label`,{className:`text-[10px] text-muted-foreground`,children:`X-axis field`}),(0,i.jsxs)(`select`,{className:`w-full h-7 text-xs border rounded px-2 bg-background`,value:o,onChange:e=>c({xAxis:e.target.value||void 0}),"data-testid":`chart-x-field`,children:[(0,i.jsx)(`option`,{value:``,children:`Select field…`}),e.map(e=>(0,i.jsx)(`option`,{value:e.value,children:e.label},e.value))]})]}),(0,i.jsxs)(`div`,{children:[(0,i.jsx)(`label`,{className:`text-[10px] text-muted-foreground`,children:`Y-axis field`}),(0,i.jsxs)(`select`,{className:`w-full h-7 text-xs border rounded px-2 bg-background`,value:s,onChange:e=>c({yAxis:e.target.value||void 0}),"data-testid":`chart-y-field`,children:[(0,i.jsx)(`option`,{value:``,children:`Select field…`}),e.filter(e=>e.type===`number`).map(e=>(0,i.jsx)(`option`,{value:e.value,children:e.label},e.value))]})]})]})]})}var R=[{value:`equals`,label:`=`},{value:`not_equals`,label:`≠`},{value:`greater_than`,label:`>`},{value:`less_than`,label:`<`},{value:`contains`,label:`Contains`}];function z({availableFields:e,value:t,onChange:n}){let a=Array.isArray(t)?t:[],s=()=>{n([...a,{field:e[0]?.value||``,operator:`equals`,value:``,backgroundColor:`#fef9c3`,textColor:``}])},c=e=>{n(a.filter((t,n)=>n!==e))},l=(e,t)=>{n(a.map((n,r)=>r===e?{...n,...t}:n))};return(0,i.jsxs)(`div`,{className:`space-y-2 py-1`,"data-testid":`conditional-format-rules`,children:[a.map((t,n)=>(0,i.jsxs)(`div`,{className:`flex items-center gap-1 text-[10px] p-1 border rounded bg-muted/20`,children:[(0,i.jsx)(`select`,{className:`h-5 text-[10px] border rounded px-1 bg-background flex-1`,value:t.field,onChange:e=>l(n,{field:e.target.value}),"data-testid":`cf-rule-field-${n}`,children:e.map(e=>(0,i.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,i.jsx)(`select`,{className:`h-5 text-[10px] border rounded px-1 bg-background w-12`,value:t.operator,onChange:e=>l(n,{operator:e.target.value}),children:R.map(e=>(0,i.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,i.jsx)(`input`,{className:`h-5 text-[10px] border rounded px-1 bg-background w-16`,value:t.value,placeholder:`value`,onChange:e=>l(n,{value:e.target.value}),"data-testid":`cf-rule-value-${n}`}),(0,i.jsx)(`input`,{type:`color`,className:`h-5 w-5 rounded border cursor-pointer`,value:t.backgroundColor||`#fef9c3`,onChange:e=>l(n,{backgroundColor:e.target.value}),title:`Background color`}),(0,i.jsx)(r.Button,{type:`button`,size:`sm`,variant:`ghost`,className:`h-5 w-5 p-0`,onClick:()=>c(n),"data-testid":`cf-rule-remove-${n}`,children:(0,i.jsx)(o.Trash2,{className:`h-3 w-3`})})]},n)),(0,i.jsxs)(r.Button,{type:`button`,size:`sm`,variant:`outline`,className:`h-6 text-[10px] w-full`,onClick:s,"data-testid":`cf-add-rule`,children:[(0,i.jsx)(o.Plus,{className:`h-3 w-3 mr-1`}),`Add Rule`]})]})}var B=[{value:`header`,label:`Header`},{value:`summary`,label:`Summary`},{value:`table`,label:`Table`},{value:`chart`,label:`Chart`},{value:`text`,label:`Text`}];function V({value:e,onChange:t}){let n=Array.isArray(e)?e:[],a=e=>{t([...n,{type:e,title:`New ${e}`,visible:!0}])},s=e=>{t(n.filter((t,n)=>n!==e))},c=(e,r)=>{t(n.map((t,n)=>n===e?{...t,...r}:t))},l=(e,r)=>{let i=e+r;if(i<0||i>=n.length)return;let a=[...n];[a[e],a[i]]=[a[i],a[e]],t(a)};return(0,i.jsxs)(`div`,{className:`space-y-2 py-1`,"data-testid":`section-manager`,children:[n.map((e,t)=>(0,i.jsxs)(`div`,{className:`flex items-center gap-1 text-[10px] p-1.5 border rounded bg-muted/20`,children:[(0,i.jsxs)(`div`,{className:`flex flex-col gap-0.5 mr-1`,children:[(0,i.jsx)(`button`,{type:`button`,className:`text-muted-foreground hover:text-foreground disabled:opacity-30`,disabled:t===0,onClick:()=>l(t,-1),"data-testid":`section-up-${t}`,children:`▲`}),(0,i.jsx)(`button`,{type:`button`,className:`text-muted-foreground hover:text-foreground disabled:opacity-30`,disabled:t===n.length-1,onClick:()=>l(t,1),"data-testid":`section-down-${t}`,children:`▼`})]}),(0,i.jsx)(`span`,{className:`text-[9px] bg-muted px-1.5 py-0.5 rounded uppercase font-medium shrink-0`,children:e.type}),(0,i.jsx)(`input`,{className:`h-5 text-[10px] border rounded px-1 bg-background flex-1 min-w-0`,value:e.title||``,placeholder:`Section title`,onChange:e=>c(t,{title:e.target.value}),"data-testid":`section-title-${t}`}),(0,i.jsx)(r.Button,{type:`button`,size:`sm`,variant:`ghost`,className:`h-5 w-5 p-0 shrink-0`,onClick:()=>s(t),"data-testid":`section-remove-${t}`,children:(0,i.jsx)(o.Trash2,{className:`h-3 w-3`})})]},t)),(0,i.jsx)(`div`,{className:`flex gap-1 flex-wrap`,children:B.map(e=>(0,i.jsxs)(r.Button,{type:`button`,size:`sm`,variant:`outline`,className:`h-6 text-[10px]`,onClick:()=>a(e.value),"data-testid":`section-add-${e.value}`,children:[(0,i.jsx)(o.Plus,{className:`h-3 w-3 mr-0.5`}),e.label]},e.value))})]})}function H(e=[]){return{breadcrumb:[`Report`,`Configuration`],sections:[{key:`basic`,title:`Basic`,fields:[{key:`label`,label:`Title`,type:`input`,placeholder:`Report title`},{key:`description`,label:`Description`,type:`input`,placeholder:`Report description`},{key:`type`,label:`Report type`,type:`select`,defaultValue:`tabular`,options:[{value:`tabular`,label:`Tabular`},{value:`summary`,label:`Summary`},{value:`matrix`,label:`Matrix`}],helpText:`Tabular: flat table. Summary: grouped with subtotals. Matrix: pivot table (planned).`}]},{key:`data`,title:`Data`,collapsible:!0,fields:[{key:`objectName`,label:`Data source`,type:`input`,placeholder:`e.g. opportunity`,helpText:`Object name to query data from`},{key:`limit`,label:`Row limit`,type:`input`,defaultValue:`100`,placeholder:`e.g. 100`}]},{key:`columns`,title:`Columns`,collapsible:!0,hint:`Select fields to display as report columns. Set aggregation per column for summary reports.`,fields:[{key:`columns`,label:`Report columns`,type:`custom`,render:(t,n)=>(0,i.jsx)(F,{availableFields:e,value:t,onChange:n})}]},{key:`filters`,title:`Filters`,collapsible:!0,hint:`Define filter conditions for the report data`,fields:[{key:`filter`,label:`Conditions`,type:`filter`,fields:e}]},{key:`groupBy`,title:`Group By`,collapsible:!0,hint:`Group report data and compute aggregations`,fields:[{key:`groupingsDown`,label:`Grouping`,type:`custom`,render:(t,n)=>(0,i.jsx)(r.SortBuilder,{fields:e,value:Array.isArray(t)?t.map(e=>({...e,order:e.order??e.sortOrder??`asc`})):[],onChange:e=>n(e.map(e=>{let{id:t,order:n,...r}=e;return{...r,sortOrder:n??`asc`}}))})}]},{key:`chart`,title:`Chart`,collapsible:!0,hint:`Add a chart visualization to the report`,fields:[{key:`chart`,label:`Chart`,type:`custom`,render:(t,n)=>(0,i.jsx)(L,{availableFields:e,value:t,onChange:n})}]},{key:`conditionalFormatting`,title:`Conditional Format`,collapsible:!0,defaultCollapsed:!0,hint:`Highlight cells based on field value conditions`,fields:[{key:`conditionalFormatting`,label:`Rules`,type:`custom`,render:(t,n)=>(0,i.jsx)(z,{availableFields:e,value:t,onChange:n})}]},{key:`sections`,title:`Sections`,collapsible:!0,defaultCollapsed:!0,hint:`Manage report layout blocks (header, table, chart, summary)`,fields:[{key:`sections`,label:`Report sections`,type:`custom`,render:(e,t)=>(0,i.jsx)(V,{value:e,onChange:t})}]},{key:`export`,title:`Export`,collapsible:!0,defaultCollapsed:!0,fields:[{key:`showExportButtons`,label:`Show export buttons`,type:`switch`,defaultValue:!0},{key:`showPrintButton`,label:`Show print button`,type:`switch`,defaultValue:!0},{key:`defaultExportFormat`,label:`Default export format`,type:`select`,defaultValue:`pdf`,options:[{value:`pdf`,label:`PDF`},{value:`excel`,label:`Excel`},{value:`csv`,label:`CSV`},{value:`json`,label:`JSON`},{value:`html`,label:`HTML`}]}]},{key:`schedule`,title:`Schedule`,collapsible:!0,defaultCollapsed:!0,fields:[{key:`schedule`,label:`Schedule`,type:`custom`,render:(e,t)=>(0,i.jsx)(M,{schedule:e,onChange:t})}]},{key:`appearance`,title:`Appearance`,collapsible:!0,defaultCollapsed:!0,fields:[{key:`showToolbar`,label:`Show toolbar`,type:`switch`,defaultValue:!0},{key:`refreshInterval`,label:`Refresh interval`,type:`select`,defaultValue:`0`,options:[{value:`0`,label:`Manual`},{value:`30`,label:`30s`},{value:`60`,label:`1 min`},{value:`300`,label:`5 min`}]}]}]}}function U({open:e,onClose:t,config:a,onSave:o,onFieldChange:s,availableFields:c}){let{draft:l,isDirty:u,updateField:d,discard:f,undo:p,redo:m,canUndo:h,canRedo:g}=(0,r.useConfigDraft)(a,{onUpdate:s});return(0,i.jsx)(r.ConfigPanelRenderer,{open:e,onClose:t,schema:n.useMemo(()=>H(c),[c]),draft:l,isDirty:u,onFieldChange:d,onSave:()=>o(l),onDiscard:f,onUndo:p,onRedo:m,canUndo:h,canRedo:g})}async function W(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 x(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 G(e,t,n={}){let{columns:r,filename:i,includeAggregationRow:a=!1}=n,o=r||(e.fields||[]).map(q),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 J(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=X(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)}Q(``+[s.join(` `),...c.map(e=>e.join(` `))].join(`
|
|
59
|
-
`),i||`${e.title||`report`}.tsv`,`text/tab-separated-values`)}function
|
|
56
|
+
</html>`),o.document.close(),o.onload=()=>{o.print()}}function ye(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=be(n),typeof n==`string`&&(n.includes(`,`)||n.includes(`"`)||n.includes(`
|
|
57
|
+
`)||n.includes(` `))?`"${n.replace(/"/g,`""`)}"`:n??``}));X(``+[...n?.includeHeaders===!1?[]:[i.join(` `)],...a.map(e=>e.join(` `))].join(`
|
|
58
|
+
`),n?.filename||`${e.title||`report`}.tsv`,`text/tab-separated-values`)}function J(e,t,n,r){switch(e){case`csv`:ge(t,n,r);break;case`json`:_e(t,n,r);break;case`html`:q(t,n,r);break;case`pdf`:ve(t,n,r);break;case`excel`:ye(t,n,r);break;default:console.warn(`Unsupported export format: ${e}`)}}function Y(e){return e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`).replace(/'/g,`'`)}function be(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 xe(e){return[`A4`,`A3`,`Letter`,`Legal`].includes(e||``)?e:`A4`}function Se(e){return e===`landscape`?`landscape`:`portrait`}function X(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 Z(e,t){if(e==null||e===``)return``;let n=t?.type,r=t?.format;if(n===`date`||r===`date`||Ce(e))return we(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 Ce(e){return typeof e==`string`?/^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2})?/.test(e):!1}function we(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 Te(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 Q=({schema:e,onRefresh:r})=>{let{report:o,data:s,showToolbar:c=!0,allowExport:f=!0,allowPrint:p=!0,loading:m=!1}=e,h=e=>{if(!o){console.warn(`ReportViewer: Cannot export, no report defined`);return}J(e,o,s||[],o.exportConfigs?.[e])},g=()=>{window.print()},_=()=>{r?.()},v=(e,t)=>{if(!s)return 0;let n=s.map(t=>Number(t[e])||0);switch(t){case`count`:return s.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=o?.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,a.jsx)(i.Badge,{className:t.colorMap?.[String(e)]||``,children:String(e)});if(t.aggregation)return Z(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,a.jsx)((0,d.getCellRenderer)((0,d.resolveCellRendererType)(n)),{value:e,field:n})}return Z(e,t)};return o?(0,a.jsxs)(`div`,{className:`space-y-4`,children:[c&&(0,a.jsxs)(`div`,{className:`flex items-center justify-between gap-2 p-4 bg-card rounded-lg border`,children:[(0,a.jsxs)(`div`,{children:[(0,a.jsx)(`h2`,{className:`text-lg font-semibold`,children:o.title}),o.description&&(0,a.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:o.description})]}),(0,a.jsxs)(`div`,{className:`flex items-center gap-2`,children:[o.refreshInterval&&(0,a.jsxs)(i.Button,{variant:`outline`,size:`sm`,onClick:_,children:[(0,a.jsx)(u.RefreshCw,{className:`h-4 w-4 mr-2`}),`Refresh`]}),p&&(0,a.jsxs)(i.Button,{variant:`outline`,size:`sm`,onClick:g,children:[(0,a.jsx)(u.Printer,{className:`h-4 w-4 mr-2`}),`Print`]}),f&&o.showExportButtons&&(0,a.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,a.jsxs)(i.Button,{variant:`outline`,size:`sm`,onClick:()=>h(`pdf`),children:[(0,a.jsx)(u.Download,{className:`h-4 w-4 mr-2`}),`PDF`]}),(0,a.jsxs)(i.Button,{variant:`outline`,size:`sm`,onClick:()=>h(`excel`),children:[(0,a.jsx)(u.Download,{className:`h-4 w-4 mr-2`}),`Excel`]}),(0,a.jsxs)(i.Button,{variant:`outline`,size:`sm`,onClick:()=>h(`csv`),children:[(0,a.jsx)(u.Download,{className:`h-4 w-4 mr-2`}),`CSV`]})]})]})]}),(0,a.jsxs)(i.Card,{children:[(0,a.jsxs)(i.CardHeader,{children:[!c&&o.title&&(0,a.jsx)(i.CardTitle,{children:o.title}),!c&&o.description&&(0,a.jsx)(i.CardDescription,{children:o.description})]}),(0,a.jsxs)(i.CardContent,{className:`space-y-6`,children:[m&&(0,a.jsxs)(`div`,{className:`space-y-6`,children:[(0,a.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:[1,2,3].map(e=>(0,a.jsx)(i.Card,{children:(0,a.jsxs)(i.CardContent,{className:`p-4 space-y-2`,children:[(0,a.jsx)(i.Skeleton,{className:`h-4 w-20`}),(0,a.jsx)(i.Skeleton,{className:`h-8 w-28`})]})},e))}),(0,a.jsxs)(`div`,{className:`space-y-2`,children:[(0,a.jsx)(i.Skeleton,{className:`h-10 w-full`}),[1,2,3,4,5].map(e=>(0,a.jsx)(i.Skeleton,{className:`h-8 w-full`},e))]})]}),!m&&o.sections?.map((e,r)=>e.visible===!1?null:(0,a.jsxs)(`div`,{className:`space-y-2`,children:[e.title&&e.type!==`header`&&(0,a.jsx)(`h3`,{className:`text-lg font-semibold border-b pb-2`,children:e.title}),e.type===`header`&&e.title&&(0,a.jsx)(`div`,{className:`text-2xl font-bold py-4`,children:e.title}),e.type===`summary`&&(0,a.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:o.fields?.filter(e=>e.showInSummary).map((e,t)=>(0,a.jsx)(i.Card,{children:(0,a.jsxs)(i.CardContent,{className:`p-4`,children:[(0,a.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:e.label||e.name}),(0,a.jsx)(`div`,{className:`text-2xl font-bold`,children:Z(v(e.name,e.aggregation),e)})]})},t))}),e.type===`chart`&&e.chart&&(0,a.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 i=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,a.jsx)(l.SchemaRenderer,{schema:{...e.chart,type:n,...i,data:s||e.chart.data,className:e.chart.className||`w-full h-[350px]`}})})()}),e.type===`table`&&(0,a.jsx)(`div`,{className:`border rounded-lg overflow-x-auto`,children:(0,a.jsxs)(`table`,{className:`w-full text-sm min-w-[600px]`,children:[(0,a.jsx)(`thead`,{className:`bg-muted`,children:(0,a.jsx)(`tr`,{children:e.columns?.map((e,t)=>(0,a.jsx)(`th`,{className:`px-4 py-2 font-medium ${e.type===`number`?`text-right`:`text-left`}`,children:e.label||e.name},t))})}),(0,a.jsx)(`tbody`,{children:(()=>{let t=Te(s||[],o.groupBy||[]);return t?t.map(t=>(0,a.jsxs)(n.default.Fragment,{children:[(0,a.jsx)(`tr`,{className:`bg-muted/60`,children:(0,a.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,a.jsx)(`tr`,{className:`border-t hover:bg-muted/50 even:bg-muted/20`,children:e.columns?.map((e,n)=>(0,a.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)):s?.map((t,n)=>(0,a.jsx)(`tr`,{className:`border-t hover:bg-muted/50 even:bg-muted/20`,children:e.columns?.map((e,n)=>(0,a.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,a.jsx)(`div`,{className:`prose max-w-none`,children:(0,a.jsx)(`p`,{children:e.text})}),e.type===`page-break`&&(0,a.jsx)(`div`,{className:`border-t-2 border-dashed my-8 print:page-break-after-always`}),e.content&&(0,a.jsx)(l.SchemaRenderer,{schema:e.content})]},r)),!o.sections&&s&&s.length>0&&(0,a.jsx)(`div`,{className:`border rounded-lg overflow-x-auto`,children:(0,a.jsxs)(`table`,{className:`w-full text-sm min-w-[600px]`,children:[(0,a.jsx)(`thead`,{className:`bg-muted`,children:(0,a.jsx)(`tr`,{children:o.fields?.map((e,t)=>(0,a.jsx)(`th`,{className:`px-4 py-2 font-medium ${e.type===`number`?`text-right`:`text-left`}`,children:e.label||e.name},t))})}),(0,a.jsx)(`tbody`,{children:s.map((e,t)=>(0,a.jsx)(`tr`,{className:`border-t hover:bg-muted/50 even:bg-muted/20`,children:o.fields?.map((t,n)=>(0,a.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,a.jsx)(i.Card,{children:(0,a.jsx)(i.CardContent,{className:`p-8 text-center text-muted-foreground`,children:`No report to display`})})},$=({schedule:e,onChange:t})=>{let[r,o]=(0,n.useState)(e||{enabled:!1,frequency:`weekly`,time:`09:00`,timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,recipients:[],formats:[`pdf`]}),s=e=>{let n={...r,...e};o(n),t?.(n)};return(0,a.jsxs)(i.Card,{children:[(0,a.jsx)(i.CardHeader,{children:(0,a.jsxs)(i.CardTitle,{className:`flex items-center gap-2`,children:[(0,a.jsx)(u.Calendar,{className:`h-5 w-5`}),`Schedule Configuration`]})}),(0,a.jsxs)(i.CardContent,{className:`space-y-4`,children:[(0,a.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,a.jsx)(`input`,{type:`checkbox`,id:`schedule-enabled`,checked:r.enabled||!1,onChange:e=>s({enabled:e.target.checked}),className:`rounded`}),(0,a.jsx)(i.Label,{htmlFor:`schedule-enabled`,children:`Enable Scheduled Report`})]}),r.enabled&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(`div`,{className:`space-y-2`,children:[(0,a.jsx)(i.Label,{children:`Frequency`}),(0,a.jsx)(`select`,{className:`w-full border rounded-md p-2 bg-background`,value:r.frequency||`weekly`,onChange:e=>s({frequency:e.target.value}),children:[{value:`once`,label:`Once`},{value:`daily`,label:`Daily`},{value:`weekly`,label:`Weekly`},{value:`monthly`,label:`Monthly`},{value:`quarterly`,label:`Quarterly`},{value:`yearly`,label:`Yearly`}].map(e=>(0,a.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),r.frequency===`weekly`&&(0,a.jsxs)(`div`,{className:`space-y-2`,children:[(0,a.jsx)(i.Label,{children:`Day of Week`}),(0,a.jsx)(`select`,{className:`w-full border rounded-md p-2 bg-background`,value:r.dayOfWeek??1,onChange:e=>s({dayOfWeek:Number(e.target.value)}),children:[{value:0,label:`Sunday`},{value:1,label:`Monday`},{value:2,label:`Tuesday`},{value:3,label:`Wednesday`},{value:4,label:`Thursday`},{value:5,label:`Friday`},{value:6,label:`Saturday`}].map(e=>(0,a.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),r.frequency===`monthly`&&(0,a.jsxs)(`div`,{className:`space-y-2`,children:[(0,a.jsx)(i.Label,{children:`Day of Month`}),(0,a.jsx)(i.Input,{type:`number`,min:1,max:31,value:r.dayOfMonth??1,onChange:e=>s({dayOfMonth:Number(e.target.value)})})]}),(0,a.jsxs)(`div`,{className:`space-y-2`,children:[(0,a.jsxs)(i.Label,{className:`flex items-center gap-2`,children:[(0,a.jsx)(u.Clock,{className:`h-4 w-4`}),`Time`]}),(0,a.jsx)(i.Input,{type:`time`,value:r.time||`09:00`,onChange:e=>s({time:e.target.value})})]}),(0,a.jsxs)(`div`,{className:`space-y-2`,children:[(0,a.jsx)(i.Label,{children:`Timezone`}),(0,a.jsx)(i.Input,{value:r.timezone||``,onChange:e=>s({timezone:e.target.value}),placeholder:`e.g. America/New_York`})]}),(0,a.jsxs)(`div`,{className:`space-y-2`,children:[(0,a.jsx)(i.Label,{children:`Export Formats`}),(0,a.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:[{value:`pdf`,label:`PDF`},{value:`excel`,label:`Excel`},{value:`csv`,label:`CSV`},{value:`html`,label:`HTML`}].map(e=>(0,a.jsxs)(`label`,{className:`flex items-center gap-1.5 px-3 py-1.5 border rounded-md cursor-pointer hover:bg-muted/50`,children:[(0,a.jsx)(`input`,{type:`checkbox`,checked:r.formats?.includes(e.value)||!1,onChange:t=>{let n=r.formats||[];s({formats:t.target.checked?[...n,e.value]:n.filter(t=>t!==e.value)})},className:`rounded`}),(0,a.jsx)(`span`,{className:`text-sm`,children:e.label})]},e.value))})]}),(0,a.jsxs)(`div`,{className:`space-y-2`,children:[(0,a.jsxs)(i.Label,{className:`flex items-center gap-2`,children:[(0,a.jsx)(u.Mail,{className:`h-4 w-4`}),`Email Recipients`]}),(0,a.jsx)(i.Input,{placeholder:`email1@example.com, email2@example.com`,value:r.recipients?.join(`, `)||``,onChange:e=>s({recipients:e.target.value.split(`,`).map(e=>e.trim()).filter(Boolean)})})]}),(0,a.jsxs)(`div`,{className:`space-y-2`,children:[(0,a.jsx)(i.Label,{children:`Email Subject`}),(0,a.jsx)(i.Input,{value:r.subject||``,onChange:e=>s({subject:e.target.value}),placeholder:`Scheduled Report: {report_title}`})]})]})]})]})},Ee=({schema:e})=>{let{report:t,dataSources:r=[],availableFields:o=[],showPreview:s=!0,onSave:c,onCancel:l}=e,[d,f]=(0,n.useState)(t||{type:`report`,title:`New Report`,fields:[],filters:[],groupBy:[],sections:[],showExportButtons:!0,showPrintButton:!0}),[p,m]=(0,n.useState)(d.fields||[]),[h,g]=(0,n.useState)(d.filters||[]),[_,v]=(0,n.useState)(d.groupBy||[]),[y,b]=(0,n.useState)(d.sections||[]),x=()=>{if(o.length>0&&p.length<o.length){let e=o.find(e=>!p.some(t=>t.name===e.name));if(e){let t=[...p,e];m(t),f({...d,fields:t})}}},S=e=>{let t=p.filter((t,n)=>n!==e);m(t),f({...d,fields:t})},C=(e,t)=>{let n=[...p];n[e]=t,m(n),f({...d,fields:n})},w=()=>{let e={field:o[0]?.name||``,operator:`equals`,value:``},t=[...h,e];g(t),f({...d,filters:t})},T=e=>{let t=h.filter((t,n)=>n!==e);g(t),f({...d,filters:t})},E=(e,t)=>{let n=[...h];n[e]=t,g(n),f({...d,filters:n})},D=()=>{let e={field:o[0]?.name||``,sort:`asc`},t=[..._,e];v(t),f({...d,groupBy:t})},O=e=>{let t=_.filter((t,n)=>n!==e);v(t),f({...d,groupBy:t})},k=(e,t)=>{let n=[..._];n[e]=t,v(n),f({...d,groupBy:n})},A=e=>{let t={type:e,title:`New ${e} Section`},n=[...y,t];b(n),f({...d,sections:n})},j=e=>{let t=y.filter((t,n)=>n!==e);b(t),f({...d,sections:t})},M=(e,t)=>{let n=[...y];n[e]=t,b(n),f({...d,sections:n})};return(0,a.jsxs)(`div`,{className:`space-y-4`,children:[(0,a.jsxs)(i.Card,{children:[(0,a.jsxs)(i.CardHeader,{children:[(0,a.jsx)(i.CardTitle,{children:`Report Builder`}),(0,a.jsx)(i.CardDescription,{children:`Configure your report settings, fields, filters, and sections`})]}),(0,a.jsxs)(i.CardContent,{children:[(0,a.jsxs)(i.Tabs,{defaultValue:`basic`,className:`w-full`,children:[(0,a.jsxs)(i.TabsList,{className:`grid w-full grid-cols-6`,children:[(0,a.jsxs)(i.TabsTrigger,{value:`basic`,children:[(0,a.jsx)(u.Settings,{className:`h-4 w-4 mr-2`}),`Basic`]}),(0,a.jsxs)(i.TabsTrigger,{value:`fields`,children:[(0,a.jsx)(u.Layers,{className:`h-4 w-4 mr-2`}),`Fields`]}),(0,a.jsxs)(i.TabsTrigger,{value:`filters`,children:[(0,a.jsx)(u.Filter,{className:`h-4 w-4 mr-2`}),`Filters`]}),(0,a.jsxs)(i.TabsTrigger,{value:`grouping`,children:[(0,a.jsx)(u.Layers,{className:`h-4 w-4 mr-2`}),`Group By`]}),(0,a.jsxs)(i.TabsTrigger,{value:`sections`,children:[(0,a.jsx)(u.Layers,{className:`h-4 w-4 mr-2`}),`Sections`]}),(0,a.jsxs)(i.TabsTrigger,{value:`schedule`,children:[(0,a.jsx)(u.Calendar,{className:`h-4 w-4 mr-2`}),`Schedule`]})]}),(0,a.jsx)(i.TabsContent,{value:`basic`,className:`space-y-4 mt-4`,children:(0,a.jsxs)(`div`,{className:`space-y-4`,children:[(0,a.jsxs)(`div`,{className:`space-y-2`,children:[(0,a.jsx)(i.Label,{htmlFor:`report-title`,children:`Report Title`}),(0,a.jsx)(i.Input,{id:`report-title`,value:d.title||``,onChange:e=>f({...d,title:e.target.value}),placeholder:`Enter report title`})]}),(0,a.jsxs)(`div`,{className:`space-y-2`,children:[(0,a.jsx)(i.Label,{htmlFor:`report-description`,children:`Description`}),(0,a.jsx)(i.Input,{id:`report-description`,value:d.description||``,onChange:e=>f({...d,description:e.target.value}),placeholder:`Enter report description`})]}),r.length>0&&(0,a.jsxs)(`div`,{className:`space-y-2`,children:[(0,a.jsx)(i.Label,{children:`Data Source`}),(0,a.jsxs)(`select`,{className:`w-full border rounded-md p-2`,children:[(0,a.jsx)(`option`,{value:``,children:`Select a data source`}),r.map((e,t)=>(0,a.jsxs)(`option`,{value:t,children:[`Data Source `,t+1]},t))]})]}),(0,a.jsxs)(`div`,{className:`space-y-2`,children:[(0,a.jsx)(i.Label,{children:`Export Options`}),(0,a.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,a.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,a.jsx)(`input`,{type:`checkbox`,checked:d.showExportButtons||!1,onChange:e=>f({...d,showExportButtons:e.target.checked})}),(0,a.jsx)(`span`,{className:`text-sm`,children:`Show Export Buttons`})]}),(0,a.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,a.jsx)(`input`,{type:`checkbox`,checked:d.showPrintButton||!1,onChange:e=>f({...d,showPrintButton:e.target.checked})}),(0,a.jsx)(`span`,{className:`text-sm`,children:`Show Print Button`})]})]})]}),(0,a.jsxs)(`div`,{className:`space-y-2`,children:[(0,a.jsx)(i.Label,{htmlFor:`export-format`,children:`Default Export Format`}),(0,a.jsxs)(`select`,{id:`export-format`,className:`w-full border rounded-md p-2`,value:d.defaultExportFormat||`pdf`,onChange:e=>f({...d,defaultExportFormat:e.target.value}),children:[(0,a.jsx)(`option`,{value:`pdf`,children:`PDF`}),(0,a.jsx)(`option`,{value:`excel`,children:`Excel`}),(0,a.jsx)(`option`,{value:`csv`,children:`CSV`}),(0,a.jsx)(`option`,{value:`json`,children:`JSON`}),(0,a.jsx)(`option`,{value:`html`,children:`HTML`})]})]})]})}),(0,a.jsxs)(i.TabsContent,{value:`fields`,className:`space-y-4 mt-4`,children:[(0,a.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,a.jsx)(i.Label,{children:`Report Fields`}),(0,a.jsxs)(i.Button,{size:`sm`,variant:`outline`,onClick:x,disabled:p.length>=o.length,children:[(0,a.jsx)(u.Plus,{className:`h-4 w-4 mr-2`}),`Add Field`]})]}),(0,a.jsxs)(`div`,{className:`space-y-2`,children:[p.map((e,t)=>(0,a.jsx)(`div`,{className:`flex items-center gap-2 p-3 border rounded-lg`,children:(0,a.jsxs)(`div`,{className:`flex-1 grid grid-cols-4 gap-2`,children:[(0,a.jsxs)(`div`,{children:[(0,a.jsx)(i.Label,{className:`text-xs`,children:`Field Name`}),(0,a.jsx)(`div`,{className:`text-sm font-medium`,children:e.name})]}),(0,a.jsxs)(`div`,{children:[(0,a.jsx)(i.Label,{className:`text-xs`,children:`Label`}),(0,a.jsx)(i.Input,{className:`h-8 text-sm`,value:e.label||e.name,onChange:n=>C(t,{...e,label:n.target.value})})]}),(0,a.jsxs)(`div`,{children:[(0,a.jsx)(i.Label,{className:`text-xs`,children:`Aggregation`}),(0,a.jsxs)(`select`,{className:`w-full border rounded-md h-8 text-sm px-2`,value:e.aggregation||``,onChange:n=>C(t,{...e,aggregation:n.target.value}),children:[(0,a.jsx)(`option`,{value:``,children:`None`}),(0,a.jsx)(`option`,{value:`sum`,children:`Sum`}),(0,a.jsx)(`option`,{value:`count`,children:`Count`}),(0,a.jsx)(`option`,{value:`avg`,children:`Average`}),(0,a.jsx)(`option`,{value:`min`,children:`Min`}),(0,a.jsx)(`option`,{value:`max`,children:`Max`})]})]}),(0,a.jsx)(`div`,{className:`flex items-end justify-end`,children:(0,a.jsx)(i.Button,{size:`sm`,variant:`ghost`,className:`text-red-500 hover:text-red-700 hover:bg-red-50`,onClick:()=>S(t),children:(0,a.jsx)(u.Trash2,{className:`h-4 w-4`})})})]})},t)),p.length===0&&(0,a.jsx)(`div`,{className:`text-center py-8 text-muted-foreground border-2 border-dashed rounded-lg`,children:`No fields selected. Click "Add Field" to begin.`})]})]}),(0,a.jsxs)(i.TabsContent,{value:`filters`,className:`space-y-4 mt-4`,children:[(0,a.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,a.jsx)(i.Label,{children:`Report Filters`}),(0,a.jsxs)(i.Button,{size:`sm`,variant:`outline`,onClick:w,children:[(0,a.jsx)(u.Plus,{className:`h-4 w-4 mr-2`}),`Add Filter`]})]}),(0,a.jsxs)(`div`,{className:`space-y-2`,children:[h.map((e,t)=>(0,a.jsxs)(`div`,{className:`flex items-center gap-2 p-3 border rounded-lg`,children:[(0,a.jsxs)(`div`,{className:`flex-1 grid grid-cols-3 gap-2`,children:[(0,a.jsxs)(`div`,{children:[(0,a.jsx)(i.Label,{className:`text-xs`,children:`Field`}),(0,a.jsx)(`select`,{className:`w-full border rounded-md h-8 text-sm px-2`,value:e.field,onChange:n=>E(t,{...e,field:n.target.value}),children:o.map((e,t)=>(0,a.jsx)(`option`,{value:e.name,children:e.label||e.name},t))})]}),(0,a.jsxs)(`div`,{children:[(0,a.jsx)(i.Label,{className:`text-xs`,children:`Operator`}),(0,a.jsxs)(`select`,{className:`w-full border rounded-md h-8 text-sm px-2`,value:e.operator,onChange:n=>E(t,{...e,operator:n.target.value}),children:[(0,a.jsx)(`option`,{value:`equals`,children:`Equals`}),(0,a.jsx)(`option`,{value:`contains`,children:`Contains`}),(0,a.jsx)(`option`,{value:`gt`,children:`Greater Than`}),(0,a.jsx)(`option`,{value:`lt`,children:`Less Than`}),(0,a.jsx)(`option`,{value:`between`,children:`Between`})]})]}),(0,a.jsxs)(`div`,{children:[(0,a.jsx)(i.Label,{className:`text-xs`,children:`Value`}),(0,a.jsx)(i.Input,{className:`h-8 text-sm`,value:String(e.value),onChange:n=>E(t,{...e,value:n.target.value})})]})]}),(0,a.jsx)(i.Button,{size:`sm`,variant:`ghost`,className:`text-red-500 hover:text-red-700 hover:bg-red-50 self-end`,onClick:()=>T(t),children:(0,a.jsx)(u.Trash2,{className:`h-4 w-4`})})]},t)),h.length===0&&(0,a.jsx)(`div`,{className:`text-center py-8 text-muted-foreground border-2 border-dashed rounded-lg`,children:`No filters defined.`})]})]}),(0,a.jsxs)(i.TabsContent,{value:`grouping`,className:`space-y-4 mt-4`,children:[(0,a.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,a.jsx)(i.Label,{children:`Grouping Rules`}),(0,a.jsxs)(i.Button,{size:`sm`,variant:`outline`,onClick:D,children:[(0,a.jsx)(u.Plus,{className:`h-4 w-4 mr-2`}),`Add Group`]})]}),(0,a.jsxs)(`div`,{className:`space-y-2`,children:[_.map((e,t)=>(0,a.jsxs)(`div`,{className:`flex items-center gap-2 p-3 border rounded-lg`,children:[(0,a.jsxs)(`div`,{className:`flex-1 grid grid-cols-2 gap-2`,children:[(0,a.jsxs)(`div`,{children:[(0,a.jsx)(i.Label,{className:`text-xs`,children:`Field`}),(0,a.jsx)(`select`,{className:`w-full border rounded-md h-8 text-sm px-2`,value:e.field,onChange:n=>k(t,{...e,field:n.target.value}),children:o.map((e,t)=>(0,a.jsx)(`option`,{value:e.name,children:e.label||e.name},t))})]}),(0,a.jsxs)(`div`,{children:[(0,a.jsx)(i.Label,{className:`text-xs`,children:`Sort Order`}),(0,a.jsxs)(`select`,{className:`w-full border rounded-md h-8 text-sm px-2`,value:e.sort||`asc`,onChange:n=>k(t,{...e,sort:n.target.value}),children:[(0,a.jsx)(`option`,{value:`asc`,children:`Ascending`}),(0,a.jsx)(`option`,{value:`desc`,children:`Descending`})]})]})]}),(0,a.jsx)(i.Button,{size:`sm`,variant:`ghost`,className:`text-red-500 hover:text-red-700 hover:bg-red-50 self-end`,onClick:()=>O(t),children:(0,a.jsx)(u.Trash2,{className:`h-4 w-4`})})]},t)),_.length===0&&(0,a.jsx)(`div`,{className:`text-center py-8 text-muted-foreground border-2 border-dashed rounded-lg`,children:`No grouping rules applied.`})]})]}),(0,a.jsxs)(i.TabsContent,{value:`sections`,className:`space-y-4 mt-4`,children:[(0,a.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,a.jsx)(i.Label,{children:`Report Sections`}),(0,a.jsxs)(`div`,{className:`flex gap-2`,children:[(0,a.jsxs)(i.Button,{size:`sm`,variant:`outline`,onClick:()=>A(`header`),children:[(0,a.jsx)(u.Plus,{className:`h-4 w-4 mr-2`}),`Header`]}),(0,a.jsxs)(i.Button,{size:`sm`,variant:`outline`,onClick:()=>A(`chart`),children:[(0,a.jsx)(u.Plus,{className:`h-4 w-4 mr-2`}),`Chart`]}),(0,a.jsxs)(i.Button,{size:`sm`,variant:`outline`,onClick:()=>A(`table`),children:[(0,a.jsx)(u.Plus,{className:`h-4 w-4 mr-2`}),`Table`]})]})]}),(0,a.jsxs)(`div`,{className:`space-y-2`,children:[y.map((e,t)=>(0,a.jsxs)(`div`,{className:`p-3 border rounded-lg space-y-2`,children:[(0,a.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,a.jsxs)(`div`,{className:`font-medium flex items-center gap-2`,children:[(0,a.jsx)(`div`,{className:`text-xs bg-muted px-2 py-0.5 rounded uppercase`,children:e.type}),e.title]}),(0,a.jsx)(i.Button,{size:`sm`,variant:`ghost`,className:`text-red-500 hover:text-red-700 hover:bg-red-50`,onClick:()=>j(t),children:(0,a.jsx)(u.Trash2,{className:`h-4 w-4`})})]}),(0,a.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,a.jsxs)(`div`,{children:[(0,a.jsx)(i.Label,{className:`text-xs`,children:`Title`}),(0,a.jsx)(i.Input,{className:`h-8 text-sm`,value:e.title||``,onChange:n=>M(t,{...e,title:n.target.value})})]}),e.type===`text`&&(0,a.jsxs)(`div`,{className:`col-span-2`,children:[(0,a.jsx)(i.Label,{className:`text-xs`,children:`Content`}),(0,a.jsx)(i.Input,{className:`h-8 text-sm`,value:e.text||``,onChange:n=>M(t,{...e,text:n.target.value})})]}),e.type===`chart`&&(0,a.jsxs)(`div`,{className:`col-span-2 grid grid-cols-2 gap-2 mt-2 p-2 bg-muted/20 rounded`,children:[(0,a.jsx)(`div`,{className:`col-span-2`,children:(0,a.jsx)(i.Label,{className:`text-xs font-semibold`,children:`Chart Configuration`})}),(0,a.jsxs)(`div`,{children:[(0,a.jsx)(i.Label,{className:`text-xs`,children:`Chart Type`}),(0,a.jsxs)(`select`,{className:`flex h-8 w-full rounded-md border border-input bg-background px-3 py-1 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,value:e.chart?.chartType||`bar`,onChange:n=>M(t,{...e,chart:{...e.chart,type:`chart`,chartType:n.target.value}}),children:[(0,a.jsx)(`option`,{value:`bar`,children:`Bar`}),(0,a.jsx)(`option`,{value:`line`,children:`Line`}),(0,a.jsx)(`option`,{value:`area`,children:`Area`}),(0,a.jsx)(`option`,{value:`pie`,children:`Pie`})]})]}),(0,a.jsxs)(`div`,{children:[(0,a.jsx)(i.Label,{className:`text-xs`,children:`X-Axis Field`}),(0,a.jsxs)(`select`,{className:`flex h-8 w-full rounded-md border border-input bg-background px-3 py-1 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,value:e.chart?.xAxisField||``,onChange:n=>M(t,{...e,chart:{...e.chart,type:`chart`,xAxisField:n.target.value}}),children:[(0,a.jsx)(`option`,{value:``,children:`Select Field...`}),o.map(e=>(0,a.jsx)(`option`,{value:e.name,children:e.label||e.name},e.name)),o.length===0&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(`option`,{value:`name`,children:`Name`}),(0,a.jsx)(`option`,{value:`month`,children:`Month`})]})]})]}),(0,a.jsxs)(`div`,{className:`col-span-2`,children:[(0,a.jsx)(i.Label,{className:`text-xs`,children:`Y-Axis Fields (comma separated)`}),(0,a.jsx)(i.Input,{className:`h-8 text-sm`,placeholder:`e.g. value, count`,value:e.chart?.yAxisFields?.join(`, `)||``,onChange:n=>M(t,{...e,chart:{...e.chart,type:`chart`,yAxisFields:n.target.value.split(`,`).map(e=>e.trim()).filter(Boolean)}})})]})]})]})]},t)),y.length===0&&(0,a.jsx)(`div`,{className:`text-center py-8 text-muted-foreground border-2 border-dashed rounded-lg`,children:`No customized sections. The default report layout will be used.`})]})]}),(0,a.jsx)(i.TabsContent,{value:`schedule`,className:`space-y-4 mt-4`,children:(0,a.jsx)($,{schedule:d.schedule,onChange:e=>f({...d,schedule:e})})})]}),(0,a.jsxs)(`div`,{className:`flex items-center justify-end gap-2 mt-6 pt-4 border-t`,children:[(0,a.jsx)(i.Button,{variant:`outline`,onClick:()=>{l&&console.log(`Report cancelled:`,l)},children:`Cancel`}),(0,a.jsxs)(i.Button,{onClick:()=>{console.log(`Saving report:`,d),c&&alert(`Report saved! (Handler: `+c+`)`)},children:[(0,a.jsx)(u.Save,{className:`h-4 w-4 mr-2`}),`Save Report`]})]})]})]}),s&&(0,a.jsxs)(i.Card,{className:`mt-8 border-2 border-blue-100`,children:[(0,a.jsx)(i.CardHeader,{className:`bg-blue-50/50`,children:(0,a.jsx)(i.CardTitle,{className:`text-blue-900 text-sm uppercase tracking-wide`,children:`Live Preview`})}),(0,a.jsx)(i.CardContent,{className:`pt-6`,children:(0,a.jsx)(Q,{schema:{type:`report-viewer`,report:{...d,fields:p,filters:h,groupBy:_,sections:y},data:[{id:1,name:`Sample Item A`,value:100,status:`New`},{id:2,name:`Sample Item B`,value:250,status:`Active`},{id:3,name:`Sample Item C`,value:75,status:`Closed`}]}})})]})]})},De=[{value:``,label:`None`},{value:`sum`,label:`Sum`},{value:`count`,label:`Count`},{value:`avg`,label:`Average`},{value:`min`,label:`Min`},{value:`max`,label:`Max`}];function Oe({availableFields:e,value:t,onChange:n}){let r=Array.isArray(t)?t.map(e=>typeof e==`string`?{field:e,label:e,type:`string`}:{field:e.field||e.name||e.value,label:e.label||e.name||e.field||``,type:e.type||`string`,aggregate:e.aggregate??e.aggregation}):[],o=r.map(e=>e.field),s=t=>{let i=o.includes(t),a;if(i)a=r.filter(e=>e.field!==t);else{let n=e.find(e=>e.value===t);a=[...r,{field:t,label:n?.label||t,type:n?.type||`string`}]}n(a)},c=(e,t)=>{n(r.map(n=>n.field===e?{...n,aggregate:t||void 0}:n))};return e.length===0?(0,a.jsx)(`div`,{className:`text-xs text-muted-foreground py-2`,"data-testid":`field-picker-empty`,children:`No fields available`}):(0,a.jsx)(`div`,{className:`space-y-1 py-1`,"data-testid":`field-picker`,children:e.map(e=>{let t=o.includes(e.value),n=r.find(t=>t.field===e.value);return(0,a.jsxs)(`div`,{className:`flex items-center gap-2 px-1 py-0.5 rounded hover:bg-muted/50 text-xs`,children:[(0,a.jsxs)(`label`,{className:`flex items-center gap-2 flex-1 cursor-pointer`,children:[(0,a.jsx)(i.Checkbox,{checked:t,onCheckedChange:()=>s(e.value),"data-testid":`field-picker-${e.value}`}),(0,a.jsx)(`span`,{className:`flex-1`,children:e.label}),e.type&&(0,a.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:e.type})]}),t&&(0,a.jsx)(`select`,{className:`h-5 text-[10px] border rounded px-1 bg-background`,value:n?.aggregate||``,onChange:t=>c(e.value,t.target.value),"data-testid":`field-agg-${e.value}`,children:De.map(e=>(0,a.jsx)(`option`,{value:e.value,children:e.label},e.value))})]},e.value)})})}var ke=[{value:``,label:`None`},{value:`bar`,label:`Bar Chart`},{value:`line`,label:`Line Chart`},{value:`pie`,label:`Pie Chart`},{value:`area`,label:`Area Chart`},{value:`donut`,label:`Donut Chart`},{value:`scatter`,label:`Scatter Plot`}];function Ae({availableFields:e,value:t,onChange:n}){let r=t||{},i=r.type??r.chartType??``,o=r.xAxis??r.xAxisField??``,s=r.yAxis??r.yAxisFields?.[0]??``,c=e=>{let t={...r,...e};`type`in e&&delete t.chartType,`xAxis`in e&&delete t.xAxisField,`yAxis`in e&&delete t.yAxisFields,n(t)};return(0,a.jsxs)(`div`,{className:`space-y-2 py-1`,"data-testid":`chart-config`,children:[(0,a.jsxs)(`div`,{children:[(0,a.jsx)(`label`,{className:`text-[10px] text-muted-foreground`,children:`Chart type`}),(0,a.jsx)(`select`,{className:`w-full h-7 text-xs border rounded px-2 bg-background`,value:i,onChange:e=>c({type:e.target.value||void 0}),"data-testid":`chart-type-select`,children:ke.map(e=>(0,a.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),i&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(`div`,{children:[(0,a.jsx)(`label`,{className:`text-[10px] text-muted-foreground`,children:`X-axis field`}),(0,a.jsxs)(`select`,{className:`w-full h-7 text-xs border rounded px-2 bg-background`,value:o,onChange:e=>c({xAxis:e.target.value||void 0}),"data-testid":`chart-x-field`,children:[(0,a.jsx)(`option`,{value:``,children:`Select field…`}),e.map(e=>(0,a.jsx)(`option`,{value:e.value,children:e.label},e.value))]})]}),(0,a.jsxs)(`div`,{children:[(0,a.jsx)(`label`,{className:`text-[10px] text-muted-foreground`,children:`Y-axis field`}),(0,a.jsxs)(`select`,{className:`w-full h-7 text-xs border rounded px-2 bg-background`,value:s,onChange:e=>c({yAxis:e.target.value||void 0}),"data-testid":`chart-y-field`,children:[(0,a.jsx)(`option`,{value:``,children:`Select field…`}),e.filter(e=>e.type===`number`).map(e=>(0,a.jsx)(`option`,{value:e.value,children:e.label},e.value))]})]})]})]})}var je=[{value:`equals`,label:`=`},{value:`not_equals`,label:`≠`},{value:`greater_than`,label:`>`},{value:`less_than`,label:`<`},{value:`contains`,label:`Contains`}];function Me({availableFields:e,value:t,onChange:n}){let r=Array.isArray(t)?t:[],o=()=>{n([...r,{field:e[0]?.value||``,operator:`equals`,value:``,backgroundColor:`#fef9c3`,textColor:``}])},s=e=>{n(r.filter((t,n)=>n!==e))},c=(e,t)=>{n(r.map((n,r)=>r===e?{...n,...t}:n))};return(0,a.jsxs)(`div`,{className:`space-y-2 py-1`,"data-testid":`conditional-format-rules`,children:[r.map((t,n)=>(0,a.jsxs)(`div`,{className:`flex items-center gap-1 text-[10px] p-1 border rounded bg-muted/20`,children:[(0,a.jsx)(`select`,{className:`h-5 text-[10px] border rounded px-1 bg-background flex-1`,value:t.field,onChange:e=>c(n,{field:e.target.value}),"data-testid":`cf-rule-field-${n}`,children:e.map(e=>(0,a.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,a.jsx)(`select`,{className:`h-5 text-[10px] border rounded px-1 bg-background w-12`,value:t.operator,onChange:e=>c(n,{operator:e.target.value}),children:je.map(e=>(0,a.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,a.jsx)(`input`,{className:`h-5 text-[10px] border rounded px-1 bg-background w-16`,value:t.value,placeholder:`value`,onChange:e=>c(n,{value:e.target.value}),"data-testid":`cf-rule-value-${n}`}),(0,a.jsx)(`input`,{type:`color`,className:`h-5 w-5 rounded border cursor-pointer`,value:t.backgroundColor||`#fef9c3`,onChange:e=>c(n,{backgroundColor:e.target.value}),title:`Background color`}),(0,a.jsx)(i.Button,{type:`button`,size:`sm`,variant:`ghost`,className:`h-5 w-5 p-0`,onClick:()=>s(n),"data-testid":`cf-rule-remove-${n}`,children:(0,a.jsx)(u.Trash2,{className:`h-3 w-3`})})]},n)),(0,a.jsxs)(i.Button,{type:`button`,size:`sm`,variant:`outline`,className:`h-6 text-[10px] w-full`,onClick:o,"data-testid":`cf-add-rule`,children:[(0,a.jsx)(u.Plus,{className:`h-3 w-3 mr-1`}),`Add Rule`]})]})}var Ne=[{value:`header`,label:`Header`},{value:`summary`,label:`Summary`},{value:`table`,label:`Table`},{value:`chart`,label:`Chart`},{value:`text`,label:`Text`}];function Pe({value:e,onChange:t}){let n=Array.isArray(e)?e:[],r=e=>{t([...n,{type:e,title:`New ${e}`,visible:!0}])},o=e=>{t(n.filter((t,n)=>n!==e))},s=(e,r)=>{t(n.map((t,n)=>n===e?{...t,...r}:t))},c=(e,r)=>{let i=e+r;if(i<0||i>=n.length)return;let a=[...n];[a[e],a[i]]=[a[i],a[e]],t(a)};return(0,a.jsxs)(`div`,{className:`space-y-2 py-1`,"data-testid":`section-manager`,children:[n.map((e,t)=>(0,a.jsxs)(`div`,{className:`flex items-center gap-1 text-[10px] p-1.5 border rounded bg-muted/20`,children:[(0,a.jsxs)(`div`,{className:`flex flex-col gap-0.5 mr-1`,children:[(0,a.jsx)(`button`,{type:`button`,className:`text-muted-foreground hover:text-foreground disabled:opacity-30`,disabled:t===0,onClick:()=>c(t,-1),"data-testid":`section-up-${t}`,children:`▲`}),(0,a.jsx)(`button`,{type:`button`,className:`text-muted-foreground hover:text-foreground disabled:opacity-30`,disabled:t===n.length-1,onClick:()=>c(t,1),"data-testid":`section-down-${t}`,children:`▼`})]}),(0,a.jsx)(`span`,{className:`text-[9px] bg-muted px-1.5 py-0.5 rounded uppercase font-medium shrink-0`,children:e.type}),(0,a.jsx)(`input`,{className:`h-5 text-[10px] border rounded px-1 bg-background flex-1 min-w-0`,value:e.title||``,placeholder:`Section title`,onChange:e=>s(t,{title:e.target.value}),"data-testid":`section-title-${t}`}),(0,a.jsx)(i.Button,{type:`button`,size:`sm`,variant:`ghost`,className:`h-5 w-5 p-0 shrink-0`,onClick:()=>o(t),"data-testid":`section-remove-${t}`,children:(0,a.jsx)(u.Trash2,{className:`h-3 w-3`})})]},t)),(0,a.jsx)(`div`,{className:`flex gap-1 flex-wrap`,children:Ne.map(e=>(0,a.jsxs)(i.Button,{type:`button`,size:`sm`,variant:`outline`,className:`h-6 text-[10px]`,onClick:()=>r(e.value),"data-testid":`section-add-${e.value}`,children:[(0,a.jsx)(u.Plus,{className:`h-3 w-3 mr-0.5`}),e.label]},e.value))})]})}function Fe(e=[]){return{breadcrumb:[`Report`,`Configuration`],sections:[{key:`basic`,title:`Basic`,fields:[{key:`label`,label:`Title`,type:`input`,placeholder:`Report title`},{key:`description`,label:`Description`,type:`input`,placeholder:`Report description`},{key:`type`,label:`Report type`,type:`select`,defaultValue:`tabular`,options:[{value:`tabular`,label:`Tabular`},{value:`summary`,label:`Summary`},{value:`matrix`,label:`Matrix`}],helpText:`Tabular: flat table. Summary: grouped with subtotals. Matrix: pivot table (planned).`}]},{key:`data`,title:`Data`,collapsible:!0,fields:[{key:`objectName`,label:`Data source`,type:`input`,placeholder:`e.g. opportunity`,helpText:`Object name to query data from`},{key:`limit`,label:`Row limit`,type:`input`,defaultValue:`100`,placeholder:`e.g. 100`}]},{key:`columns`,title:`Columns`,collapsible:!0,hint:`Select fields to display as report columns. Set aggregation per column for summary reports.`,fields:[{key:`columns`,label:`Report columns`,type:`custom`,render:(t,n)=>(0,a.jsx)(Oe,{availableFields:e,value:t,onChange:n})}]},{key:`filters`,title:`Filters`,collapsible:!0,hint:`Define filter conditions for the report data`,fields:[{key:`filter`,label:`Conditions`,type:`filter`,fields:e}]},{key:`groupBy`,title:`Group By`,collapsible:!0,hint:`Group report data and compute aggregations`,fields:[{key:`groupingsDown`,label:`Grouping`,type:`custom`,render:(t,n)=>(0,a.jsx)(i.SortBuilder,{fields:e,value:Array.isArray(t)?t.map(e=>({...e,order:e.order??e.sortOrder??`asc`})):[],onChange:e=>n(e.map(e=>{let{id:t,order:n,...r}=e;return{...r,sortOrder:n??`asc`}}))})}]},{key:`chart`,title:`Chart`,collapsible:!0,hint:`Add a chart visualization to the report`,fields:[{key:`chart`,label:`Chart`,type:`custom`,render:(t,n)=>(0,a.jsx)(Ae,{availableFields:e,value:t,onChange:n})}]},{key:`conditionalFormatting`,title:`Conditional Format`,collapsible:!0,defaultCollapsed:!0,hint:`Highlight cells based on field value conditions`,fields:[{key:`conditionalFormatting`,label:`Rules`,type:`custom`,render:(t,n)=>(0,a.jsx)(Me,{availableFields:e,value:t,onChange:n})}]},{key:`sections`,title:`Sections`,collapsible:!0,defaultCollapsed:!0,hint:`Manage report layout blocks (header, table, chart, summary)`,fields:[{key:`sections`,label:`Report sections`,type:`custom`,render:(e,t)=>(0,a.jsx)(Pe,{value:e,onChange:t})}]},{key:`export`,title:`Export`,collapsible:!0,defaultCollapsed:!0,fields:[{key:`showExportButtons`,label:`Show export buttons`,type:`switch`,defaultValue:!0},{key:`showPrintButton`,label:`Show print button`,type:`switch`,defaultValue:!0},{key:`defaultExportFormat`,label:`Default export format`,type:`select`,defaultValue:`pdf`,options:[{value:`pdf`,label:`PDF`},{value:`excel`,label:`Excel`},{value:`csv`,label:`CSV`},{value:`json`,label:`JSON`},{value:`html`,label:`HTML`}]}]},{key:`schedule`,title:`Schedule`,collapsible:!0,defaultCollapsed:!0,fields:[{key:`schedule`,label:`Schedule`,type:`custom`,render:(e,t)=>(0,a.jsx)($,{schedule:e,onChange:t})}]},{key:`appearance`,title:`Appearance`,collapsible:!0,defaultCollapsed:!0,fields:[{key:`showToolbar`,label:`Show toolbar`,type:`switch`,defaultValue:!0},{key:`refreshInterval`,label:`Refresh interval`,type:`select`,defaultValue:`0`,options:[{value:`0`,label:`Manual`},{value:`30`,label:`30s`},{value:`60`,label:`1 min`},{value:`300`,label:`5 min`}]}]}]}}function Ie({open:e,onClose:t,config:r,onSave:o,onFieldChange:s,availableFields:c}){let{draft:l,isDirty:u,updateField:d,discard:f,undo:p,redo:m,canUndo:h,canRedo:g}=(0,i.useConfigDraft)(r,{onUpdate:s});return(0,a.jsx)(i.ConfigPanelRenderer,{open:e,onClose:t,schema:n.useMemo(()=>Fe(c),[c]),draft:l,isDirty:u,onFieldChange:d,onSave:()=>o(l),onDiscard:f,onUndo:p,onRedo:m,canUndo:h,canRedo:g})}async function Le(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 J(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(Be),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 Ve(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=Ue(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)}Ge(``+[s.join(` `),...c.map(e=>e.join(` `))].join(`
|
|
59
|
+
`),i||`${e.title||`report`}.tsv`,`text/tab-separated-values`)}function ze(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 Le(e,{dataSource:t,resource:n,format:r});o.push(i)}return r(e,i),o}}function Be(e){return{name:e.name,header:e.label||e.name}}function Ve(e,t){return e==null?``:typeof e==`number`&&t?e.toLocaleString(`en-US`,He(t)):We(String(e))}function He(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 Ue(e){let t=``,n=e;for(;n>=0;)t=String.fromCharCode(n%26+65)+t,n=Math.floor(n/26)-1;return t}function We(e){if(e.length>0){let t=e.charAt(0);if(t===`=`||t===`+`||t===`-`||t===`@`||t===`|`)return`'${e}`}return e}function Ge(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`,K,{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`,K,{namespace:`report`,label:`Spec Report`,category:`Report`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`},{name:`type`,type:`string`,label:`Report Type`}]}),t.ComponentRegistry.register(`report-viewer`,Q,{namespace:`report`,label:`Report Viewer`,category:`Report`,inputs:[{name:`report`,type:`code`,label:`Report Definition`},{name:`showToolbar`,type:`boolean`,label:`Show Toolbar`}]}),t.ComponentRegistry.register(`report-builder`,Ee,{namespace:`report`,label:`Report Builder`,category:`Report`,inputs:[{name:`report`,type:`code`,label:`Initial Report`}]}),e.JoinedReportRenderer=me,e.LegacyReportRenderer=y,e.MatrixRenderer=de,e.ReportBuilder=Ee,e.ReportConfigPanel=Ie,e.ReportRenderer=K,e.ReportViewer=Q,e.ScheduleConfig=$,e.SpecReportGrid=B,e.aggregateRows=C,e.bucketDate=x,e.buildAggregateQuery=P,e.buildDrillAction=z,e.collectFields=N,e.columnKey=b,e.createDrillHandler=ie,e.createScheduleTrigger=ze,e.exportAsCSV=ge,e.exportAsExcel=ye,e.exportAsHTML=q,e.exportAsJSON=_e,e.exportAsPDF=ve,e.exportExcelWithFormulas=Re,e.exportReport=J,e.exportWithLiveData=Le,e.formatValue=Z,e.groupAndAggregate=w,e.groupingValue=S,e.isDrillAction=re,e.mergeFilters=M,e.pivotRows=T,e.registerDrillHandler=ae,e.useReportData=L});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ActionRunner } from '../../core/src';
|
|
2
|
+
import { DataSource, JoinedReportBlock, JoinedSpecReport } from '../../types/src';
|
|
3
|
+
import { DrillOpenIn, DrillView } from './drill';
|
|
4
|
+
/**
|
|
5
|
+
* JoinedReportRenderer
|
|
6
|
+
*
|
|
7
|
+
* Renders a spec `Report` of `type: 'joined'` as a vertical stack of
|
|
8
|
+
* self-contained `ReportRenderer` blocks. Each block is its own `SpecReport`
|
|
9
|
+
* with its own data fetch, aggregations, and drill — they are independent
|
|
10
|
+
* widgets composed on a single page.
|
|
11
|
+
*
|
|
12
|
+
* Filter inheritance
|
|
13
|
+
* ------------------
|
|
14
|
+
* The outer (joined) report can carry a top-level `filter`. It is merged into
|
|
15
|
+
* each block's `filter` as a logical `$and`, so a report-wide constraint
|
|
16
|
+
* (e.g. "owner = me") propagates to every block without repetition. Block
|
|
17
|
+
* filters keep precedence on key collisions because they are by convention
|
|
18
|
+
* the more specific constraint.
|
|
19
|
+
*
|
|
20
|
+
* Drill & runtime propagation
|
|
21
|
+
* ---------------------------
|
|
22
|
+
* `dataSource`, `actionRunner`, `drillView`, `drillOpenIn` and `runtimeFilter`
|
|
23
|
+
* flow uniformly into every block so any block's drill behaves identically to
|
|
24
|
+
* a standalone report. Each block calls its own {@link useReportData} hook —
|
|
25
|
+
* there is no shared cache, by design (blocks may query different objects).
|
|
26
|
+
*
|
|
27
|
+
* Layout
|
|
28
|
+
* ------
|
|
29
|
+
* Blocks render vertically. The block label/description renders above the
|
|
30
|
+
* block content. We intentionally avoid imposing a column layout: composition
|
|
31
|
+
* (e.g. a 2×2 grid of blocks) is a host concern handled by a parent layout
|
|
32
|
+
* component.
|
|
33
|
+
*/
|
|
34
|
+
import * as React from 'react';
|
|
35
|
+
export interface JoinedReportRendererProps {
|
|
36
|
+
report: JoinedSpecReport;
|
|
37
|
+
dataSource?: DataSource;
|
|
38
|
+
/** Runtime filter (e.g. global toolbar filter) merged into every block. */
|
|
39
|
+
runtimeFilter?: Record<string, unknown>;
|
|
40
|
+
actionRunner?: ActionRunner;
|
|
41
|
+
drillView?: DrillView;
|
|
42
|
+
drillOpenIn?: DrillOpenIn;
|
|
43
|
+
className?: string;
|
|
44
|
+
/** Override rendering of an individual block (advanced). */
|
|
45
|
+
renderBlock?: (block: JoinedReportBlock, index: number, content: React.ReactNode) => React.ReactNode;
|
|
46
|
+
}
|
|
47
|
+
export declare const JoinedReportRenderer: React.FC<JoinedReportRendererProps>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
export interface LegacyReportRendererProps {
|
|
3
|
+
schema: {
|
|
4
|
+
type: string;
|
|
5
|
+
id?: string;
|
|
6
|
+
title?: string;
|
|
7
|
+
description?: string;
|
|
8
|
+
chart?: any;
|
|
9
|
+
data?: any[];
|
|
10
|
+
columns?: any[];
|
|
11
|
+
className?: string;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export declare const LegacyReportRenderer: React.FC<LegacyReportRendererProps>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { ActionRunner } from '../../core/src';
|
|
2
|
+
import { SpecReport, DataSource } from '../../types/src';
|
|
3
|
+
import { DrillOpenIn, DrillView } from './drill';
|
|
4
|
+
/**
|
|
5
|
+
* MatrixRenderer
|
|
6
|
+
*
|
|
7
|
+
* Renders a spec `Report` of type `'matrix'` as a 2D pivot table.
|
|
8
|
+
*
|
|
9
|
+
* - Drives data via {@link useReportData}, which returns a {@link PivotMatrix}
|
|
10
|
+
* when `report.groupingsAcross` is non-empty.
|
|
11
|
+
* - Headers: row headers down the left, column headers across the top.
|
|
12
|
+
* Multi-level groupings are shown as concatenated path segments.
|
|
13
|
+
* - Body cells display one row per column-definition (e.g. `amount sum`).
|
|
14
|
+
* When `report.columns` has more than one entry, each cell shows the
|
|
15
|
+
* values stacked vertically with their labels.
|
|
16
|
+
* - Totals: row total column on the right, column total row at the bottom,
|
|
17
|
+
* and grand-total in the bottom-right corner.
|
|
18
|
+
* - Drill-down: clicking a body cell fires `onCellClick` with both the row
|
|
19
|
+
* key and column key; if an `actionRunner` is supplied, it also dispatches
|
|
20
|
+
* a {@link buildDrillAction} carrying both keys merged.
|
|
21
|
+
*
|
|
22
|
+
* We intentionally don't use ObjectGrid here — its tree model is single-axis
|
|
23
|
+
* and bolting a 2D matrix onto AG-Grid header groups would be heavier than a
|
|
24
|
+
* direct table. The pivot dataset is already small (rows × cols are
|
|
25
|
+
* dimensions, not raw records).
|
|
26
|
+
*/
|
|
27
|
+
import * as React from 'react';
|
|
28
|
+
export interface MatrixCellClickArgs {
|
|
29
|
+
rowKey: Record<string, unknown>;
|
|
30
|
+
colKey: Record<string, unknown>;
|
|
31
|
+
/** Pre-merged key combining row + col — convenient for drill construction. */
|
|
32
|
+
combinedKey: Record<string, unknown>;
|
|
33
|
+
/** Pre-aggregated values for the clicked cell (may be undefined for empty cells). */
|
|
34
|
+
values?: Record<string, unknown>;
|
|
35
|
+
}
|
|
36
|
+
export interface MatrixRendererProps {
|
|
37
|
+
report: SpecReport;
|
|
38
|
+
dataSource?: DataSource;
|
|
39
|
+
rows?: Array<Record<string, unknown>>;
|
|
40
|
+
runtimeFilter?: Record<string, unknown>;
|
|
41
|
+
/** Imperative drill callback. */
|
|
42
|
+
onCellClick?: (args: MatrixCellClickArgs) => void;
|
|
43
|
+
/** Declarative drill: dispatch a `type: 'drill'` action when a cell is clicked. */
|
|
44
|
+
actionRunner?: ActionRunner;
|
|
45
|
+
drillView?: DrillView;
|
|
46
|
+
drillOpenIn?: DrillOpenIn;
|
|
47
|
+
className?: string;
|
|
48
|
+
/** Render text for an empty cell. Defaults to "—". */
|
|
49
|
+
emptyCellText?: string;
|
|
50
|
+
}
|
|
51
|
+
export declare const MatrixRenderer: React.FC<MatrixRendererProps>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { StoryObj } from '@storybook/react';
|
|
2
|
+
/**
|
|
3
|
+
* MatrixRenderer stories — region × quarter pivot for M2 demo.
|
|
4
|
+
*
|
|
5
|
+
* Showcases:
|
|
6
|
+
* - `groupingsAcross` rendering as columns
|
|
7
|
+
* - `dateGranularity: 'quarter'` bucketing on close_date
|
|
8
|
+
* - Server-side aggregation path: stories supply a mock `dataSource.aggregate`
|
|
9
|
+
* that returns pre-bucketed rows so the hook skips client aggregation,
|
|
10
|
+
* mirroring what objectql's engine fallback now does end-to-end.
|
|
11
|
+
* - Cell click → drill action with combined (region, quarter) filter.
|
|
12
|
+
*/
|
|
13
|
+
import * as React from 'react';
|
|
14
|
+
declare const meta: {
|
|
15
|
+
title: string;
|
|
16
|
+
component: React.FC<import('./MatrixRenderer').MatrixRendererProps>;
|
|
17
|
+
parameters: {
|
|
18
|
+
layout: string;
|
|
19
|
+
};
|
|
20
|
+
tags: string[];
|
|
21
|
+
};
|
|
22
|
+
export default meta;
|
|
23
|
+
type Story = StoryObj<typeof meta>;
|
|
24
|
+
export declare const RegionByQuarterServerAggregated: Story;
|
|
@@ -1,14 +1,44 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ActionRunner } from '../../core/src';
|
|
2
|
+
import { SpecReport, DataSource } from '../../types/src';
|
|
3
|
+
import { LegacyReportRendererProps } from './LegacyReportRenderer';
|
|
4
|
+
import { DrillOpenIn, DrillView } from './drill';
|
|
5
|
+
/**
|
|
6
|
+
* ReportRenderer
|
|
7
|
+
*
|
|
8
|
+
* Thin dispatcher that routes a report schema to the correct renderer based
|
|
9
|
+
* on whether it is a spec-native `SpecReport` (preferred) or a legacy
|
|
10
|
+
* presentation-layer schema (`data`/`columns`/`chart`).
|
|
11
|
+
*
|
|
12
|
+
* Dispatch table:
|
|
13
|
+
* | report.type | Renderer |
|
|
14
|
+
* |------------------------|-----------------------------------|
|
|
15
|
+
* | tabular | summary | <SpecReportGrid> |
|
|
16
|
+
* | matrix | placeholder (M2) |
|
|
17
|
+
* | joined | placeholder (M3) |
|
|
18
|
+
* | (legacy / no type) | <LegacyReportRenderer> |
|
|
19
|
+
*
|
|
20
|
+
* Host apps can:
|
|
21
|
+
* - Pass a `SpecReport` plus a `dataSource` to drive a live, drillable report.
|
|
22
|
+
* - Pass a legacy `{ data, columns, chart }` schema for backwards compatibility.
|
|
23
|
+
*/
|
|
24
|
+
import * as React from 'react';
|
|
25
|
+
export type ReportRendererSchema = SpecReport | LegacyReportRendererProps['schema'];
|
|
2
26
|
export interface ReportRendererProps {
|
|
3
|
-
schema
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
27
|
+
/** Either a spec-native `SpecReport` or a legacy presentation schema. */
|
|
28
|
+
schema: ReportRendererSchema;
|
|
29
|
+
/** Required for spec reports unless `rows` is provided. */
|
|
30
|
+
dataSource?: DataSource | Record<string, unknown>;
|
|
31
|
+
/** Pre-fetched rows (skips data fetch). */
|
|
32
|
+
rows?: Array<Record<string, unknown>>;
|
|
33
|
+
/** Runtime filter merged on top of `report.filter`. */
|
|
34
|
+
runtimeFilter?: Record<string, unknown>;
|
|
35
|
+
/** Action runner used to dispatch `drill` actions on row click. */
|
|
36
|
+
actionRunner?: ActionRunner;
|
|
37
|
+
/** Default view for drill targets. */
|
|
38
|
+
drillView?: DrillView;
|
|
39
|
+
/** Where the drill target should open. */
|
|
40
|
+
drillOpenIn?: DrillOpenIn;
|
|
41
|
+
/** Optional class for the outer container. */
|
|
42
|
+
className?: string;
|
|
13
43
|
}
|
|
14
44
|
export declare const ReportRenderer: React.FC<ReportRendererProps>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { SpecReport, DataSource } from '../../types/src';
|
|
2
|
+
import { ActionRunner } from '../../core/src';
|
|
3
|
+
import { DrillOpenIn, DrillView } from './drill';
|
|
4
|
+
/**
|
|
5
|
+
* SpecReportGrid
|
|
6
|
+
*
|
|
7
|
+
* Bridge between the spec `Report` (definition) and `ObjectGrid` (renderer).
|
|
8
|
+
*
|
|
9
|
+
* - Drives data fetch via {@link useReportData}.
|
|
10
|
+
* - For `tabular` reports, renders a flat grid with columns mapped from `report.columns`.
|
|
11
|
+
* - For `summary` reports, applies `report.groupingsDown` as ObjectGrid grouping and
|
|
12
|
+
* passes per-group aggregations so collapsible group headers show subtotals.
|
|
13
|
+
* - `matrix` reports fall through to a "not supported" notice (handled by M2).
|
|
14
|
+
*
|
|
15
|
+
* The grand total is rendered as a footer-style row above the grid; per-column
|
|
16
|
+
* `summary` on the grid handles classic SQL `GRAND TOTAL` semantics.
|
|
17
|
+
*/
|
|
18
|
+
import * as React from 'react';
|
|
19
|
+
export interface SpecReportGridProps {
|
|
20
|
+
report: SpecReport;
|
|
21
|
+
/** Optional DataSource adapter. When omitted, `rows` must be supplied. */
|
|
22
|
+
dataSource?: DataSource;
|
|
23
|
+
/** Optional pre-fetched rows (skips dataSource.find). */
|
|
24
|
+
rows?: Record<string, unknown>[];
|
|
25
|
+
/** Optional runtime filter merged with report.filter via `$and`. */
|
|
26
|
+
runtimeFilter?: Record<string, unknown>;
|
|
27
|
+
/** Drill-down callback. Receives the group key for the clicked row. */
|
|
28
|
+
onDrillDown?: (groupKey: Record<string, unknown>, rawRows: Record<string, unknown>[]) => void;
|
|
29
|
+
/**
|
|
30
|
+
* Optional `ActionRunner` used to dispatch a `type: 'drill'` action on row
|
|
31
|
+
* click. When set, the grid builds the drill action via {@link buildDrillAction}
|
|
32
|
+
* and runs it through the engine — the host must register a `drill` handler
|
|
33
|
+
* (see {@link registerDrillHandler}) for the navigation to take effect.
|
|
34
|
+
* `onDrillDown` still fires (after dispatch) so consumers can observe.
|
|
35
|
+
*/
|
|
36
|
+
actionRunner?: ActionRunner;
|
|
37
|
+
/** Drill view override (default `'list'`). */
|
|
38
|
+
drillView?: DrillView;
|
|
39
|
+
/** Drill open-in override (default `'current'`). */
|
|
40
|
+
drillOpenIn?: DrillOpenIn;
|
|
41
|
+
className?: string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Render a spec `Report` as an `ObjectGrid` (Summary/Tabular only).
|
|
45
|
+
*
|
|
46
|
+
* For `matrix`/`joined` types this returns a placeholder; M2/M3 will
|
|
47
|
+
* provide dedicated renderers.
|
|
48
|
+
*/
|
|
49
|
+
export declare const SpecReportGrid: React.FC<SpecReportGridProps>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { StoryObj } from '@storybook/react';
|
|
2
|
+
/**
|
|
3
|
+
* SpecReportGrid stories — CRM-flavoured demos for M1.
|
|
4
|
+
*
|
|
5
|
+
* - Sales funnel by stage (summary report, sum amount, count opportunities)
|
|
6
|
+
* - Sales funnel by owner → stage (multi-level grouping)
|
|
7
|
+
* - Pipeline by region × quarter (matrix placeholder — M2 will render this)
|
|
8
|
+
*
|
|
9
|
+
* Stories supply rows inline so they work without a backend; the drill action
|
|
10
|
+
* is wired to a console-logging ActionRunner so clicks demonstrate the
|
|
11
|
+
* declarative drill protocol.
|
|
12
|
+
*/
|
|
13
|
+
import * as React from 'react';
|
|
14
|
+
declare const meta: {
|
|
15
|
+
title: string;
|
|
16
|
+
component: React.FC<import('./SpecReportGrid').SpecReportGridProps>;
|
|
17
|
+
parameters: {
|
|
18
|
+
layout: string;
|
|
19
|
+
};
|
|
20
|
+
tags: string[];
|
|
21
|
+
};
|
|
22
|
+
export default meta;
|
|
23
|
+
type Story = StoryObj<typeof meta>;
|
|
24
|
+
/** Funnel by stage — classic CRM "summary by status" view. */
|
|
25
|
+
export declare const FunnelByStage: Story;
|
|
26
|
+
/** Two-level funnel: owner → stage. Click a row to dispatch a drill action. */
|
|
27
|
+
export declare const FunnelByOwnerAndStage: Story;
|
|
28
|
+
/** Tabular detail report — flat opportunity list with totals. */
|
|
29
|
+
export declare const TabularOpportunityList: Story;
|
|
30
|
+
/** Matrix report placeholder — region × quarter pivot will land in M2. */
|
|
31
|
+
export declare const MatrixRegionByQuarter: Story;
|