Skip to content

Commit b535a01

Browse files
Fix/clipping examples (#768)
* wrapped text vertically, to understand how to prevent column resizing * Added cellWidth to limit width of cells and stop out of scope table. Also added x-direction scrollbar for overflow --------- Co-authored-by: Alfred Rubin <[email protected]>
1 parent 8dabb29 commit b535a01

File tree

1 file changed

+58
-8
lines changed

1 file changed

+58
-8
lines changed

src/extensions/text2cypher/component/model-examples/ExampleDisplayTable.tsx

Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { useEffect, useState } from 'react';
22
import {
33
TrashIconOutline,
44
PencilSquareIconOutline,
@@ -7,6 +7,7 @@ import {
77
ChevronDoubleRightIconOutline,
88
ChevronRightIconOutline,
99
} from '@neo4j-ndl/react/icons';
10+
import ShowMoreText from 'react-show-more-text';
1011
import {
1112
createColumnHelper,
1213
flexRender,
@@ -57,11 +58,15 @@ function ExampleDisplayTable({ examples, deleteModelExample, handleEdit }) {
5758
const columns = React.useMemo(
5859
() => [
5960
columnHelper.accessor('question', {
60-
cell: (info) => info.getValue(),
61+
cell: (info) => <ShowMoreText lines={3}>{info.getValue()}</ShowMoreText>,
6162
header: () => 'Question',
6263
}),
6364
columnHelper.accessor('answer', {
64-
cell: (info) => info.getValue(),
65+
cell: (info) => (
66+
<div>
67+
<ShowMoreText lines={3}>{info.getValue()}</ShowMoreText>
68+
</div>
69+
),
6570
header: 'Answer',
6671
}),
6772
{
@@ -87,19 +92,52 @@ function ExampleDisplayTable({ examples, deleteModelExample, handleEdit }) {
8792
},
8893
});
8994

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+
90114
return (
91115
<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' }}>
93117
<table className='ndl-div-table'>
94118
<thead className='ndl-table-thead'>
95119
{table.getHeaderGroups().map((headerGroup) => (
96120
<tr
97121
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+
}}
99127
key={headerGroup.id}
100128
>
101129
{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+
>
103141
{header.isPlaceholder ? null : flexRender(header.column.columnDef.header, header.getContext())}
104142
</th>
105143
))}
@@ -110,11 +148,23 @@ function ExampleDisplayTable({ examples, deleteModelExample, handleEdit }) {
110148
{table.getRowModel().rows.map((row) => (
111149
<tr
112150
className='ndl-table-tr'
113-
style={{ display: 'grid', gridTemplateColumns: '1fr 1fr 120px' }}
151+
style={{
152+
display: 'grid',
153+
gridTemplateColumns: '1fr 1fr 120px',
154+
}}
114155
key={row.id}
115156
>
116157
{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+
>
118168
{flexRender(cell.column.columnDef.cell, cell.getContext())}
119169
</td>
120170
))}

0 commit comments

Comments
 (0)