@@ -32,6 +32,100 @@ const handleTableValue = (value, t) => {
3232 }
3333} ;
3434
35+ const rowRenderer = (
36+ entry ,
37+ index ,
38+ structure ,
39+ tExt ,
40+ jsonata ,
41+ arrayItems ,
42+ title ,
43+ setTitle ,
44+ schema ,
45+ originalResource ,
46+ singleRootResource ,
47+ props ,
48+ ) => {
49+ const tdClassNames = classNames ( {
50+ 'collapsible-panel' : ! structure . disablePadding ,
51+ } ) ;
52+ const makeTitle = async ( ) => {
53+ const defaultTitle =
54+ tExt ( structure . name , {
55+ defaultValue : structure . name || structure . source ,
56+ } ) +
57+ ' #' +
58+ ( index + 1 ) ;
59+ if ( structure . collapsibleTitle ) {
60+ try {
61+ return await jsonata ( structure . collapsibleTitle , {
62+ index : index ,
63+ scope : entry ,
64+ arrayItems : [ ...arrayItems , entry ] ,
65+ } ) ;
66+ } catch ( e ) {
67+ console . warn ( e ) ;
68+ return defaultTitle ;
69+ }
70+ } else {
71+ return defaultTitle ;
72+ }
73+ } ;
74+ makeTitle ( ) . then ( ( result ) => {
75+ if ( ! structure . collapsible ) {
76+ return ;
77+ }
78+ if ( result && JSON . stringify ( title ?. [ index ] ) !== JSON . stringify ( result ) ) {
79+ setTitle ( ( prev ) => ( { ...prev , [ index ] : result } ) ) ;
80+ }
81+ } ) ;
82+
83+ const cells = ( structure . children || [ ] ) . map ( ( column , cellIndex ) => {
84+ return (
85+ < Widget
86+ { ...props }
87+ key = { cellIndex }
88+ value = { entry }
89+ scope = { entry }
90+ arrayItems = { [ ...arrayItems , entry ] }
91+ structure = { column }
92+ schema = { schema }
93+ originalResource = { originalResource }
94+ singleRootResource = { singleRootResource }
95+ index = { index }
96+ />
97+ ) ;
98+ } ) ;
99+
100+ if ( ! structure . collapsible ) {
101+ return cells ;
102+ }
103+
104+ return {
105+ cells,
106+ title : title ?. [ index ] ?? '' ,
107+ collapseContent : (
108+ < div className = { tdClassNames } >
109+ { structure . collapsible . map ( ( child , cellIndex ) => (
110+ < Widget
111+ { ...props }
112+ key = { cellIndex }
113+ value = { entry }
114+ scope = { entry }
115+ arrayItems = { [ ...arrayItems , entry ] }
116+ structure = { child }
117+ schema = { schema }
118+ inlineRenderer = { InlineWidget }
119+ originalResource = { originalResource }
120+ singleRootResource = { singleRootResource }
121+ index = { index }
122+ />
123+ ) ) }
124+ </ div >
125+ ) ,
126+ } ;
127+ } ;
128+
35129export function Table ( {
36130 value,
37131 structure,
@@ -63,87 +157,12 @@ export function Table({
63157 arrayItems,
64158 } ) ;
65159
66- const [ title , setTitle ] = useState ( '' ) ;
160+ const [ title , setTitle ] = useState ( { } ) ;
67161
68162 const coreHeaders = ( structure . children || [ ] ) . map ( ( { name } ) => tExt ( name ) ) ;
69163 const headerRenderer = ( ) =>
70164 structure . collapsible ? [ '' , ...coreHeaders ] : coreHeaders ;
71165
72- const tdClassNames = classNames ( {
73- 'collapsible-panel' : ! structure . disablePadding ,
74- } ) ;
75-
76- const rowRenderer = ( entry , index ) => {
77- const makeTitle = async ( ) => {
78- const defaultTitle =
79- tExt ( structure . name , {
80- defaultValue : structure . name || structure . source ,
81- } ) +
82- ' #' +
83- ( index + 1 ) ;
84- if ( structure . collapsibleTitle ) {
85- try {
86- return await jsonata ( structure . collapsibleTitle , {
87- index : index ,
88- scope : entry ,
89- arrayItems : [ ...arrayItems , entry ] ,
90- } ) ;
91- } catch ( e ) {
92- console . warn ( e ) ;
93- return defaultTitle ;
94- }
95- } else {
96- return defaultTitle ;
97- }
98- } ;
99- makeTitle ( ) . then ( ( result ) => setTitle ( result ) ) ;
100-
101- const cells = ( structure . children || [ ] ) . map ( ( column , cellIndex ) => {
102- return (
103- < Widget
104- { ...props }
105- key = { cellIndex }
106- value = { entry }
107- scope = { entry }
108- arrayItems = { [ ...arrayItems , entry ] }
109- structure = { column }
110- schema = { schema }
111- originalResource = { originalResource }
112- singleRootResource = { singleRootResource }
113- index = { index }
114- />
115- ) ;
116- } ) ;
117-
118- if ( ! structure . collapsible ) {
119- return cells ;
120- }
121-
122- return {
123- cells,
124- title : title ,
125- collapseContent : (
126- < div className = { tdClassNames } >
127- { structure . collapsible . map ( ( child , cellIndex ) => (
128- < Widget
129- { ...props }
130- key = { cellIndex }
131- value = { entry }
132- scope = { entry }
133- arrayItems = { [ ...arrayItems , entry ] }
134- structure = { child }
135- schema = { schema }
136- inlineRenderer = { InlineWidget }
137- originalResource = { originalResource }
138- singleRootResource = { singleRootResource }
139- index = { index }
140- />
141- ) ) }
142- </ div >
143- ) ,
144- } ;
145- } ;
146-
147166 const { sortOptions } = getSortDetails ( structure ) ;
148167
149168 const { searchOptions, defaultSearch } = getSearchDetails ( structure ) ;
@@ -180,7 +199,22 @@ export function Table({
180199 } ) }
181200 extraHeaderContent = { extraHeaderContent }
182201 headerRenderer = { headerRenderer }
183- rowRenderer = { rowRenderer }
202+ rowRenderer = { ( entry , index ) =>
203+ rowRenderer (
204+ entry ,
205+ index ,
206+ structure ,
207+ tExt ,
208+ jsonata ,
209+ arrayItems ,
210+ title ,
211+ setTitle ,
212+ schema ,
213+ originalResource ,
214+ singleRootResource ,
215+ props ,
216+ )
217+ }
184218 { ...handleTableValue ( value , t ) }
185219 sortBy = { ( ) => sortBy ( jsonata , sortOptions , tExt , { } , originalResource ) }
186220 searchSettings = { {
0 commit comments