@@ -118,6 +118,14 @@ import { builtinAggregateLabels, useSafeFieldLabel, useSafeTranslate, useDisplay
118118import { useDataInvalidation , classifyLoadError } from '@object-ui/react' ;
119119import { mergeFilters } from './mergeFilters' ;
120120import { useDatasetDimensionMeta , type DatasetDimensionMeta } from './useDatasetDimensionLabels' ;
121+ import {
122+ ReportExportControl ,
123+ ReportTableSnapshotContext ,
124+ PublishReportTableSnapshot ,
125+ exportDimensionCell ,
126+ exportMeasureCell ,
127+ type ReportTableSnapshot ,
128+ } from './ReportExport' ;
121129
122130type Row = Record < string , unknown > ;
123131
@@ -205,6 +213,12 @@ interface DatasetReportLike {
205213 label ?: unknown ;
206214 description ?: unknown ;
207215 blocks ?: DatasetReportLike [ ] ;
216+ /**
217+ * The report's export control (`ReportSchema.exportOptions`): the formats
218+ * offered and how the file is written — see `ReportExport.tsx`. Refused on a
219+ * `joined` container by the spec, and not read there.
220+ */
221+ exportOptions ?: unknown ;
208222}
209223
210224export interface DatasetReportRendererProps {
@@ -846,8 +860,28 @@ function DatasetReportTable({
846860 ? state . totals ?. find ( ( t ) => Array . isArray ( t . dimensions ) && t . dimensions . length === 0 ) ?. rows ?. [ 0 ]
847861 : undefined ;
848862 const totalText = tt ( 'report.total' , 'Total' ) ;
863+ const fmt = ( measure : string , value : unknown ) =>
864+ formatMeasure ( value , measureField ( measure ) ?. format , measureField ( measure ) ?. currency , measureField ( measure ) ?. percentScale , displayLocale ) ;
865+ // The cells below, as the export writes them (`ReportExport.tsx`).
866+ const snapshot : ReportTableSnapshot = {
867+ object : state . object ,
868+ header : columns . map ( ( c ) => headerLabel ( c ) ) ,
869+ rows : [
870+ ...layout . map ( ( i ) =>
871+ columns . map ( ( c ) =>
872+ values . includes ( c )
873+ ? exportMeasureCell ( fmt ( c , displayRows [ i ] [ c ] ) , displayRows [ i ] [ c ] )
874+ : exportDimensionCell ( formatDimensionValue ( displayRows [ i ] [ c ] , displayLocale ) ) ,
875+ ) ,
876+ ) ,
877+ ...( grandTotal
878+ ? [ [ ...rows . map ( ( _ , k ) => ( { text : k === 0 ? totalText : '' } ) ) , ...values . map ( ( m ) => exportMeasureCell ( fmt ( m , grandTotal [ m ] ) , grandTotal [ m ] ) ) ] ]
879+ : [ ] ) ,
880+ ] ,
881+ } ;
849882 return (
850883 < div className = "overflow-auto max-h-[70vh] rounded-md border" >
884+ < PublishReportTableSnapshot snapshot = { snapshot } />
851885 < table className = "w-full text-xs" >
852886 < thead className = "bg-muted/40" >
853887 < tr >
@@ -1675,9 +1709,43 @@ function DatasetMatrixTable({
16751709 const grandTotal = findTotals ( [ ] ) ?. [ 0 ] ;
16761710 const showTotalCol = rowTotalById . size > 0 ;
16771711 const showTotalRow = colTotalById . size > 0 ;
1712+ const fmt = ( measure : string , value : unknown ) =>
1713+ formatMeasure ( value , measureField ( measure ) ?. format , measureField ( measure ) ?. currency , measureField ( measure ) ?. percentScale , displayLocale ) ;
1714+ const totalHeader = ( measure : string ) => ( values . length === 1 ? totalText : `${ totalText } · ${ headerLabel ( measure ) } ` ) ;
1715+ // The cross-tab below, as the export writes it (`ReportExport.tsx`).
1716+ const snapshot : ReportTableSnapshot = {
1717+ object : state . object ,
1718+ header : [
1719+ ...rows . map ( ( d ) => headerLabel ( d ) ) ,
1720+ ...cellCols . map ( ( cc ) => cc . header ) ,
1721+ ...( showTotalCol ? values . map ( totalHeader ) : [ ] ) ,
1722+ ] ,
1723+ rows : [
1724+ ...pivot . rowHeaders . map ( ( rh ) => [
1725+ ...rows . map ( ( d ) => exportDimensionCell ( formatDimensionValue ( rh . display [ d ] , displayLocale ) ) ) ,
1726+ ...cellCols . map ( ( cc ) => {
1727+ const value = pivot . cells . get ( pivotCellKey ( rh . id , cc . col . id ) ) ?. row [ cc . measure ] ;
1728+ return exportMeasureCell ( fmt ( cc . measure , value ) , value ) ;
1729+ } ) ,
1730+ ...( showTotalCol
1731+ ? values . map ( ( m ) => exportMeasureCell ( fmt ( m , rowTotalById . get ( rh . id ) ?. [ m ] ) , rowTotalById . get ( rh . id ) ?. [ m ] ) )
1732+ : [ ] ) ,
1733+ ] ) ,
1734+ ...( showTotalRow
1735+ ? [ [
1736+ ...rows . map ( ( _ , k ) => ( { text : k === 0 ? totalText : '' } ) ) ,
1737+ ...cellCols . map ( ( cc ) =>
1738+ exportMeasureCell ( fmt ( cc . measure , colTotalById . get ( cc . col . id ) ?. [ cc . measure ] ) , colTotalById . get ( cc . col . id ) ?. [ cc . measure ] ) ,
1739+ ) ,
1740+ ...( showTotalCol ? values . map ( ( m ) => exportMeasureCell ( fmt ( m , grandTotal ?. [ m ] ) , grandTotal ?. [ m ] ) ) : [ ] ) ,
1741+ ] ]
1742+ : [ ] ) ,
1743+ ] ,
1744+ } ;
16781745
16791746 return (
16801747 < div className = "overflow-auto max-h-[70vh] rounded-md border" data-testid = "dataset-matrix" >
1748+ < PublishReportTableSnapshot snapshot = { snapshot } />
16811749 < table className = "w-full text-xs" >
16821750 < thead className = "bg-muted/40" >
16831751 < tr >
@@ -1784,6 +1852,8 @@ export const DatasetReportRenderer: React.FC<DatasetReportRendererProps> = ({
17841852 const drillSink = report . drilldown === false ? undefined : onDrill ;
17851853 // The DECLARED type drives the branch (#2941) — never the data shape.
17861854 const presentation = resolveReportPresentation ( report . type ) ;
1855+ // The drawn table's cells, for the export control (not read on `joined`).
1856+ const [ tableSnapshot , setTableSnapshot ] = React . useState < ReportTableSnapshot | null > ( null ) ;
17871857
17881858 // Joined → a vertical stack of dataset-bound blocks.
17891859 if ( presentation === 'joined' && Array . isArray ( report . blocks ) ) {
@@ -1916,15 +1986,22 @@ export const DatasetReportRenderer: React.FC<DatasetReportRendererProps> = ({
19161986 // the ruling on objectstack-ai/objectstack#20293 draws a matrix's chart
19171987 // "beside or below the cross-tab", and below is the one placement that needs
19181988 // no new layout option.
1989+ //
1990+ // The export control (`exportOptions`, objectstack-ai/objectstack#25873)
1991+ // writes the table the report draws, which the table hands up through the
1992+ // snapshot context; it draws nothing until the table has rows.
19191993 return (
1994+ < ReportTableSnapshotContext . Provider value = { setTableSnapshot } >
19201995 < div
19211996 className = { `${ className ?? '' } flex flex-col gap-3` }
19221997 data-testid = "dataset-report"
19231998 data-report-name = { report . name }
19241999 data-report-presentation = { presentation }
19252000 >
2001+ < ReportExportControl exportOptions = { report . exportOptions } label = { report . label } name = { report . name } snapshot = { tableSnapshot } />
19262002 { crossTab ? table : chart }
19272003 { crossTab ? chart : table }
19282004 </ div >
2005+ </ ReportTableSnapshotContext . Provider >
19292006 ) ;
19302007} ;
0 commit comments