1
- import React from 'react' ;
1
+ import React , { useEffect , useState } from 'react' ;
2
2
import {
3
3
TrashIconOutline ,
4
4
PencilSquareIconOutline ,
7
7
ChevronDoubleRightIconOutline ,
8
8
ChevronRightIconOutline ,
9
9
} from '@neo4j-ndl/react/icons' ;
10
+ import ShowMoreText from 'react-show-more-text' ;
10
11
import {
11
12
createColumnHelper ,
12
13
flexRender ,
@@ -57,11 +58,15 @@ function ExampleDisplayTable({ examples, deleteModelExample, handleEdit }) {
57
58
const columns = React . useMemo (
58
59
( ) => [
59
60
columnHelper . accessor ( 'question' , {
60
- cell : ( info ) => info . getValue ( ) ,
61
+ cell : ( info ) => < ShowMoreText lines = { 3 } > { info . getValue ( ) } </ ShowMoreText > ,
61
62
header : ( ) => 'Question' ,
62
63
} ) ,
63
64
columnHelper . accessor ( 'answer' , {
64
- cell : ( info ) => info . getValue ( ) ,
65
+ cell : ( info ) => (
66
+ < div >
67
+ < ShowMoreText lines = { 3 } > { info . getValue ( ) } </ ShowMoreText >
68
+ </ div >
69
+ ) ,
65
70
header : 'Answer' ,
66
71
} ) ,
67
72
{
@@ -87,19 +92,52 @@ function ExampleDisplayTable({ examples, deleteModelExample, handleEdit }) {
87
92
} ,
88
93
} ) ;
89
94
95
+ const [ cellWidth , setCellWidth ] = useState ( '600px' ) ;
96
+
97
+ // For screens with 1080 x pixels or less
98
+ useEffect ( ( ) => {
99
+ const updateCellWidth = ( ) => {
100
+ if ( window . innerWidth <= 1080 ) {
101
+ // Example breakpoint for smaller screens
102
+ setCellWidth ( '463px' ) ;
103
+ } else {
104
+ setCellWidth ( '600px' ) ;
105
+ }
106
+ } ;
107
+
108
+ window . addEventListener ( 'resize' , updateCellWidth ) ;
109
+ updateCellWidth ( ) ; // Initialize on component mount
110
+
111
+ return ( ) => window . removeEventListener ( 'resize' , updateCellWidth ) ;
112
+ } , [ ] ) ;
113
+
90
114
return (
91
115
< div className = 'n-flex n-flex-col n-gap-2 n-mb-[15px]' >
92
- < div className = 'ndl-table-root n-rounded-lg' >
116
+ < div className = 'ndl-table-root n-rounded-lg' style = { { maxWidth : '100%' , overflowX : 'auto' } } >
93
117
< table className = 'ndl-div-table' >
94
118
< thead className = 'ndl-table-thead' >
95
119
{ table . getHeaderGroups ( ) . map ( ( headerGroup ) => (
96
120
< tr
97
121
className = 'ndl-table-tr'
98
- style = { { display : 'grid' , gridTemplateColumns : '1fr 1fr 120px' } }
122
+ style = { {
123
+ display : 'grid' ,
124
+ gridTemplateColumns : '1fr 1fr 120px' ,
125
+ textAlign : 'left' , // Aligns text to the left
126
+ } }
99
127
key = { headerGroup . id }
100
128
>
101
129
{ headerGroup . headers . map ( ( header ) => (
102
- < th className = 'ndl-table-th ndl-focusable-cell ndl-header-group ndl-header-cell' key = { header . id } >
130
+ < th
131
+ className = 'ndl-table-th ndl-focusable-cell ndl-header-group ndl-header-cell'
132
+ key = { header . id }
133
+ style = { {
134
+ wordBreak : 'break-word' ,
135
+ overflowWrap : 'break-word' ,
136
+ borderBottom : '1px solid #ccc' , // Adds bottom border to each cell
137
+ padding : '8px' , // Adds padding for readability
138
+ maxWidth : cellWidth ,
139
+ } }
140
+ >
103
141
{ header . isPlaceholder ? null : flexRender ( header . column . columnDef . header , header . getContext ( ) ) }
104
142
</ th >
105
143
) ) }
@@ -110,11 +148,23 @@ function ExampleDisplayTable({ examples, deleteModelExample, handleEdit }) {
110
148
{ table . getRowModel ( ) . rows . map ( ( row ) => (
111
149
< tr
112
150
className = 'ndl-table-tr'
113
- style = { { display : 'grid' , gridTemplateColumns : '1fr 1fr 120px' } }
151
+ style = { {
152
+ display : 'grid' ,
153
+ gridTemplateColumns : '1fr 1fr 120px' ,
154
+ } }
114
155
key = { row . id }
115
156
>
116
157
{ row . getVisibleCells ( ) . map ( ( cell ) => (
117
- < td className = 'ndl-table-td ndl-focusable-cell' key = { cell . id } >
158
+ < td
159
+ className = 'ndl-table-td ndl-focusable-cell'
160
+ key = { cell . id }
161
+ style = { {
162
+ wordBreak : 'break-word' ,
163
+ overflowWrap : 'break-word' ,
164
+ padding : '8px' , // Adds padding for readability
165
+ maxWidth : cellWidth ,
166
+ } }
167
+ >
118
168
{ flexRender ( cell . column . columnDef . cell , cell . getContext ( ) ) }
119
169
</ td >
120
170
) ) }
0 commit comments